HTML and CSS Reference
In-Depth Information
}
},
step: function(dt) {
var p = this.p;
var hit = Q.stage().collide(this);
if(hit) {
p.dy = hit.p.y < 100 ? 1 : -1;
}
p.x += p.dx * p.speed * dt;
p.y += p.dy * p.speed * dt;
var maxX = Q.width - p.w;
if(p.x < 0) { p.x = 0; p.dx = 1; }
else if(p.x > maxX) { p.dx = -1; p.x = maxX; }
if(p.y < 0 || p.y > Q.height) {
p.x = 200; p.y = 100;
p.dy *= -1;
}
if(gameType == 'master') {
p.ballSend -= dt;
if(p.ballSend < 0) {
socket.emit("ball", { x: p.x, y: p.y, dx: p.dx, dy: p.dy });
p.ballSend += p.ballRate;
}
}
},
draw: function(ctx) {
ctx.fillStyle = "black";
ctx.beginPath();
ctx.arc(this.p.x + this.p.w/2,
this.p.y + this.p.h/2,
this.p.w/2,0,Math.PI*2);
ctx.fill();
}
});
Q.scene('game',new Q.Scene(function(stage) {
if(gameType == 'master') {
stage.insert(new Q.PlayerPaddle({ x:0, y: 40}));
stage.insert(new Q.EnemyPaddle({ x:0, y: Q.height - 100}));
} else if(gameType == 'slave') {
stage.insert(new Q.EnemyPaddle({ x:0, y: 40}));
stage.insert(new Q.PlayerPaddle({ x:0, y: Q.height - 100}));
}
stage.insert(new Q.Ball());
}));
 
Search WWH ::




Custom Search