forked from Armen138/SpaceDefender
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
163 additions
and
132 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
define(["ParticleSystem", "canvas", "effects"], function(PS, Canvas, effects) { | ||
var bullet = function(position, enemies) { | ||
var start = Date.now(); | ||
var speed = 0.7; | ||
var dead = false; | ||
var baseY = position.Y; | ||
var baseX = position.X; | ||
var trail = new PS.ParticleSystem(effects("bullet")); | ||
var b = { | ||
draw: function() { | ||
trail.draw(Canvas.element, position.X, position.Y, 17); | ||
position.Y = baseY - ((Date.now() - start) * speed); | ||
//position.X = baseX - ((Date.now() - start) * speed); | ||
if(position.Y < -10 && !dead) { | ||
trail.kill(); | ||
dead = true; | ||
} | ||
for(var i = 0; i < enemies.length; i++) { | ||
if((Math.abs(enemies[i].position.X - position.X) < 30) && | ||
(Math.abs(enemies[i].position.Y - position.Y) < 30)) { | ||
enemies[i].die(); | ||
trail.kill(); | ||
dead = true; | ||
} | ||
} | ||
if(trail.isDone()) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
}; | ||
return b; | ||
}; | ||
return bullet; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
define(function() { | ||
return function(effect) { | ||
switch(effect) { | ||
case "bullet": | ||
return {"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":255,"green":167,"blue":63,"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 "shield": | ||
return {"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; | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
define(["canvas", "events"], function(Canvas, events) { | ||
var enemy = function(image, position) { | ||
var start = Date.now(); | ||
var speed = 0.2; | ||
var dead = false; | ||
var hp = 10; | ||
var startPosition = {X: position.X, Y: position.Y}; | ||
var e = { | ||
position: position, | ||
hit: function(damage) { | ||
hp -= damage; | ||
if(hp < 0) { | ||
e.die(); | ||
} | ||
}, | ||
die: function() { | ||
dead = true; | ||
e.fire("death"); | ||
}, | ||
draw: function() { | ||
position.Y = startPosition.Y + ((Date.now() - start) * speed); | ||
Canvas.context.save(); | ||
var angle = 90 * 0.0174532925; | ||
Canvas.context.translate(position.X, position.Y); | ||
Canvas.context.rotate(angle); | ||
Canvas.context.drawImage(image, 264, 945, 22, 25, 0, 0, 22, 25); | ||
Canvas.context.restore(); | ||
if(position.Y > Canvas.height || dead) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
events.attach(e); | ||
return e; | ||
}; | ||
return enemy; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
define(["canvas"], function(Canvas) { | ||
var powerup = function(image, action, position) { | ||
var start = Date.now(); | ||
var lastScale = 0; | ||
var scaleTime = 50; | ||
var scale = 0.5; | ||
var inc = 0.1; | ||
return { | ||
draw: function() { | ||
//scale = 0.5 + ((Date.now() - start) % 50 / 50); | ||
if(Date.now() - lastScale > scaleTime) { | ||
lastScale = Date.now(); | ||
scale += inc; | ||
if(scale === 1.2 || scale === 0.4) { | ||
inc *= -1; | ||
} | ||
} | ||
Canvas.context.save(); | ||
Canvas.context.translate(position.X, position.Y); | ||
Canvas.context.scale(scale, scale); | ||
Canvas.context.drawImage(image, -1 * (image.width / 2) * scale, -1 * (image.height / 2) * scale); | ||
Canvas.context.restore(); | ||
} | ||
}; | ||
}; | ||
return powerup; | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
define(function() { | ||
var stars = function(Canvas) { | ||
var starMap = []; | ||
var maxStars = 100; | ||
var maxLayers = 4; | ||
for(var l = 0; l < maxLayers; l++) { | ||
starMap[l] = []; | ||
for(var i = 0; i < maxStars; i++) { | ||
starMap[l].push({X: Math.random() * Canvas.width | 0, | ||
Y: Math.random() * Canvas.height | 0}); | ||
} | ||
} | ||
var s = { | ||
draw: function() { | ||
for(var l = 0; l < starMap.length; l++) { | ||
var shade = 200 / (l + 1); | ||
Canvas.context.fillStyle = "rgb(" + shade + "," + shade + "," + shade + ")"; | ||
for(var i = 0; i < starMap[l].length; i++) { | ||
Canvas.context.fillRect(starMap[l][i].X, starMap[l][i].Y, 2, 2); | ||
starMap[l][i].Y += (1 / l); | ||
if(starMap[l][i].Y > Canvas.height) { | ||
starMap[l][i].Y -= Canvas.height; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return s; | ||
} | ||
return stars; | ||
}); |