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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/*!
*
* melonJS
* http://www.melonjs.org
*
* Step by step game creation tutorial
*
**/
// game resources
var g_resources= [{
name: "tiles",
type: "image",
src: "data/tiles.png"
}, {
name: "test1",
type: "tmx",
src: "data/test1.tmx"
}, {
name: "moongirl",
type: "image",
src: "data/moongirl.png"
}, {
name: "earth",
type: "image",
src: "data/earth1.jpg"
}, {
name: "jump",
type: "audio",
src: "data/",
channel: 1 // ??????
}];
var jsApp =
{
/* ---
Initialize the jsApp
--- */
onload: function()
{
// init the video
if (!me.video.init('jsapp', 640, 480, false, 1.0))
{
alert("Sorry but your browser does not support html 5 canvas.");
return;
}
// initialize the "audio"
//look for ogg, then wav. chrome seems to die if file is missing
me.audio.init("ogg,wav");
// set all resources to be loaded
me.loader.onload = this.loaded.bind(this);
// set all resources to be loaded
me.loader.preload(g_resources);
// load everything & display a loading screen
me.state.change(me.state.LOADING);
},
/* ---
callback when everything is loaded
--- */
loaded: function ()
{
// set the "Play/Ingame" Screen Object
me.state.set(me.state.PLAY, new PlayScreen());
// add player to entity pool (?)
me.entityPool.add("moongirl", PlayerEntity);
// keys
me.input.bindKey(me.input.KEY.LEFT, "left");
me.input.bindKey(me.input.KEY.RIGHT, "right");
// wonder if we can bind more than one key to jump...
me.input.bindKey(me.input.KEY.X, "jump", true);
// start the game
me.state.change(me.state.PLAY);
}
}; // jsApp
/* the in game stuff*/
var PlayScreen = me.ScreenObject.extend(
{
onResetEvent: function()
{
// stuff to reset on state change
// load level
me.levelDirector.loadLevel("test1");
},
// action to perform when game is finished (state change)
onDestroyEvent: function()
{
}
});
//bootstrap :)
window.onReady(function()
{
jsApp.onload();
});
|