katbugjs/Pickup.js

102 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-03-31 21:41:48 +00:00
window.stuff = [{},{},{},{},{},{},{},{},{},{}]
function Pickup()
{
var pType = Math.floor(Math.random()*10);
this.y = 0 + Math.floor(Math.random()*148);
2019-03-31 21:41:48 +00:00
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 (stuff[i] != null)
2019-03-31 21:41:48 +00:00
{
movePickup(stuff[i]);
if (stuff[i].x < -32)
2019-03-31 21:41:48 +00:00
{
stuff[i] = null;
2019-03-31 21:41:48 +00:00
catbug.HP--;
}
else
{
box = {
x: stuff[i].x,
y: stuff[i].y,
w: 36,
h: 36
}
2019-03-31 21:41:48 +00:00
if (catbug.isInRect(box))
{
getPickup(stuff[i]);
stuff[i] = null;
2019-03-31 21:41:48 +00:00
}
}
}
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;
}
}