random ints

This commit is contained in:
John Alanbrook 2023-06-07 17:45:00 +00:00
parent 6c0e850180
commit 4c77c5f472
2 changed files with 14 additions and 5 deletions

View file

@ -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) {

View file

@ -1705,6 +1705,12 @@ var gameobject = {
return obj;
},
instandup() {
var dup = World.spawn(gameobjects[this.from]);
dup.pos = this.pos;
dup.velocity = this.velocity;
},
ed_locked: false,
_visible: true,
@ -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 = {};