action_nitro: general gameplay tweaks
authorAlexis Laferrière <alexis.laf@xymus.net>
Sun, 2 Apr 2017 04:06:29 +0000 (00:06 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 4 Apr 2017 21:24:52 +0000 (17:24 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/action_nitro/src/action_nitro.nit
contrib/action_nitro/src/game/core.nit
contrib/action_nitro/src/game/planegen.nit

index b780a5d..e4366e6 100644 (file)
@@ -122,6 +122,9 @@ redef class App
        private var altitude_counter = new CounterSprites(texts_sheet.n,
                new Point3d[Float](1400.0, -64.0, 0.0))
 
+       # Did the player asked to skip the intro animation?
+       private var skip_intro = false
+
        redef fun on_create
        do
                super
@@ -240,7 +243,7 @@ redef class App
                # Cinematic?
                var t = world.t
                var intro_duration = 8.0
-               if t < intro_duration then
+               if t < intro_duration and not skip_intro then
                        var pitch = t/intro_duration
                        pitch = (pitch*pi).sin
                        world_camera.pitch = pitch
@@ -248,16 +251,10 @@ redef class App
                end
 
                if world.player == null then
-                       # Game is starting!
-                       world.spawn_player
-                       world.planes.add new Airplane(new Point3d[Float](0.0, world.player.center.y - 10.0, 0.0), 16.0, 4.0)
-
-                       # Setup tutorial
-                       ui_sprites.clear
-                       ui_sprites.add_all([tutorial_wasd, tutorial_arrows, tutorial_chute])
-
                        world_camera.pitch = 0.0
                        world_camera.far = 700.0
+
+                       begin_play true
                end
 
                # Update counters
@@ -336,6 +333,20 @@ redef class App
                end
        end
 
+       # Begin playing, after intro if `initial`, otherwise after death
+       fun begin_play(initial: Bool)
+       do
+               ui_sprites.clear
+
+               world.spawn_player
+               world.planes.add new Airplane(new Point3d[Float](0.0, world.player.center.y - 10.0, 0.0), 16.0, 4.0)
+
+               if initial then
+                       # Setup tutorial
+                       ui_sprites.add_all([tutorial_wasd, tutorial_arrows, tutorial_chute])
+               end
+       end
+
        # Seconds at which the game was won, using `world.t` as reference
        private var won_at: nullable Float = null
 
@@ -350,7 +361,7 @@ redef class App
 
        redef fun accept_event(event)
        do
-               var s = super
+               if super then return true
 
                if event isa QuitEvent then
                        print perfs
@@ -397,17 +408,20 @@ redef class App
                                        else player.sprite.as(PlayerSprite).start_running
                                end
                        end
+               end
 
-                       # When player is dead, respawn on spacebar
-                       if player != null and not player.is_alive then
-                               if event.name == "space" then
-                                       ui_sprites.clear
-                                       world.spawn_player
-                               end
+               # When player is dead, respawn on spacebar or pointer depressed
+               if (event isa KeyEvent and event.name == "space") or
+                  (event isa PointerEvent and not event.is_move and event.depressed) then
+                       var player = world.player
+                       if player == null then
+                               skip_intro = true
+                       else if not player.is_alive then
+                               begin_play false
                        end
                end
 
-               return s
+               return false
        end
 end
 
index 9e437a1..25cf457 100644 (file)
@@ -238,7 +238,7 @@ abstract class Body
        end
 
        # Destroy this objects and most references to it
-       protected fun destroy(world: World) do end
+       fun destroy(world: World) do end
 
        # ---
        # Box services
index 94cb237..667783c 100644 (file)
@@ -40,7 +40,7 @@ redef class World
                for i in planes.reverse_iterator do
                        if i.out_of_screen(p, self) then
                                #print "Despawning plane"
-                               i.die(self)
+                               i.destroy self
                        end
                end
 
@@ -118,14 +118,14 @@ redef class World
                if p == null then return
                if p.altitude >= boss_altitude then
                        for e in enemies.reverse_iterator do if e isa JetpackEnemy then
-                               e.die(self)
+                               e.destroy self
                        end
                        return
                end
                for i in enemies.reverse_iterator do
                        if i.out_of_screen(p, self) then
                                #print "Despawning enemy"
-                               i.die(self)
+                               i.destroy self
                        end
                end