/moongirl

To get this branch, use:
bzr branch /bzr/moongirl

« back to all changes in this revision

Viewing changes to main.js

  • Committer: Josh C
  • Date: 2012-01-13 21:21:19 UTC
  • Revision ID: josh@9ix.org-20120113212119-9g0xm8b47d7u5qvj
tutorial files

Show diffs side-by-side

added added

removed removed

 
1
/*!
 
2
 * 
 
3
 *   melonJS
 
4
 *   http://www.melonjs.org
 
5
 *              
 
6
 *   Step by step game creation tutorial
 
7
 *
 
8
 **/
 
9
 
 
10
// game resources
 
11
var g_resources= [];
 
12
 
 
13
 
 
14
var jsApp       = 
 
15
{       
 
16
        /* ---
 
17
        
 
18
                Initialize the jsApp
 
19
                
 
20
                ---                     */
 
21
        onload: function()
 
22
        {
 
23
                
 
24
                // init the video
 
25
                if (!me.video.init('jsapp', 640, 480, false, 1.0))
 
26
                {
 
27
                        alert("Sorry but your browser does not support html 5 canvas.");
 
28
         return;
 
29
                }
 
30
                                
 
31
                // initialize the "audio"
 
32
                me.audio.init("mp3,ogg");
 
33
                
 
34
                // set all resources to be loaded
 
35
                me.loader.onload = this.loaded.bind(this);
 
36
                
 
37
                // set all resources to be loaded
 
38
                me.loader.preload(g_resources);
 
39
 
 
40
                // load everything & display a loading screen
 
41
                me.state.change(me.state.LOADING);
 
42
        },
 
43
        
 
44
        
 
45
        /* ---
 
46
        
 
47
                callback when everything is loaded
 
48
                
 
49
                ---                                                                             */
 
50
        loaded: function ()
 
51
        {
 
52
                // set the "Play/Ingame" Screen Object
 
53
                me.state.set(me.state.PLAY, new PlayScreen());
 
54
      
 
55
      // start the game 
 
56
                me.state.change(me.state.PLAY);
 
57
        }
 
58
 
 
59
}; // jsApp
 
60
 
 
61
/* the in game stuff*/
 
62
var PlayScreen = me.ScreenObject.extend(
 
63
{
 
64
 
 
65
   onResetEvent: function()
 
66
        {       
 
67
      // stuff to reset on state change
 
68
        },
 
69
        
 
70
        
 
71
        /* ---
 
72
        
 
73
                 action to perform when game is finished (state change)
 
74
                
 
75
                ---     */
 
76
        onDestroyEvent: function()
 
77
        {
 
78
        
 
79
   }
 
80
 
 
81
});
 
82
 
 
83
 
 
84
//bootstrap :)
 
85
window.onReady(function() 
 
86
{
 
87
        jsApp.onload();
 
88
});