1 # this file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Linux part of mnit_ballz
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
39 var display
= self.display
.as(not null)
40 game
= new Game(display
.width
.to_f
, display
.height
.to_f
)
43 redef fun frame_core
(display
)
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))
53 game
.draw
(display
, assets
)
59 if ie
isa QuitEvent then
73 redef fun intercepts
(event
)
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
81 if event
.is_arrow_right
then
82 acceleration
(-value
, 0.0)
83 app
.right_arrow_down
= event
.is_down
85 if event
.is_arrow_up
then
86 acceleration
(0.0, -value
)
87 app
.up_arrow_down
= event
.is_down
89 if event
.is_arrow_down
then
90 acceleration
(0.0, value
)
91 app
.down_arrow_down
= event
.is_down