Merge: gamnit: new services and a lot of bug fixes and performance improvements
[nit.git] / contrib / asteronits / src / asteronits.nit
index 588bdb6..628fc69 100644 (file)
@@ -19,10 +19,10 @@ module asteronits is
        app_version(1, 0, git_revision)
 
        android_manifest_activity """android:screenOrientation="sensorLandscape""""
-       android_api_target 15
+       android_api_target 10
 end
 
-import gamnit::simple_2d
+import gamnit::flat
 
 import game_logic
 import spritesheet
@@ -59,12 +59,19 @@ redef class App
        # Current world in play
        var world = new World(12, 2, display.aspect_ratio) is lazy
 
-       redef fun on_create
+       # Sound effects
+       private var fx_fire = new Sound("sounds/fire.ogg")
+       private var fx_explosion_ship = new Sound("sounds/explosion_ship.wav")
+       private var fx_explosion_asteroids = new Sound("sounds/explosion_asteroids.wav")
+
+       redef fun create_scene
        do
                super
 
                # Move the camera to show all the world world in the screen range
                world_camera.reset_height(world.half_height * 2.0)
+
+               ui_camera.reset_height 720.0
        end
 
        # Main spritesheet with ships, asteroids and beams
@@ -84,6 +91,8 @@ redef class App
 
        redef fun accept_event(event)
        do
+               if super then return true
+
                if event isa QuitEvent then
                        exit 0
                else if event isa KeyEvent then
@@ -104,6 +113,12 @@ redef class App
                                return true
                        else if event.name == "escape" then
                                exit 0
+                       else if event.name == "." and event.is_down then
+                               dynamic_resolution_ratio *= 2.0
+                               print dynamic_resolution_ratio
+                       else if event.name == "," and event.is_down then
+                               dynamic_resolution_ratio /= 2.0
+                               print dynamic_resolution_ratio
                        end
                end
 
@@ -123,7 +138,7 @@ redef class SpacialObject
        redef fun do_turn(dt)
        do
                super
-               sprite.rotation = rotation + pi/2.0
+               sprite.rotation = rotation - pi/2.0
        end
 
        redef fun destroy
@@ -147,6 +162,12 @@ redef class Asteroid
                sprite = new Sprite(tex, center)
                super
        end
+
+       redef fun destroy
+       do
+               super
+               app.fx_explosion_asteroids.play
+       end
 end
 
 redef class Bullet
@@ -179,11 +200,12 @@ redef class Ship
                thrust_sprite.center.x = center.x - dist_to_engine*rotation.cos
                thrust_sprite.center.y = center.y - dist_to_engine*rotation.sin
                thrust_sprite.center.z = center.z
-               thrust_sprite.rotation = rotation + pi/2.0
+               thrust_sprite.rotation = rotation - pi/2.0
 
                # Show or hide the thrust sprite
                if applied_thrust > 0.0 then
                        thrust_sprite.alpha = 1.0
+
                else if thrust_sprite.alpha > 0.0 then
                        thrust_sprite.alpha -= dt*4.0
                        if thrust_sprite.alpha < 0.0 then thrust_sprite.alpha = 0.0
@@ -192,6 +214,18 @@ redef class Ship
                # HACK, the "enemy" ship used for the player points downwards
                sprite.rotation += pi
        end
+
+       redef fun fire
+       do
+               super
+               app.fx_fire.play
+       end
+
+       redef fun hit
+       do
+               super
+               app.fx_explosion_ship.play
+       end
 end
 
 redef class KeyEvent
@@ -199,15 +233,15 @@ redef class KeyEvent
        # How does this event affect the ship thrust?
        fun thrust: Float
        do
-               if is_arrow_up or name == "w" then return 1.0
+               if name == "up" or name == "w" then return 1.0
                return 0.0
        end
 
        # How does this event affect the ship thrust?
        fun rotation: Float
        do
-               if is_arrow_right or name == "d" then return 1.0
-               if is_arrow_left or name == "a" then return -1.0
+               if name == "right" or name == "d" then return -1.0
+               if name == "left" or name == "a" then return 1.0
                return 0.0
        end
 end