From e1ea57909885a1252f38c12819db87d644193974 Mon Sep 17 00:00:00 2001 From: BlackMinou Date: Mon, 22 Jun 2015 01:59:08 +0200 Subject: [PATCH] mnit_ballz: Android module Signed-off-by: BlackMinou --- examples/mnit_ballz/src/ballz_android.nit | 79 ++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 19 deletions(-) diff --git a/examples/mnit_ballz/src/ballz_android.nit b/examples/mnit_ballz/src/ballz_android.nit index 249ee68..dc934e7 100644 --- a/examples/mnit_ballz/src/ballz_android.nit +++ b/examples/mnit_ballz/src/ballz_android.nit @@ -1,7 +1,5 @@ # this file is part of NIT ( http://www.nitlanguage.org ). # -# Copyright 2014 Romain Chanoir -# # 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 @@ -14,22 +12,26 @@ # 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 -- 1.7.9.5