/moongirl

To get this branch, use:
bzr branch http://9ix.org/moongirl
2 by Josh C
tutorial files
1
/*!
2
 * 
3
 *   melonJS
4
 *   http://www.melonjs.org
5
 *		
6
 *   Step by step game creation tutorial
7
 *
8
 **/
9
10
// game resources
4 by Josh C
platformer!
11
var g_resources= [{
12
	name: "tiles",
13
	type: "image",
14
	src: "data/tiles.png"
15
    }, {
16
	name: "test1",
17
	type: "tmx",
18
	src: "data/test1.tmx"
19
    }, {
20
	name: "moongirl",
21
	type: "image",
22
	src: "data/moongirl.png"
5 by Josh C
earth!
23
    }, {
24
	name: "earth",
25
	type: "image",
26
	src: "data/earth1.jpg"
8 by Josh C
jump noise
27
    }, {
28
	name: "jump",
29
	type: "audio",
30
	src: "data/",
31
	channel: 1 // ??????
4 by Josh C
platformer!
32
    }];
2 by Josh C
tutorial files
33
34
35
var jsApp	= 
36
{	
37
	/* ---
38
	
39
		Initialize the jsApp
40
		
41
		---			*/
42
	onload: function()
43
	{
44
		
45
		// init the video
46
		if (!me.video.init('jsapp', 640, 480, false, 1.0))
47
		{
48
			alert("Sorry but your browser does not support html 5 canvas.");
49
         return;
50
		}
51
				
52
		// initialize the "audio"
10 by Josh C
background layer - caves, and some sense to platforms
53
		//look for ogg, then wav. chrome seems to die if file is missing
8 by Josh C
jump noise
54
		me.audio.init("ogg,wav");
2 by Josh C
tutorial files
55
		
56
		// set all resources to be loaded
57
		me.loader.onload = this.loaded.bind(this);
58
		
59
		// set all resources to be loaded
60
		me.loader.preload(g_resources);
61
62
		// load everything & display a loading screen
63
		me.state.change(me.state.LOADING);
64
	},
65
	
66
	
67
	/* ---
68
	
69
		callback when everything is loaded
70
		
71
		---										*/
72
	loaded: function ()
73
	{
4 by Josh C
platformer!
74
	    // set the "Play/Ingame" Screen Object
75
	    me.state.set(me.state.PLAY, new PlayScreen());
76
77
	    // add player to entity pool (?)
78
	    me.entityPool.add("moongirl", PlayerEntity);
79
80
	    // keys
81
	    me.input.bindKey(me.input.KEY.LEFT, "left");
82
	    me.input.bindKey(me.input.KEY.RIGHT, "right");
83
	    // wonder if we can bind more than one key to jump...
84
	    me.input.bindKey(me.input.KEY.X, "jump", true);
85
	    
86
	    // start the game 
87
	    me.state.change(me.state.PLAY);
2 by Josh C
tutorial files
88
	}
89
90
}; // jsApp
91
92
/* the in game stuff*/
93
var PlayScreen = me.ScreenObject.extend(
94
{
4 by Josh C
platformer!
95
    onResetEvent: function()
96
    {	
97
	// stuff to reset on state change
98
	
99
	// load level
100
	me.levelDirector.loadLevel("test1");
101
    },
102
    
103
    // action to perform when game is finished (state change)
104
    onDestroyEvent: function()
105
    {
106
	
107
    }
2 by Josh C
tutorial files
108
});
109
110
111
//bootstrap :)
112
window.onReady(function() 
113
{
114
	jsApp.onload();
115
});