# 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 game_logic
+import android::portrait
+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
light.enabled = true
proximity.enabled = true
maximum_fps = 50
-
+ sensors_support_enabled = true
super
end
- redef fun window_created
+ 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