Merge: Loose Tokens
[nit.git] / examples / mnit_dino / src / dino.nit
index fae8dbe..d92c468 100644 (file)
 # limitations under the License.
 
 # App for the Dino game, manages App lifecyle and inputs
-module dino
+module dino is
+       app_version(0, 2, git_revision)
+       app_name("mnit Dino")
+end
 
 import mnit
 
@@ -23,22 +26,21 @@ import graphism
 import fancy_dino
 import splash
 
-class DinoApp
-       super App
-
+redef class App
        var cavemen_at_first_level = 6
        var cavemen_incr = 4
 
        var game : nullable Game = null
+       var score = new Container[Int](0)
        var imgs : nullable ImageSet = null
        var splash : nullable SplashScreen = null
 
-       init do super
-
-       redef fun init_window
+       redef fun on_create
        do
                super
 
+               maximum_fps = 80
+
                var display = display
                assert display != null
 
@@ -72,12 +74,17 @@ class DinoApp
                else if input_event isa PointerEvent then
                        if game == null then
                                # start from splash
-                               game = new Game( cavemen_at_first_level )
+                               game = new Game( cavemen_at_first_level, score )
                        else if game.over and game.ready_to_start_over then
                                # play next game
                                var next_nbr_caveman = game.nbr_wanted_cavemen
-                               if game.won then next_nbr_caveman += cavemen_incr
-                               game = new Game( next_nbr_caveman )
+                               if game.won then
+                                       next_nbr_caveman += cavemen_incr
+                               else
+                                       score = new Container[Int](0)
+                                       next_nbr_caveman = cavemen_at_first_level
+                               end
+                               game = new Game( next_nbr_caveman, score )
                        else
                                # normal play
                                game.dino.going_to = (new ScreenPos( input_event.x, input_event.y )).to_game( display.as(not null) )
@@ -91,7 +98,3 @@ class DinoApp
                return false # unknown event, can be handled by something else
        end
 end
-
-var app = new DinoApp
-app.main_loop
-