Browse Source

changes

master
mortie 7 years ago
parent
commit
c130996c46
3 changed files with 50 additions and 18 deletions
  1. 30
    8
      js/assets.js
  2. 19
    9
      js/entities.js
  3. 1
    1
      js/vec2.js

+ 30
- 8
js/assets.js View File

"Height isn't evenly divisible by frame height. "+ "Height isn't evenly divisible by frame height. "+
"Height: "+this.height+", frame height: "+this.frameh); "Height: "+this.height+", frame height: "+this.frameh);
} }

console.log(this);
}.bind(this); }.bind(this);


this.img.src = "assets/"+src+ext; this.img.src = "assets/"+src+ext;
ImageSource.prototype.draw = function(ctx, step) { ImageSource.prototype.draw = function(ctx, step) {
if (!step) step = 0; if (!step) step = 0;


ctx.drawImage(this.img, 0, 0,
this.width, this.frameh,
ctx.drawImage(this.img,
0, this.frameh * step, 0, this.frameh * step,
this.width, this.frameh,
0, 0,
this.width, this.frameh); this.width, this.frameh);
} }


this.imgSrc = imgSrc; this.imgSrc = imgSrc;
this.fps = fps || 12; this.fps = fps || 12;
this.waitTime = 1000 / this.fps; this.waitTime = 1000 / this.fps;
this.done = false;


this.doStep = true;
this.doStep = false;


if (type === "forward" || type === "bounce") { if (type === "forward" || type === "bounce") {
this.step = 0; this.step = 0;
var next = this.step + this.direction; var next = this.step + this.direction;
if (next < 0 || next > this.imgSrc.steps - 1) { if (next < 0 || next > this.imgSrc.steps - 1) {
if (this.loop) { if (this.loop) {
this.direction = -this.direction;
next = this.step + this.direction;
if (this.type === "bounce") {
this.direction = -this.direction;
next = this.step + this.direction;
} else if (this.type === "forward") {
if (next < 0)
next = this.imgSrc.steps - 1;
else
next = 0;
}
} else { } else {
this.done = true;
this.doStep = false;
return; return;
} }
} }
if (this.doStep) { if (this.doStep) {
this.nextFrame(); this.nextFrame();
this.doStep = false; this.doStep = false;
this.setTimeout(function() {
setTimeout(function() {
this.doStep = true; this.doStep = true;
}.bind(this), this.waitTime); }.bind(this), this.waitTime);
} }
} }
Animation.prototype.play = function() {
if (this.step !== -1)
this.step = 0;
this.doStep = true;
}
Animation.prototype.setStep = function(step) {
if (step > this.imgSrc.steps - 1)
this.step = this.imgSrc.steps - 1;
else if (step < 0)
this.step = 0;
else
this.step = step;
}

+ 19
- 9
js/entities.js View File

this.invincibleTimeout = null; this.invincibleTimeout = null;
this.started = false; this.started = false;
this.rotation = 0; this.rotation = 0;
this.box = new Box();
this.shape.push(this.box);


this.erectLevel = 0; this.erectLevel = 0;
this.rise(); this.rise();


this.pos.set({ x: 0, y: game.canvas.height / 2 }); this.pos.set({ x: 0, y: game.canvas.height / 2 });
} }
Player.prototype.rise = function() {
this.erectLevel += 1;

Player.prototype.setBox = function() {
var w = 30 + ((this.erectLevel - 1) * 15); var w = 30 + ((this.erectLevel - 1) * 15);
var h = 15 + ((this.erectLevel - 1) * 6); var h = 15 + ((this.erectLevel - 1) * 6);
this.shape.push(new Box(w, h, { x: -(w/2), y: -(h/2) }));

this.box.width = w;
this.box.height = h;
this.box.pos.x = -(w / 2);
this.box.pos.y = -(h / 2);
}
Player.prototype.rise = function() {
this.erectLevel += 1;
this.setInvincible(200); this.setInvincible(200);
this.setBox();
} }
Player.prototype.lower = function() { Player.prototype.lower = function() {
if (this.invincible) if (this.invincible)
return; return;


this.shape.pop();

this.erectLevel -= 1; this.erectLevel -= 1;
if (this.erectLevel === 0) if (this.erectLevel === 0)
this.lose(); this.lose();
else else
this.setInvincible(500); this.setInvincible(500);

this.setBox();
} }
Player.prototype.setInvincible = function(time) { Player.prototype.setInvincible = function(time) {
clearTimeout(this.invincibleTimeout); clearTimeout(this.invincibleTimeout);
this.game.camera.x = this.pos.x - (this.game.canvas.width / 7); this.game.camera.x = this.pos.x - (this.game.canvas.width / 7);


// Rotate // Rotate
this.rotation = this.vel.rotation();
this.rotation = this.vel.angle();
} }
Player.prototype.lose = function() { Player.prototype.lose = function() {
alert("You died!"); alert("You died!");
else else
ctx.fillStyle = "#f5f5dc"; ctx.fillStyle = "#f5f5dc";
ctx.rotate(this.rotation); ctx.rotate(this.rotation);

this.shape.draw(ctx); this.shape.draw(ctx);
} }


makeEnt(this, game, 100); makeEnt(this, game, 100);
this.pos.set({ x: x, y: y }); this.pos.set({ x: x, y: y });


var w = 40;
var w = 70;
var h = game.canvas.height; var h = game.canvas.height;
var gap = 200; var gap = 200;


this.shape.push(new Box(30, 30)); this.shape.push(new Box(30, 30));
} }
PowerUp.prototype.draw = function(ctx) { PowerUp.prototype.draw = function(ctx) {
ctx.fillStyle = "#33ee33";
ctx.strokeStyle = "#227722";
ctx.beginPath(); ctx.beginPath();
ctx.arc(15, 15, 15, 0, 2 * Math.PI); ctx.arc(15, 15, 15, 0, 2 * Math.PI);
ctx.stroke(); ctx.stroke();
ctx.fill();
} }
PowerUp.prototype.update = function() { PowerUp.prototype.update = function() {
if (this.game.camera.x > this.pos.x + this.shape.width()) if (this.game.camera.x > this.pos.x + this.shape.width())

+ 1
- 1
js/vec2.js View File

return this; return this;
} }


Vec2.prototype.rotation = function() {
Vec2.prototype.angle = function() {
return Math.atan2(this.y, this.x); return Math.atan2(this.y, this.x);
} }

Loading…
Cancel
Save