-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·62 lines (50 loc) · 1.53 KB
/
Copy pathscript.js
File metadata and controls
executable file
·62 lines (50 loc) · 1.53 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var canvas = document.querySelector('canvas');
var c = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
window.onload = function() {
var ct = document.getElementById("game");
var img=document.getElementById("ship");
var ctx = ct.getContext("2d");
ctx.drawImage(img, window.innerWidth/2, window.innerHeight/8*7, 50, 50);
}
function KeyListener() {
this.pressedKeys = [];
this.keydown = function(e) {
this.pressedKeys[e.keyCode] = true;
};
this.keyup = function(e) {
this.pressedKeys[e.keyCode] = false;
};
document.addEventListener("keydown", this.keydown.bind(this));
document.addEventListener("keyup", this.keyup.bind(this));
document.addEventListener("keyleft", this.keydown.bind(this));
document.addEventListener("keyright", this.keyup.bind(this));
}
KeyListener.prototype.isPressed = function(key)
{
return this.pressedKeys[key] ? true : false;
};
KeyListener.prototype.addKeyPressListener = function(keyCode, callback)
{
document.addEventListener("keypress", function(e) {
if (e.keyCode == keyCode)
callback(e);
});
};
function Game(){
var canvas = document.getElementById("game");
this.width = canvas.width;
this.height = canvas.height;
this.context = canvas.getContext("2d");
this.keys = new KeyListener();
this.ship = new Ship(100,100);
this.ship.y = this.height/2 - this.p1.height/2;
}
function Ship(x,y) {
this.x = x;
this.y = y;
}
Ship.prototype.draw = function(p)
{
};