Skip to content

Commit

Permalink
powerup refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Armen138 committed Feb 17, 2013
1 parent 0cc4cc5 commit 7cdac4c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Binary file added 3d/ship_test.blend
Binary file not shown.
3 changes: 1 addition & 2 deletions js/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ define(function() {
case "shield":
e = {"emitterStartLocation":{"x":0,"y":0},"emitterStopLocation":{"x":0,"y":0},"systemLifeSpan":0,"particleSpawnArea":{"x":0,"y":0},"maxParticles":300,"averageLifeSpan":0.3,"lifeSpanVariance":0.1,"startColor":{"red":63,"green":167,"blue":255,"alpha":1},"stopColor":{"red":0,"green":0,"blue":0,"alpha":1},"averageVelocity":{"horizontal":0,"vertical":0},"velocityVariance":{"x":0.3,"y":0.3},"minParticleSize":2,"maxParticleSize":4,"particleFadeTime":0.6,"globalCompositeOperation":"lighter","renderType":"spriteSheet","type":"relative"};
break;
case "powerup":
//return {"emitterStartLocation":{"x":0,"y":0},"emitterStopLocation":{"x":0,"y":0},"systemLifeSpan":5,"particleSpawnArea":{"x":32,"y":32},"maxParticles":100,"averageLifeSpan":1,"lifeSpanVariance":0.5,"startColor":{"red":255,"green":167,"blue":63,"alpha":1},"stopColor":{"red":13,"green":141,"blue":0,"alpha":1},"averageVelocity":{"horizontal":0,"vertical":0},"velocityVariance":{"x":1,"y":1},"minParticleSize":5,"maxParticleSize":10,"particleFadeTime":0.8,"globalCompositeOperation":"lighter","renderType":"image","image":"images/star.png","type":"absolute"};
case "powerup":
e = {"emitterStartLocation":{"x":0,"y":0},"emitterStopLocation":{"x":0,"y":0},"systemLifeSpan":1,"particleSpawnArea":{"x":32,"y":32},"maxParticles":100,"averageLifeSpan":0.4,"lifeSpanVariance":0.1,"startColor":{"red":255,"green":167,"blue":63,"alpha":1},"stopColor":{"red":13,"green":141,"blue":0,"alpha":1},"averageVelocity":{"horizontal":0,"vertical":0},"velocityVariance":{"x":2,"y":2},"minParticleSize":5,"maxParticleSize":10,"particleFadeTime":0.5,"globalCompositeOperation":"lighter","renderType":"image","image":image || "images/star.png","type":"absolute"};
break;
case "explosion":
Expand Down
23 changes: 20 additions & 3 deletions js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ define(["canvas", "resources", "keys", "menu", "stars", "enemy", "effects", "bul
}
], Resources.images.logo);

var weapons = {
gun: {
loadTime: 100,
ammo: Bullet
},
rocket: {
loadTime: 1000,
ammo: Bullet
}
}

var bullets = [];
var lastShot = 0;
Expand All @@ -70,6 +80,9 @@ define(["canvas", "resources", "keys", "menu", "stars", "enemy", "effects", "bul
var ship = {
X: 100,
Y: 100,
hp: 100,
shield: 100,
currentWeapon: weapons.gun,
enableShield: false,
loadTime: 100,
draw: function() {
Expand Down Expand Up @@ -112,7 +125,10 @@ define(["canvas", "resources", "keys", "menu", "stars", "enemy", "effects", "bul
}
if(down[play.controls.fire]) {
ship.fire();
}
}
if(ship.shield <= 0) {
ship.enableShield = false;
}
},
left: function() {
ship.X -=10;
Expand All @@ -127,9 +143,9 @@ define(["canvas", "resources", "keys", "menu", "stars", "enemy", "effects", "bul
ship.Y += 10;
},
fire: function() {
if(Date.now() - lastShot > ship.loadTime) {
if(Date.now() - lastShot > ship.currentWeapon.loadTime) {
lastShot = Date.now();
bullets.push(Bullet({X: ship.X + 11, Y: ship.Y - 25}, enemies));
bullets.push(ship.currentWeapon.ammo({X: ship.X + 11, Y: ship.Y - 25}, enemies));
}
}
}
Expand Down Expand Up @@ -218,6 +234,7 @@ define(["canvas", "resources", "keys", "menu", "stars", "enemy", "effects", "bul
image: Resources.images.shield,
action: function() {
getPowerup();
ship.shield = 100;
ship.enableShield = true;
}
}
Expand Down

0 comments on commit 7cdac4c

Please sign in to comment.