Merge: Give top-level methods some rules
[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
18
19 import game_logic
20
21 redef class App
22
23 var screen: nullable Screen
24
25 redef fun run
26 do
27 sensors_support_enabled = true
28 accelerometer.enabled = true
29 accelerometer.event_rate = 10000
30 magnetic_field.enabled = true
31 gyroscope.enabled = true
32 light.enabled = true
33 proximity.enabled = true
34 maximum_fps = 50
35
36 super
37 end
38
39 redef fun window_created
40 do
41 super
42 screen = new Screen(self, display.as(Display))
43 end
44
45 redef fun frame_core(display)
46 do
47 var screen = self.screen
48 if screen != null then
49 screen.game.do_turn
50 screen.do_frame(display)
51 end
52 end
53
54 redef fun input(ie)
55 do
56 if ie isa QuitEvent then
57 quit = true
58 return true
59 end
60 if screen != null then
61 return screen.input(ie)
62 end
63 return false
64 end
65 end