-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControls.js
73 lines (66 loc) · 1.54 KB
/
Controls.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
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
63
64
65
66
67
68
69
70
71
72
73
/*
Damon Gwinn
The controls:
- AD for movement left and right
- SPACE for jumping
- S for a downward force while in the air
- Click to shoot a pellet (only one on screen at a time)
*/
var LeftRightForce;
var JumpForce;
var DownForce;
var ShootForce;
function keyDown(event)
{
//console.log("In keyDown\n");
var code = event.keyCode;
if(code == 65) // a
{
MoveLeft(JumperManModel, LeftRightForce);
}
else if(code == 68) // d
{
MoveRight(JumperManModel, LeftRightForce);
}
else if(code == 83) // s
{
MoveDown(JumperManModel, DownForce);
}
else if(code == 87) // w
{
//Jump(JumperManModel, JumpForce);
}
else if(code == 32) // SPACE
{
Jump(JumperManModel, JumpForce);
}
}
function keyUp(event)
{
//console.log("In keyUp\n");
var code = event.keyCode;
if(code == 65) // a
{
StopLeft(JumperManModel, LeftRightForce);
}
else if(code == 68) // d
{
StopRight(JumperManModel, LeftRightForce);
}
else if(code == 83) // s
{
// Found this lead to unsmooth gameplay
//StopDown(JumperManModel, DownForce);
}
}
function canvasClicked(event)
{
var canvasX = event.clientX;
var canvasY = event.clientY;
// Converting to clipspace coords
xCoord = 2.0 * canvasX / VIEWPORT_WIDTH-1.0;
yCoord = -(2.0 * canvasY / VIEWPORT_HEIGHT-1.0);
//console.log(xCoord);
//console.log(yCoord);
ShootEvent(PelletModel, JumperManModel, ShootForce, xCoord, yCoord);
}