affb3e9b4bf4db387de1041ea5b1b680e7c355bf
[nit.git] / examples / mnit_ballz / src / ballz_android.nit
1 # this file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Romain Chanoir <romain.chanoir@viacesi.fr>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 module ballz_android is
18 app_version(1, 0, git_revision)
19 app_name("Ballz")
20 end
21
22 import game_logic
23
24 redef class App
25
26 var screen: nullable Screen
27
28 redef fun run
29 do
30 sensors_support_enabled = true
31 accelerometer.enabled = true
32 accelerometer.event_rate = 10000
33 magnetic_field.enabled = true
34 gyroscope.enabled = true
35 light.enabled = true
36 proximity.enabled = true
37 maximum_fps = 50
38
39 super
40 end
41
42 redef fun window_created
43 do
44 super
45 screen = new Screen(self, display.as(Display))
46 end
47
48 redef fun frame_core(display)
49 do
50 var screen = self.screen
51 if screen != null then
52 screen.game.do_turn
53 screen.do_frame(display)
54 end
55 end
56
57 redef fun input(ie)
58 do
59 if ie isa QuitEvent then
60 quit = true
61 return true
62 end
63 if screen != null then
64 return screen.input(ie)
65 end
66 return false
67 end
68 end