mnit_ballz: Android module
authorBlackMinou <romain.chanoir@viacesi.fr>
Sun, 21 Jun 2015 23:59:08 +0000 (01:59 +0200)
committerBlackMinou <romain.chanoir@viacesi.fr>
Wed, 9 Sep 2015 08:34:48 +0000 (10:34 +0200)
Signed-off-by: BlackMinou <romain.chanoir@viacesi.fr>

examples/mnit_ballz/src/ballz_android.nit

index 249ee68..dc934e7 100644 (file)
@@ -1,7 +1,5 @@
 # this file is part of NIT ( http://www.nitlanguage.org ).
 #
-# Copyright 2014 Romain Chanoir <romain.chanoir@viacesi.fr>
-#
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+
+# Android part of mnit_ballz
 module ballz_android is
-       app_version(1, 0, git_revision)
+       app_version(0, 2, git_revision)
        app_name("Ballz")
+       app_namespace "org.nitlanguage.ballz"
+       android_api_target 19
 end
 
 import android::portrait
-
-import game_logic
+import android::sensors
+import display
+import mnit::android
 
 redef class App
 
-       var screen: nullable Screen
+       # The game
+       var game: nullable Game is noautoinit
 
-       redef fun run
-       do
-               sensors_support_enabled = true
+       redef fun run do
                accelerometer.enabled = true
                accelerometer.event_rate = 10000
                magnetic_field.enabled = true
@@ -37,33 +39,72 @@ redef class App
                light.enabled = true
                proximity.enabled = true
                maximum_fps = 50
-
+               sensors_support_enabled = true
                super
        end
 
        redef fun on_create
        do
                super
-               screen = new Screen(self, display.as(Display))
+               game = new Game(display.width.to_f, display.height.to_f)
        end
 
        redef fun frame_core(display)
        do
-               var screen = self.screen
-               if screen != null then
-                       screen.game.do_turn
-                       screen.do_frame(display)
+               var game = game
+               if game != null then
+                       game.do_turn
+                       game.draw(display, assets)
                end
        end
 
        redef fun input(ie)
-       do      
-               if ie isa QuitEvent then 
+       do
+               if paused then return false
+               if ie isa QuitEvent then
                        quit = true
                        return true
                end
-               if screen != null then
-                       return screen.input(ie)
+               var game = game
+               if game != null then
+                       return game.input(ie)
+               end
+               return false
+       end
+end
+
+redef class Ball
+
+       redef fun intercepts(event)
+       do
+               if event isa ASensorAccelerometer then
+                       acceleration(event.x, event.y)
+               else if event isa ASensorMagneticField then
+                       #deal with Magnetic field sensor
+                       #print "ASensorMagneticField : x = " + event.x.to_s + " y = " + event.y.to_s + " z = " + event.z.to_s
+               else if event isa ASensorGyroscope then
+                       #deal with Gyroscope sensor
+                       #print "ASensorGyroscope : x = " + event.x.to_s + " y = " + event.y.to_s + " z = " + event.z.to_s
+               else if event isa ASensorLight then
+                       #deal with light sensor
+                       #print "ASensorLight : light = " + event.light.to_s
+               else if event isa ASensorProximity then
+                       #deal with proximity sensor
+                       #print "ASensorProximity : distance = " + event.distance.to_s
+               else if event isa MotionEvent then
+               end
+               return true
+       end
+end
+
+
+redef class Game
+
+       redef fun input(ie)
+       do
+               if ie isa ASensorAccelerometer or ie isa MotionEvent then
+                       ball.intercepts(ie)
+                       return true
                end
                return false
        end