From 4c77c5f472c0a3d92c8366bcbc01fdfd7b3ac069 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Wed, 7 Jun 2023 17:45:00 +0000 Subject: [PATCH] random ints --- source/scripts/base.js | 5 +++-- source/scripts/engine.js | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/source/scripts/base.js b/source/scripts/base.js index 46491f1..3d483c2 100644 --- a/source/scripts/base.js +++ b/source/scripts/base.js @@ -522,8 +522,9 @@ Math.angledist = function (a1, a2) { return wrap; }; -Math.deg2rad = function(deg) { return deg * 0.0174533; } -Math.rad2deg = function(rad) { return rad / 0.0174533; } +Math.deg2rad = function(deg) { return deg * 0.0174533; }; +Math.rad2deg = function(rad) { return rad / 0.0174533; }; +Math.randomint = function(max) { return Math.clamp(Math.floor(Math.random() * max), 0, max-1); }; /* BOUNDINGBOXES */ function cwh2bb(c, wh) { diff --git a/source/scripts/engine.js b/source/scripts/engine.js index 6407df3..1779b8b 100644 --- a/source/scripts/engine.js +++ b/source/scripts/engine.js @@ -1704,6 +1704,12 @@ var gameobject = { return obj; }, + + instandup() { + var dup = World.spawn(gameobjects[this.from]); + dup.pos = this.pos; + dup.velocity = this.velocity; + }, ed_locked: false, @@ -1741,7 +1747,6 @@ var gameobject = { flipx: false, flipy: false, - body: -1, controlled: false, @@ -1840,12 +1845,13 @@ var gameobject = { get boundingbox() { var boxes = []; boxes.push({t:0, r:0,b:0,l:0}); + for (var key in this.components) { if ('boundingbox' in this.components[key]) boxes.push(this.components[key].boundingbox); } - if (boxes.empty) return; + if (boxes.empty) return cwh2bb([0,0], [0,0]); var bb = boxes[0]; @@ -1880,6 +1886,8 @@ var gameobject = { stop() {}, + + kill() { if (this.body === -1) { Log.warn(`Object is already dead!`); @@ -2201,4 +2209,4 @@ for (var key in prototypes) { function save_gameobjects_as_prototypes() { slurpwrite(JSON.stringify(gameobjects,null,2), "proto.json"); }; -let Gamestate = {}; +var Gamestate = {};