Catbug, Engine, Pickup: use null instead of empty object, cleaner initialization for non-function properties

This commit is contained in:
Iris Lightshard 2021-02-07 11:27:11 -05:00
parent 7eff511ff1
commit c07d60efd5
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
3 changed files with 24 additions and 34 deletions

View file

@ -1,11 +1,13 @@
var catbug = {};
catbug.x = 45;
catbug.y = 90;
catbug.vX = 0;
catbug.vY = 0;
catbug.frame = 0;
catbug.HP = 3;
catbug.maxHP = 3;
var catbug = {
x: 45,
y: 90,
vX: 0,
vY: 0,
frame: 0,
HP: 3,
maxHP: 3
};
catbug.move = function()
{
this.x += this.vX;

View file

@ -100,7 +100,7 @@ renderer.drawPickups = function()
var i;
for (i = 0; i < 10; i++)
{
if (!isEmptyObject(stuff[i])){
if (stuff[i] != null){
screen.drawImage(stuff[i].sprite, stuff[i].x, stuff[i].y);}
}
}
@ -136,20 +136,6 @@ controller.left = false;
controller.space = false;
controller.q = false;
function isEmptyObject(obj)
{
var name;
for (name in obj)
{
if (obj.hasOwnProperty(name))
{
return false;
}
}
return true;
}
function scoreSummary()
{
gameState.frame = thisFrame;
@ -191,7 +177,7 @@ function resetGame()
catbug.vY = 0;
gameState.points = 0;
gameState.threshold = 10;
stuff = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}];
stuff = new Array(10);
}
function loop()
@ -346,4 +332,4 @@ function releaseHandler(e)
default:
break;
}
}
}

View file

@ -43,25 +43,27 @@ function managePickups()
else genSpeed = Math.floor(Math.random()*10);
for (i = 0; i < 10; i++)
{
if (!isEmptyObject(stuff[i]))
if (stuff[i] != null)
{
movePickup(stuff[i]);
if (stuff[i].x < -32)
{
stuff[i] = {};
stuff[i] = null;
catbug.HP--;
}
else
{
var box = {};
box.x = stuff[i].x;
box.y = stuff[i].y;
box.w = 36;
box.h = 36;
box = {
x: stuff[i].x,
y: stuff[i].y,
w: 36,
h: 36
}
if (catbug.isInRect(box))
{
getPickup(stuff[i]);
stuff[i] = {};
stuff[i] = null;
}
}
}
@ -96,4 +98,4 @@ function getPickup(self)
catbug.HP = catbug.maxHP;
}
}
}