Skip to content

Commit

Permalink
jump now has particles
Browse files Browse the repository at this point in the history
  • Loading branch information
rydrman committed Jan 26, 2014
1 parent 21193d2 commit 01b878c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
31 changes: 27 additions & 4 deletions engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Engine.prototype.init = function()
this.generator = new Generator();

//graphics
this.jumpParticles = [];
this.offsetForeground = 0;
this.offsetBackground = 0;
this.numScrollsForeground = 0;
Expand Down Expand Up @@ -103,11 +104,21 @@ Engine.prototype.init = function()
window.addEventListener('keydown', function(e) {
//jump - space
if (e.keyCode == 32 /*&& self.g != 0*/) {
if (!self.char.falling || self.g > 200){
self.char.jump();
} else if (self.char.falling && self.g >= 25) {
if (!self.char.falling || self.g >= 25){
if (self.char.falling)
{
if(self.g < 200)
self.g -= 25;
//create particle emiter
var emitter = new particleEmitter(self.context, 'rect', [self.char.x, self.char.y + 50],
[0,0], [10,10], "green", [6,6], 20, 10, false);
for(var i = 0; i < 10; i++)
emitter.makeParticle();

emitter.time = self.lastTime;
self.jumpParticles.push(emitter);
}
self.char.jump();
self.g -= 25;
}
}
//attack - f
Expand Down Expand Up @@ -302,6 +313,11 @@ Engine.prototype.animate = function(time) {
if (this.colorPickup) { this.colorPickup.render(context); }

//particle emitter stuff
//char jumps
for(var i =0 ; i < this.jumpParticles.length; i++)
{
this.jumpParticles[i].run();
}
//character projectiles
this.timeSinceLastParticle += timeSinceLastFrame;
if(this.char.projectiles.length !=0 || this.char.shields.length != 0){
Expand Down Expand Up @@ -438,6 +454,13 @@ Engine.prototype.translateWorld = function(t) {
bp.l[i].x += dX;
bp.l[i].y += dY;
}

//jump emitters
for(var i = 0; i < this.jumpParticles.length; i++)
{
//this.jumpParticles[i].position[0] += dX;
//this.jumpParticles[i].position[1] += dY;
}

// translate colorPickup
if (this.colorPickup) {
Expand Down
5 changes: 3 additions & 2 deletions particles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//emitter to place at a location
var particleEmitter = function(context, type, position, velocity, particleVelocity, color, size, rate, maxParticles, life){
var particleEmitter = function(context, type, position, velocity, particleVelocity, color, size, rate, maxParticles, centralParticle){
this.context = context;
this.type = type;
this.position = position;
Expand All @@ -9,6 +9,7 @@ var particleEmitter = function(context, type, position, velocity, particleVeloci
this.rate = rate;
this.size = size;
this.maxParticles = maxParticles;
this.centralParticle = (typeof(centralParticle) == 'undefined') ? true : centralParticle;

this.particles = new Array();
}
Expand All @@ -32,7 +33,7 @@ particleEmitter.prototype.run = function(time){


//draw the projectile
if(this.type == "rect"){
if(this.centralParticle){
this.context.save();
this.context.fillStyle = this.color;
this.context.globalAlpha = 0.9;
Expand Down

0 comments on commit 01b878c

Please sign in to comment.