X-Git-Url: http://nitlanguage.org diff --git a/examples/mnit_dino/src/dino.nit b/examples/mnit_dino/src/dino.nit index 6333b3e..27ced99 100644 --- a/examples/mnit_dino/src/dino.nit +++ b/examples/mnit_dino/src/dino.nit @@ -15,33 +15,32 @@ # 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 -import realtime 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 target_dt = 12000000 - var game : nullable Game = null + var score = new Ref[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.0 + var display = display assert display != null @@ -59,16 +58,8 @@ class DinoApp do var game = game if game != null then - var clock = new Clock - var turn = game.do_turn game.draw( display, imgs.as(not null), turn ) - - var dt = clock.lapse - if dt.sec == 0 and dt.nanosec < target_dt then - var sleep_t = target_dt - dt.nanosec - sys.nanosleep(0, sleep_t) - end else splash.draw( display, true ) end @@ -83,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 Ref[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) ) @@ -102,7 +98,3 @@ class DinoApp return false # unknown event, can be handled by something else end end - -var app = new DinoApp -app.main_loop -