shoot: fix usage of the new App framework
authorJean Privat <jean@pryen.org>
Thu, 12 Jun 2014 16:06:17 +0000 (12:06 -0400)
committerJean Privat <jean@pryen.org>
Fri, 13 Jun 2014 00:57:07 +0000 (20:57 -0400)
#479 did the job poorly

Signed-off-by: Jean Privat <jean@pryen.org>

examples/shoot/src/shoot.nit

index ee41363..94f13e9 100644 (file)
@@ -23,16 +23,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 +166,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 +265,7 @@ end
 
 ###
 
-class ShootApp
-       super App
+redef class App
        super View
 
        var debug: Bool = false
@@ -283,8 +282,6 @@ class ShootApp
                end
        end
 
-       init do super
-
        var scene: ShotScene
 
        var img_hitbox: Image
@@ -321,6 +318,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
@@ -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