window.stuff = [{},{},{},{},{},{},{},{},{},{}] function Pickup() { var pType = Math.floor(Math.random()*10); this.y = -16 + Math.floor(Math.random()*180); this.x = 320 + Math.floor(Math.random()*120); this.vX = -4 - Math.floor(Math.random()*catbug.maxHP); this.vY = 0; switch (pType) { case 0: case 1: case 2: case 3: case 4: this.sprite = renderer.gfx.peas; this.points = 1; break; case 5: case 6: case 7: this.sprite = renderer.gfx.pbs this.points = 2; break; case 8: case 9: this.sprite = renderer.gfx.taco; this.points = 3; break; } } function managePickups() { var genSpeed = 0; var i; if (gameState.points > 10) { genSpeed = Math.floor(Math.random()*gameState.points); } else genSpeed = Math.floor(Math.random()*10); for (i = 0; i < 10; i++) { if (!isEmptyObject(stuff[i])) { movePickup(stuff[i]); if (stuff[i].x < -32) { stuff[i] = {}; catbug.HP--; } else { var box = {}; box.x = stuff[i].x; box.y = stuff[i].y; box.w = 36; box.h = 36; if (catbug.isInRect(box)) { getPickup(stuff[i]); stuff[i] = {}; } } } else { if (( gameState.points >= 40 && genSpeed*genSpeed >= gameState.points*4) || ( gameState.points <= 40 && genSpeed*genSpeed >= gameState.threshold*2)) { var now = new Date(); if (now - gameState.ticker >= 1000) { stuff[i] = new Pickup(); gameState.ticker = now; } } } } } function movePickup(self) { self.x += self.vX; } function getPickup(self) { gameState.points += self.points; if (gameState.points >= gameState.threshold) { gameState.threshold *= 2; catbug.maxHP++; catbug.HP = catbug.maxHP; } }