From: BlackMinou Date: Mon, 22 Jun 2015 00:01:55 +0000 (+0200) Subject: mnit_ballz: Linux module X-Git-Tag: v0.7.8~29^2~7 X-Git-Url: http://nitlanguage.org mnit_ballz: Linux module Signed-off-by: BlackMinou --- diff --git a/examples/mnit_ballz/src/ballz_linux.nit b/examples/mnit_ballz/src/ballz_linux.nit new file mode 100644 index 0000000..6f089a8 --- /dev/null +++ b/examples/mnit_ballz/src/ballz_linux.nit @@ -0,0 +1,104 @@ +# this file is part of NIT ( http://www.nitlanguage.org ). +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Linux part of mnit_ballz +module ballz_linux + +import mnit::linux +import display + + +redef class App + + private var up_arrow_down = false + private var down_arrow_down = false + private var left_arrow_down = false + private var right_arrow_down = false + private var game: nullable Game is noautoinit + + redef fun run + do + maximum_fps = 50 + super + end + + redef fun on_create + do + super + game = new Game(display.width.to_f, display.height.to_f) + end + + redef fun frame_core(display) + do + if up_arrow_down then input(new SDLKeyEvent("up", true)) + if down_arrow_down then input(new SDLKeyEvent("down", true)) + if left_arrow_down then input(new SDLKeyEvent("left", true)) + if right_arrow_down then input(new SDLKeyEvent("right", true)) + + 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 + quit = true + return true + end + var game = game + if game != null then + return game.input(ie) + end + return false + end +end + +redef class Ball + + redef fun intercepts(event) + do + var value = 5.0 + if event isa SDLKeyEvent then + if event.is_arrow_left then + acceleration(value, 0.0) + app.left_arrow_down = event.is_down + end + if event.is_arrow_right then + acceleration(-value, 0.0) + app.right_arrow_down = event.is_down + end + if event.is_arrow_up then + acceleration(0.0, -value) + app.up_arrow_down = event.is_down + end + if event.is_arrow_down then + acceleration(0.0, value) + app.down_arrow_down = event.is_down + end + end + return false + end +end + +redef class Game + + redef fun input(ie) + do + ball.intercepts(ie) + return false + end +end diff --git a/tests/sav/ballz_linux.res b/tests/sav/ballz_linux.res new file mode 100644 index 0000000..18bfeab --- /dev/null +++ b/tests/sav/ballz_linux.res @@ -0,0 +1,2 @@ +../lib/mnit/linux/linux_app.nit:29,16--31: Redef Error: a virtual type cannot be refined. +../lib/mnit/linux/linux_app.nit:30,16--29: Redef Error: a virtual type cannot be refined.