-
Notifications
You must be signed in to change notification settings - Fork 57
/
main.js
64 lines (55 loc) · 1.65 KB
/
main.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
// The main logic for your project goes in this file.
/**
* The {@link Player} object; an {@link Actor} controlled by user input.
*/
var player;
/**
* Keys used for various directions.
*
* The property names of this object indicate actions, and the values are lists
* of keyboard keys or key combinations that will invoke these actions. Valid
* keys include anything that {@link jQuery.hotkeys} accepts. The up, down,
* left, and right properties are required if the `keys` variable exists; if
* you don't want to use them, just set them to an empty array. {@link Actor}s
* can have their own {@link Actor#keys keys} which will override the global
* set.
*/
var keys = {
up: ['up', 'w'],
down: ['down', 's'],
left: ['left', 'a'],
right: ['right', 'd'],
};
/**
* An array of image file paths to pre-load.
*/
var preloadables = [];
/**
* A magic-named function where all updates should occur.
*/
function update() {
player.update();
}
/**
* A magic-named function where all drawing should occur.
*/
function draw() {
// Draw a background. This is just for illustration so we can see scrolling.
context.drawCheckered(80, 0, 0, world.width, world.height);
player.draw();
}
/**
* A magic-named function for one-time setup.
*
* @param {Boolean} first
* true if the app is being set up for the first time; false if the app has
* been reset and is starting over.
*/
function setup(first) {
// Change the size of the playable area. Do this before placing items!
world.resize(canvas.width + 200, canvas.height + 200);
// Switch from side view to top-down.
Actor.prototype.GRAVITY = false;
// Initialize the player.
player = new Player();
}