tests: test_syntax now reports other errors before the pkgconfig error
[nit.git] / examples / mnit_ballz / src / ballz_linux.nit
1 # this file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Linux part of mnit_ballz
16 module ballz_linux
17
18 import mnit::linux
19 import display
20
21
22 redef class App
23
24 private var up_arrow_down = false
25 private var down_arrow_down = false
26 private var left_arrow_down = false
27 private var right_arrow_down = false
28 private var game: nullable Game is noautoinit
29
30 redef fun run
31 do
32 maximum_fps = 50.0
33 super
34 end
35
36 redef fun on_create
37 do
38 super
39 var display = self.display.as(not null)
40 game = new Game(display.width.to_f, display.height.to_f)
41 end
42
43 redef fun frame_core(display)
44 do
45 if up_arrow_down then input(new SDLKeyEvent("up", true))
46 if down_arrow_down then input(new SDLKeyEvent("down", true))
47 if left_arrow_down then input(new SDLKeyEvent("left", true))
48 if right_arrow_down then input(new SDLKeyEvent("right", true))
49
50 var game = game
51 if game != null then
52 game.do_turn
53 game.draw(display, assets)
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 var game = game
64 if game != null then
65 return game.input(ie)
66 end
67 return false
68 end
69 end
70
71 redef class Ball
72
73 redef fun intercepts(event)
74 do
75 var value = 5.0
76 if event isa SDLKeyEvent then
77 if event.is_arrow_left then
78 acceleration(value, 0.0)
79 app.left_arrow_down = event.is_down
80 end
81 if event.is_arrow_right then
82 acceleration(-value, 0.0)
83 app.right_arrow_down = event.is_down
84 end
85 if event.is_arrow_up then
86 acceleration(0.0, -value)
87 app.up_arrow_down = event.is_down
88 end
89 if event.is_arrow_down then
90 acceleration(0.0, value)
91 app.down_arrow_down = event.is_down
92 end
93 end
94 return false
95 end
96 end
97
98 redef class Game
99
100 redef fun input(ie)
101 do
102 ball.intercepts(ie)
103 return false
104 end
105 end