test
This commit is contained in:
parent
ce81e999dd
commit
8959319580
1 changed files with 12 additions and 2 deletions
14
js/index.js
14
js/index.js
|
@ -21,6 +21,8 @@ function Game() {
|
|||
this.pos = pos;
|
||||
this.vel = vel;
|
||||
this.rot = 0;
|
||||
this.dir = 1;
|
||||
this.ticks = 1;
|
||||
this.assetsIn = {
|
||||
|
||||
};
|
||||
|
@ -38,9 +40,11 @@ Game.prototype.main = function () {
|
|||
this.vel.x *= 0.9;
|
||||
this.vel.y *= 0.9;
|
||||
|
||||
this.rot += 0.08;
|
||||
this.rot += 0.08 * this.dir;
|
||||
this.rot = this.rot % (Math.PI * 10);
|
||||
|
||||
this.ticks++;
|
||||
|
||||
this.camera.x = -this.pos.x * 0.1 + this.camera.x * 0.9;
|
||||
this.camera.y = -this.pos.y * 0.1 + this.camera.y * 0.9;
|
||||
}
|
||||
|
@ -53,7 +57,7 @@ Game.prototype.render = function () {
|
|||
|
||||
ctx.save();
|
||||
|
||||
ctx.translate(camera.x + cs/2, camera.y + cs/2);
|
||||
ctx.translate(camera.x + cs / 2, camera.y + cs / 2);
|
||||
|
||||
ctx.save();
|
||||
|
||||
|
@ -71,8 +75,14 @@ Game.prototype.render = function () {
|
|||
Game.prototype.click = function () {
|
||||
let { rot } = this;
|
||||
|
||||
if (this.ticks < 10) {
|
||||
this.dir *= -1;
|
||||
}
|
||||
|
||||
this.vel.x += Math.sin(rot) * 25;
|
||||
this.vel.y -= Math.cos(rot) * 25;
|
||||
|
||||
this.ticks = 0;
|
||||
}
|
||||
|
||||
var game = new Game();
|
||||
|
|
Loading…
Reference in a new issue