Merge: Compilation to JavaScript using the Emscripten SDK
[nit.git] / examples / shoot / src / shoot.nit
index ee41363..48cadaa 100644 (file)
 
 # Space shooter.
 # This program is a fun game but also a good example of the scene2d module
-module shoot
+module shoot is
+       app_name("Space Shooter")
+       app_version(0, 1, git_revision)
+end
 
 import mnit
 import shoot_logic
@@ -23,16 +26,16 @@ redef class Sprite
        # mnit specific method to draw a sprite
        # app is used to optain the assets and the display
        # Each sprite should implements this method
-       fun draw_on_display(app: ShootApp) do end
+       fun draw_on_display(app: App) do end
 
        # Helper function to draw an image centered on the current sprite position
-       fun draw_image(app: ShootApp, img: Image)
+       fun draw_image(app: App, img: Image)
        do
                app.display.blit_centered(img, (self.x.to_f/app.scale).to_i, (self.y.to_f/app.scale).to_i)
        end
 
        # Helper function to draw an image translated and rotated on the current sprite position
-       fun draw_rotated_image(app: ShootApp, img: Image, dx, dy: Int, angle: Float)
+       fun draw_rotated_image(app: App, img: Image, dx, dy: Int, angle: Float)
        do
                app.display.blit_rotated(img, self.x.to_f/app.scale, self.y.to_f/app.scale, angle)
        end
@@ -166,8 +169,8 @@ redef class Star
 end
 
 redef class Scene
-       fun draw_on_display(app: ShootApp) do end
-       fun input(app: ShootApp, input_event: InputEvent): Bool do return false
+       fun draw_on_display(app: App) do end
+       fun input(app: App, input_event: InputEvent): Bool do return false
 end
 
 redef class PlayScene
@@ -265,8 +268,7 @@ end
 
 ###
 
-class ShootApp
-       super App
+redef class App
        super View
 
        var debug: Bool = false
@@ -283,8 +285,6 @@ class ShootApp
                end
        end
 
-       init do super
-
        var scene: ShotScene
 
        var img_hitbox: Image
@@ -321,6 +321,8 @@ class ShootApp
 
                scale = (800.0 * 600.0 / display.width.to_f / display.height.to_f).sqrt * 100.0
 
+               debug = args.length > 0 and args.first == "--debug"
+
                # TODO load assets here
                # ex: img = load_image( "img.png" )
                #     to get file located at assets/img.png before deployement
@@ -378,9 +380,6 @@ class ShootApp
                        if not self.scene.exists then quit = true
                end
                self.scene.draw_on_display(self)
-
-               # Wait the next frame
-               sys.nanosleep(0, 16000000)
        end
 
        var paused: Bool = false
@@ -410,6 +409,5 @@ if args.length > 0 and args.first == "--headless" then
        return
 end
 
-var app = new ShootApp
-app.debug = args.length > 0 and args.first == "--debug"
+app.setup
 app.run