-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_view.js
30 lines (25 loc) · 898 Bytes
/
game_view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const Util = require('./util.js');
const Asteroid = require('./asteroid.js');
const MovingObject = require('./moving_object.js');
const Game = require('./game.js');
const Ship = require('./ship.js');
const Bullet = require('./bullet.js');
// const KeyMaster = require('./keymaster.js');
function GameView(ctx) {
this.ctx = ctx;
this.game = {};
}
GameView.prototype.start = function(xDim, yDim, numAst) {
this.game = new Game(xDim, yDim, numAst);
this.bindKeyHandlers();
setInterval(() => {this.game.step();}, 20);
};
GameView.prototype.bindKeyHandlers = function() {
key('w', () => {this.game.ship.power([0,-1])});
key('s', () => {this.game.ship.power([0,1])});
key('a', () => {this.game.ship.power([-1,0])});
key('d', () => {this.game.ship.power([1,0])});
key('t', () => {this.game.ship.fireBullet()});
};
let gameview = new GameView(ctx);
gameview.start(1500, 1500, 5);