From: Alexis Laferrière Date: Wed, 24 Jan 2018 18:03:39 +0000 (-0500) Subject: examples: remove mnit_dino X-Git-Url: http://nitlanguage.org examples: remove mnit_dino Signed-off-by: Alexis Laferrière --- diff --git a/examples/mnit_dino/Makefile b/examples/mnit_dino/Makefile deleted file mode 100644 index dbc90b5..0000000 --- a/examples/mnit_dino/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -default: linux - -linux: - mkdir -p bin - ../../bin/nitc -o bin/dino src/dino_linux.nit - -android: android/res/ - mkdir -p bin - ../../bin/nitc -o bin/dino.apk src/dino_android.nit - -android-release: android/res/ - mkdir -p bin - ../../bin/nitc -o bin/dino.apk src/dino_android.nit --release - -../../contrib/inkscape_tools/bin/svg_to_icons: - $(MAKE) -C ../../contrib/inkscape_tools - -android/res/: ../../contrib/inkscape_tools/bin/svg_to_icons - mkdir -p android/res/ - ../../contrib/inkscape_tools/bin/svg_to_icons art/icon.svg --android --out android/res/ - -doc: - mkdir -p doc - ../../bin/nitdoc -d doc/ src/dino.nit src/dino_linux.nit - -pngs: - mkdir -p assets/images - tools/svg-to-pngs art/drawing.svg assets/images - -clean: - rm -rf bin/ doc/ res/ diff --git a/examples/mnit_dino/README.md b/examples/mnit_dino/README.md deleted file mode 100644 index dc46a12..0000000 --- a/examples/mnit_dino/README.md +++ /dev/null @@ -1,11 +0,0 @@ -Dino vs cavemen portable action game where the player plays the dino - -# Project Structure - -* `game_logic` defines, as its name implies, the full game logic and the basic entities. -* `graphism` defines how the game is drawn on screen with fully portable code. -* `dino` implements the the portable app structure. -* `dino_android` and `dino_linux` adapt the portable game for specific platforms. -* `fancy_dino` is an optional module which tweaks how the dino itself is drawn on screen - to create the flat rotation effect. -* `splash` defines the splash screen used while the app loads. diff --git a/examples/mnit_dino/art/drawing.svg b/examples/mnit_dino/art/drawing.svg deleted file mode 100644 index 693b704..0000000 --- a/examples/mnit_dino/art/drawing.svg +++ /dev/null @@ -1,3353 +0,0 @@ - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - You're being hunted bysavages. Run over all ofthem to survive! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - You survived! - - - - - - - - - - - - - - - - You're dead. - - - - - - - - - - - - - - - - - - - Tap to play again - - - - - - - - - - - - - - - - - - - - - Click to play again - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Hunted Dino - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Tap to play - - - - - - - - - - - - - - - - Click to play - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/mnit_dino/art/icon.svg b/examples/mnit_dino/art/icon.svg deleted file mode 100644 index ee2cf30..0000000 --- a/examples/mnit_dino/art/icon.svg +++ /dev/null @@ -1,351 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/mnit_dino/assets/images/0.png b/examples/mnit_dino/assets/images/0.png deleted file mode 100644 index 1c71a2c..0000000 Binary files a/examples/mnit_dino/assets/images/0.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/1.png b/examples/mnit_dino/assets/images/1.png deleted file mode 100644 index ace37b6..0000000 Binary files a/examples/mnit_dino/assets/images/1.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/2.png b/examples/mnit_dino/assets/images/2.png deleted file mode 100644 index 73447e6..0000000 Binary files a/examples/mnit_dino/assets/images/2.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/3.png b/examples/mnit_dino/assets/images/3.png deleted file mode 100644 index b17f046..0000000 Binary files a/examples/mnit_dino/assets/images/3.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/4.png b/examples/mnit_dino/assets/images/4.png deleted file mode 100644 index 6286125..0000000 Binary files a/examples/mnit_dino/assets/images/4.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/5.png b/examples/mnit_dino/assets/images/5.png deleted file mode 100644 index b1969b8..0000000 Binary files a/examples/mnit_dino/assets/images/5.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/6.png b/examples/mnit_dino/assets/images/6.png deleted file mode 100644 index 5dc8b4d..0000000 Binary files a/examples/mnit_dino/assets/images/6.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/7.png b/examples/mnit_dino/assets/images/7.png deleted file mode 100644 index 175c014..0000000 Binary files a/examples/mnit_dino/assets/images/7.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/8.png b/examples/mnit_dino/assets/images/8.png deleted file mode 100644 index f40379d..0000000 Binary files a/examples/mnit_dino/assets/images/8.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/9.png b/examples/mnit_dino/assets/images/9.png deleted file mode 100644 index d794791..0000000 Binary files a/examples/mnit_dino/assets/images/9.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/blood.png b/examples/mnit_dino/assets/images/blood.png deleted file mode 100644 index 29219a2..0000000 Binary files a/examples/mnit_dino/assets/images/blood.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/bush.png b/examples/mnit_dino/assets/images/bush.png deleted file mode 100644 index 205d906..0000000 Binary files a/examples/mnit_dino/assets/images/bush.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/caveman.png b/examples/mnit_dino/assets/images/caveman.png deleted file mode 100644 index 34725c7..0000000 Binary files a/examples/mnit_dino/assets/images/caveman.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/caveman_afraid.png b/examples/mnit_dino/assets/images/caveman_afraid.png deleted file mode 100644 index 69621ef..0000000 Binary files a/examples/mnit_dino/assets/images/caveman_afraid.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/caveman_ready.png b/examples/mnit_dino/assets/images/caveman_ready.png deleted file mode 100644 index 1951752..0000000 Binary files a/examples/mnit_dino/assets/images/caveman_ready.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/dino.png b/examples/mnit_dino/assets/images/dino.png deleted file mode 100644 index 266e562..0000000 Binary files a/examples/mnit_dino/assets/images/dino.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/dino_dead.png b/examples/mnit_dino/assets/images/dino_dead.png deleted file mode 100644 index 798bef1..0000000 Binary files a/examples/mnit_dino/assets/images/dino_dead.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/javelin.png b/examples/mnit_dino/assets/images/javelin.png deleted file mode 100644 index c441f60..0000000 Binary files a/examples/mnit_dino/assets/images/javelin.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/life.png b/examples/mnit_dino/assets/images/life.png deleted file mode 100644 index fc0d383..0000000 Binary files a/examples/mnit_dino/assets/images/life.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/life_empty.png b/examples/mnit_dino/assets/images/life_empty.png deleted file mode 100644 index f4c020f..0000000 Binary files a/examples/mnit_dino/assets/images/life_empty.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/play_again.png b/examples/mnit_dino/assets/images/play_again.png deleted file mode 100644 index 2f5ac97..0000000 Binary files a/examples/mnit_dino/assets/images/play_again.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/play_again_mobile.png b/examples/mnit_dino/assets/images/play_again_mobile.png deleted file mode 100644 index cce475b..0000000 Binary files a/examples/mnit_dino/assets/images/play_again_mobile.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/shadow.png b/examples/mnit_dino/assets/images/shadow.png deleted file mode 100644 index 98e64d9..0000000 Binary files a/examples/mnit_dino/assets/images/shadow.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/splash_head.png b/examples/mnit_dino/assets/images/splash_head.png deleted file mode 100644 index 180aeab..0000000 Binary files a/examples/mnit_dino/assets/images/splash_head.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/splash_play.png b/examples/mnit_dino/assets/images/splash_play.png deleted file mode 100644 index 542b181..0000000 Binary files a/examples/mnit_dino/assets/images/splash_play.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/splash_play_mobile.png b/examples/mnit_dino/assets/images/splash_play_mobile.png deleted file mode 100644 index 8a76387..0000000 Binary files a/examples/mnit_dino/assets/images/splash_play_mobile.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/splash_text.png b/examples/mnit_dino/assets/images/splash_text.png deleted file mode 100644 index 00d6157..0000000 Binary files a/examples/mnit_dino/assets/images/splash_text.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/splash_title.png b/examples/mnit_dino/assets/images/splash_title.png deleted file mode 100644 index 58266e5..0000000 Binary files a/examples/mnit_dino/assets/images/splash_title.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/you_lost.png b/examples/mnit_dino/assets/images/you_lost.png deleted file mode 100644 index 9c053fd..0000000 Binary files a/examples/mnit_dino/assets/images/you_lost.png and /dev/null differ diff --git a/examples/mnit_dino/assets/images/you_won.png b/examples/mnit_dino/assets/images/you_won.png deleted file mode 100644 index 70f5715..0000000 Binary files a/examples/mnit_dino/assets/images/you_won.png and /dev/null differ diff --git a/examples/mnit_dino/org.nitlanguage.dino.txt b/examples/mnit_dino/org.nitlanguage.dino.txt deleted file mode 100644 index df5e48d..0000000 --- a/examples/mnit_dino/org.nitlanguage.dino.txt +++ /dev/null @@ -1,10 +0,0 @@ -Categories:Nit,Games -License:Apache2 -Web Site:http://nitlanguage.org -Source Code:http://nitlanguage.org/nit.git/tree/HEAD:/examples/mnit_dino -Issue Tracker:https://github.com/nitlang/nit/issues - -Summary:Tactical arcade game -Description: -You're being hunted by puny cavemen! Defend yourself. -. diff --git a/examples/mnit_dino/package.ini b/examples/mnit_dino/package.ini deleted file mode 100644 index efa6693..0000000 --- a/examples/mnit_dino/package.ini +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name=mnit_dino -tags=game -maintainer=Alexis Laferrière -license=Apache-2.0 -[upstream] -browse=https://github.com/nitlang/nit/tree/master/examples/mnit_dino/ -git=https://github.com/nitlang/nit.git -git.directory=examples/mnit_dino/ -homepage=http://nitlanguage.org -issues=https://github.com/nitlang/nit/issues -apk=http://nitlanguage.org/fdroid/apk/dino.apk diff --git a/examples/mnit_dino/src/dino.nit b/examples/mnit_dino/src/dino.nit deleted file mode 100644 index 27ced99..0000000 --- a/examples/mnit_dino/src/dino.nit +++ /dev/null @@ -1,100 +0,0 @@ -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# Copyright 2012-2013 Alexis Laferrière -# -# 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. - -# App for the Dino game, manages App lifecyle and inputs -module dino is - app_version(0, 2, git_revision) - app_name("mnit Dino") -end - -import mnit - -import graphism -import fancy_dino -import splash - -redef class App - var cavemen_at_first_level = 6 - var cavemen_incr = 4 - - var game : nullable Game = null - var score = new Ref[Int](0) - var imgs : nullable ImageSet = null - var splash : nullable SplashScreen = null - - redef fun on_create - do - super - - maximum_fps = 80.0 - - var display = display - assert display != null - - # load only splash images - splash = new SplashScreen( self ) - splash.draw( display, false ) - - # load other images - imgs = new ImageSet( self ) - - splash.draw( display, true ) - end - - redef fun frame_core( display ) - do - var game = game - if game != null then - var turn = game.do_turn - game.draw( display, imgs.as(not null), turn ) - else - splash.draw( display, true ) - end - end - - redef fun input( input_event ) - do - if input_event isa QuitEvent then # close window button - quit = true # orders system to quit - return true # this event has been handled - - else if input_event isa PointerEvent then - if game == null then - # start from splash - game = new Game( cavemen_at_first_level, score ) - else if game.over and game.ready_to_start_over then - # play next game - var next_nbr_caveman = game.nbr_wanted_cavemen - if game.won then - next_nbr_caveman += cavemen_incr - else - score = new Ref[Int](0) - next_nbr_caveman = cavemen_at_first_level - end - game = new Game( next_nbr_caveman, score ) - else - # normal play - game.dino.going_to = (new ScreenPos( input_event.x, input_event.y )).to_game( display.as(not null) ) - end - return true - - else if input_event isa KeyEvent then - return false - end - - return false # unknown event, can be handled by something else - end -end diff --git a/examples/mnit_dino/src/dino_android.nit b/examples/mnit_dino/src/dino_android.nit deleted file mode 100644 index ebf1eaf..0000000 --- a/examples/mnit_dino/src/dino_android.nit +++ /dev/null @@ -1,55 +0,0 @@ -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# Copyright 2012-2014 Alexis Laferrière -# -# 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. - -module dino_android is - app_namespace "org.nitlanguage.dino" -end - -import dino - -import mnit::android -import android::portrait -import android::vibration - -redef class ImageSet - redef fun start_over_path do return "images/play_again_mobile.png" -end - -redef class SplashScreen - redef fun splash_play_path do return "images/splash_play_mobile.png" -end - -redef class Display - redef fun top_offset do return 92 -end - -redef class Dino - # When hit, vibrate - redef fun hit(hitter, dmg) - do - app.vibrator.vibrate 25 - super - end -end - -redef class Caveman - # When crushed, vibrate a little - redef fun die(turn) - do - app.vibrator.vibrate 10 - super - end -end diff --git a/examples/mnit_dino/src/dino_linux.nit b/examples/mnit_dino/src/dino_linux.nit deleted file mode 100644 index 5d7f97d..0000000 --- a/examples/mnit_dino/src/dino_linux.nit +++ /dev/null @@ -1,29 +0,0 @@ -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# Copyright 2012-2013 Alexis Laferrière -# -# 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. - -module dino_linux - -import dino - -import mnit::linux - -redef class ImageSet - redef fun start_over_path do return "images/play_again.png" -end - -redef class SplashScreen - redef fun splash_play_path do return "images/splash_play.png" -end diff --git a/examples/mnit_dino/src/fancy_dino.nit b/examples/mnit_dino/src/fancy_dino.nit deleted file mode 100644 index 0a486b3..0000000 --- a/examples/mnit_dino/src/fancy_dino.nit +++ /dev/null @@ -1,103 +0,0 @@ -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# Copyright 2012-2013 Alexis Laferrière -# -# 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. - -# Improves dino appearance -module fancy_dino - -import graphism - -redef class Dino - var turning_angle = 0.0 - var turning = false - var was_going_left = false - - var turning_step = 0.1 - - redef fun do_turn( turn ) - do - super - - if not turning then - if going_left != was_going_left then - turning = true - - if going_left then - turning_angle = 0.0 - else # going right - turning_angle = pi - end - end - end - - was_going_left = going_left - end - - redef fun draw( display, imgs, turn ) - do - var spos = pos.to_screen( display ) - var img : Image - if is_alive then - img = imgs.dino_img - else - img = imgs.dino_dead_img - end - var img_radius = (img.width/2).to_f - - display.blit_centered( imgs.dino_shadow, spos.x.to_i, spos.y.to_i ) - - if turning then - if going_left then - turning_angle += turning_step - else - turning_angle -= turning_step - end - - var adx = turning_angle.cos * img_radius - var ady = turning_angle.sin * img_radius # * 0.3 - - var dx = spos.x - adx - var dy = spos.y - ady - (img.height/2).to_f - var ax = spos.x + adx - var ay = spos.y + ady - (img.height/2).to_f - var bx = ax - var by = ay + img.height.to_f - var cx = dx - var cy = dy + img.height.to_f - - display.blit_stretched( img, ax, ay, bx, by, cx, cy, dx, dy ) - - if (going_left and turning_angle >= pi) or - (going_right and turning_angle <= 0.0)then - turning = false - end - else - var dx = spos.x + img_radius - var dy = spos.y - (img.height/2).to_f - var ax = spos.x - img_radius - var ay = dy - var bx = ax - var by = dy + img.height.to_f - var cx = dx - var cy = by - - if going_left then - display.blit_stretched( img, ax, ay, bx, by, cx, cy, dx, dy ) - else - display.blit_stretched( img, dx, dy, cx, cy, bx, by, ax, ay ) - end - end - end -end diff --git a/examples/mnit_dino/src/game_logic.nit b/examples/mnit_dino/src/game_logic.nit deleted file mode 100644 index 63b6d53..0000000 --- a/examples/mnit_dino/src/game_logic.nit +++ /dev/null @@ -1,386 +0,0 @@ -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# Copyright 2012-2013 Alexis Laferrière -# -# 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. - -# Entire game logic for the Dino game -# Depends only on Nit `core` library -module game_logic - -interface Turnable - fun do_turn( turn : Turn ) is abstract -end - -class Game - var nbr_wanted_cavemen : Int - - var dino = new Dino - var cavemen = new Array[Caveman] - var javelins_in_air = new Array[Javelin] - var items_on_ground = new Array[Entity] - var entities = new Array[Entity].with_items(dino) - var turn_nbr = 0 - - var over_since = 0 - - var score: Ref[Int] - - var random_radius_min = 200 - var random_radius_max = 400 - protected var random_radius_diff : Int = - random_radius_max - random_radius_min - - var entities_sorter = new EntitiesSorter - - init( cavemen_nbr : Int, score: Ref[Int] ) - do - srand_from(cavemen_nbr) - - self.score = score - - nbr_wanted_cavemen = cavemen_nbr - - for n in [0..nbr_wanted_cavemen[ do - var man = new Caveman - cavemen.add( man ) - entities.add( man ) - - var radius = (random_radius_min + random_radius_diff.rand).to_f - var angle = (2.0*pi).rand - man.pos.x = ( angle.cos * radius ).to_i - man.pos.y = ( angle.sin * radius ).to_i - end - - for b in 24.times do - var bush = new Bush - bush.pos = new GamePos([-300..300[.rand, [-400..400[.rand) - items_on_ground.add bush - entities.add bush - end - end - - fun do_turn : Turn - do - turn_nbr += 1 - var turn = new Turn( self ) - - dino.do_turn( turn ) - for man in cavemen do - man.do_turn( turn ) - if not man.is_alive then - cavemen.remove( man ) - score.item += 1 - end - end - - for j in javelins_in_air do - j.do_turn( turn ) - if j.hit_dino then - javelins_in_air.remove( j ) - entities.remove( j ) - else if j.hit_ground then - javelins_in_air.remove( j ) - items_on_ground.add( j ) - end - end - - if over and over_since == 0 then - over_since = turn.nbr - end - - # sort for blitting, firsts and in the back - entities_sorter.sort entities - - return turn - end - - fun add_javelin( j : Javelin ) - do - javelins_in_air.add( j ) - entities.add( j ) - end - - fun over : Bool do return dino.life <= 0 or cavemen.is_empty - fun won : Bool do return cavemen.is_empty and dino.is_alive - fun lost : Bool do return not won - - fun ready_to_start_over : Bool do return over_since + 80 < turn_nbr -end - -class Turn - var game : Game - var nbr : Int - - init ( g : Game ) - do - game = g - nbr = game.turn_nbr - end -end - -class GamePos - var x : Int - var y : Int - - init copy( src : GamePos ) - do - init(src.x, src.y) - end - - fun squared_dist_with( other : GamePos ) : Int - do - var dx = other.x - x - var dy = other.y - y - - return dx*dx + dy*dy - end - - redef fun to_s do return "<{x}|{y}>" -end - -class Entity - super Turnable - - fun run_over_distance_x: Int do return 50 - fun run_over_distance_y: Int do return 16 - - var pos = new GamePos( 0, 0 ) - - fun squared_dist_with_dino( game : Game ) : Int - do - return pos.squared_dist_with( game.dino.pos ) - end - - fun under_dino(game: Game): Bool - do - var dy = pos.y - game.dino.pos.y - if dy.abs > run_over_distance_y then return false - - var dx = pos.x - game.dino.pos.x - return dx.abs <= run_over_distance_x - end -end - -class MovingEntity - super Entity - - var going_to : nullable GamePos = null is writable - - fun speed : Int is abstract - - var going_left = false - var going_right = false - - redef fun do_turn( t ) - do - if going_to != null then - var ds = pos.squared_dist_with( going_to.as(not null) ) - if ds < speed*speed then - going_to = null # is there - else - var dx = going_to.x - pos.x - var dy = going_to.y - pos.y - var a = atan2( dy.to_f, dx.to_f ) - var mx = a.cos*speed.to_f - var my = a.sin*speed.to_f - - pos.x += mx.to_i - pos.y += my.to_i - - going_left = mx < 0.0 - going_right = mx > 0.0 - end - end - end -end - -class MortalEntity - super Entity - - fun is_alive : Bool is abstract -end - -class Dino - super MovingEntity - super MortalEntity - - #var running_until = 0 - var total_life = 20 - var life : Int = total_life - - redef fun speed do return 8 - - redef fun is_alive do return life > 0 - - fun hit( hitter : Entity, damage : Int ) - do - if is_alive then - life -= damage - end - end - - redef fun do_turn( t ) - do - if is_alive then - super - end - - for i in t.game.items_on_ground do - if i.under_dino(t.game) then - t.game.items_on_ground.remove i - t.game.entities.remove i - end - end - end -end - -class Caveman - super MovingEntity - super MortalEntity - - var afraid_until = 0 - var cannot_throw_until = 0 - - var throw_distance : Int = 400*40+10.rand - var fear_distance : Int = 300*20+8.rand - var flee_distance : Int = 600*60+16.rand - - var fear_duration : Int = 80+40.rand - var throw_period : Int = 40+8.rand - - var variance_angle: Float = 2.0*pi.rand - var variance_dist: Int = throw_distance.to_f.sqrt.to_i-4 - var variance_x: Int = (variance_angle.cos*variance_dist.to_f).to_i - var variance_y: Int = (variance_angle.sin*variance_dist.to_f).to_i - - redef var is_alive : Bool = true - - redef var speed: Int = 3+3.rand - - fun is_afraid( turn : Turn ) : Bool do return turn.nbr < afraid_until - fun can_throw( turn : Turn ) : Bool do return cannot_throw_until < turn.nbr - fun die(turn: Turn) do is_alive = false - - redef fun do_turn( t ) - do - if is_alive then - if under_dino(t.game) then - if t.game.dino.is_alive then die(t) - return - else if is_afraid( t ) then - # going to destination - else if t.game.dino.life <= 0 then - # dino is dead, chill - else - var dwd = squared_dist_with_dino( t.game ) - if dwd < fear_distance then - afraid_until = t.nbr + fear_duration - - var dino_pos = t.game.dino.pos - var dx = dino_pos.x - pos.x - var dy = dino_pos.y - pos.y - var a = atan2( dy.to_f, dx.to_f ) - a += pi # get opposite - a += [-100..100[.rand.to_f*pi/3.0/100.0 - var x = a.cos*flee_distance.to_f - var y = a.sin*flee_distance.to_f - going_to = new GamePos( x.to_i, y.to_i ) - else if dwd < throw_distance then - if can_throw( t ) then - cannot_throw_until = t.nbr + throw_period - var javelin = new Javelin( pos, t.game.dino.pos ) - t.game.add_javelin( javelin ) - going_to = null - end - else - # get closer to dino - var dino_pos = t.game.dino.pos - going_to = new GamePos(dino_pos.x+variance_x, dino_pos.y+variance_y) - end - end - - super - end - end -end - -class Javelin - super Entity - - var z = 400 - var angle : Float = pi/2.0 - - var thrown_angle_xy : Float - #var thrown_angle_z - var speed_z = 60 - - var hit_ground = false - var hit_dino = false - - var speed : Int = 10+2.rand - var hit_dino_distance = 128 - var hit_damage = 1 - var gravity : Int = -3 - - init ( from : GamePos, to : GamePos ) - do - var dx = to.x-from.x - var dy = to.y-from.y - thrown_angle_xy = atan2( dy.to_f, dx.to_f ) - pos = new GamePos.copy( from ) - end - - redef fun do_turn( t ) - do - var dwd = squared_dist_with_dino( t.game ) - if dwd < hit_dino_distance and t.game.dino.is_alive then - t.game.dino.hit( self, hit_damage ) - hit_dino = true - else - if z <= 0 then - hit_ground = true - if thrown_angle_xy.cos > 0.0 then - angle = pi*5.0/8.0+(pi/4.0).rand - else - # left of the screen - angle = pi*9.0/8.0+(pi/4.0).rand - end - else - # in the air - speed_z += gravity - z += speed_z - - var mx = (thrown_angle_xy.cos * speed.to_f).to_i - pos.x += mx - pos.y += (thrown_angle_xy.sin * speed.to_f).to_i - - if mx > 0 then - angle = atan2( (speed_z/10).to_f, -1.0*speed.to_f )-pi/2.0 - else - angle = atan2( (speed_z/10).to_f, speed.to_f )-pi/2.0 - end - end - end - end -end - -class Bush super Entity end - -# Sort entities on screen in order of Y, entities in the back are drawn first -class EntitiesSorter - super Comparator - redef type COMPARED: Entity - - redef fun compare(a, b) do return b.pos.y <=> a.pos.y -end diff --git a/examples/mnit_dino/src/graphism.nit b/examples/mnit_dino/src/graphism.nit deleted file mode 100644 index d7e54a4..0000000 --- a/examples/mnit_dino/src/graphism.nit +++ /dev/null @@ -1,199 +0,0 @@ -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# Copyright 2012-2013 Alexis Laferrière -# -# 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. - -# Graphism for the Dino game -# Uses the Display interface from MNit. -module graphism - -import mnit # for Display - -import game_logic - -redef class GamePos - fun to_screen( d : Display ) : ScreenPos - do - var x = x+d.width/2 - var y = d.height/2-y - return new ScreenPos( x.to_f, y.to_f ) - end -end - -class ScreenPos - var x : Float - var y : Float - - fun to_game( d : Display ) : GamePos - do - var x = x.to_i-d.width/2 - var y = d.height/2-y.to_i - return new GamePos( x, y ) - end -end - -redef class Entity - fun draw( display : Display, imgs : ImageSet, turn : Turn ) is abstract -end - -redef class Dino - # Notice: This method only implements the basic drawing feature, it is - # redefed in `fancy_dino`. If the `fancy_dino` module is imported by - # user methods, this code is dead and will never be executed. - redef fun draw( display, imgs, turn ) - do - var spos = pos.to_screen( display ) - var img : Image - if is_alive then - img = imgs.dino_img - else - img = imgs.dino_dead_img - end - display.blit_centered( img, spos.x.to_i, spos.y.to_i ) - end -end - -redef class Caveman - redef fun draw( display, imgs, turn ) - do - var man_pos = pos.to_screen( display ) - var img : Image - - if not is_alive then - img = imgs.blood_img - else if is_afraid( turn ) then - img = imgs.caveman_afraid_img - else if can_throw( turn ) then - img = imgs.caveman_ready_img - else - img = imgs.caveman_img - end - - display.blit_centered( img, man_pos.x.to_i, man_pos.y.to_i ) - end -end - -redef class Javelin - redef fun draw( display, imgs, turn ) - do - var spos = pos.to_screen( display ) - spos.y -= z.to_f/10.0 - display.blit_rotated( imgs.javelin_img, spos.x, spos.y, angle ) - end -end - -redef class Bush - redef fun draw( display, imgs, turn ) - do - var spos = pos.to_screen( display ) - var img = imgs.bush_img - display.blit_centered( img, spos.x.to_i, spos.y.to_i ) - end -end - -class ImageSet - var javelin_img : Image - - var dino_img : Image - var dino_dead_img : Image - var dino_shadow : Image - - var caveman_img : Image - var caveman_afraid_img : Image - var caveman_ready_img : Image - var blood_img : Image - var bush_img : Image - - var life_img : Image - var life_empty_img : Image - - var you_won_img : Image - var you_lost_img : Image - var start_over_img : Image - fun start_over_path : String is abstract - - var numbers: NumberImages - - init ( app : App ) - do - javelin_img = app.load_image( "images/javelin.png" ) - - dino_img = app.load_image( "images/dino.png" ) - dino_dead_img = app.load_image( "images/dino_dead.png" ) - dino_shadow = app.load_image( "images/shadow.png" ) - - caveman_img = app.load_image( "images/caveman.png" ) - caveman_afraid_img = app.load_image( "images/caveman_afraid.png" ) - caveman_ready_img = app.load_image( "images/caveman_ready.png" ) - blood_img = app.load_image( "images/blood.png" ) - bush_img = app.load_image( "images/bush.png" ) - - life_img = app.load_image( "images/life.png" ) - life_empty_img = app.load_image( "images/life_empty.png" ) - - you_won_img = app.load_image( "images/you_won.png" ) - you_lost_img = app.load_image( "images/you_lost.png" ) - start_over_img = app.load_image( start_over_path ) - - numbers = app.load_numbers("images/#.png") - end -end - -redef class Game - fun draw( display : Display, imgs : ImageSet, turn : Turn ) - do - display.clear(0.05, 0.45, 0.1) - - # entities (dino, cavemen and javelins) - for e in entities do - e.draw( display, imgs, turn ) - end - - # life - var life_out_of_ten = 10 * dino.life / dino.total_life - if dino.life*10 % dino.total_life != 0 then - life_out_of_ten += 1 - end - - for life in [0..life_out_of_ten[ do - display.blit_centered( imgs.life_img, display.width*(life+1)/11, display.top_offset ) - end - - for empty in [life_out_of_ten..10[ do - display.blit_centered( imgs.life_empty_img, display.width*(empty+1)/11, display.top_offset ) - end - - # display score - display.blit_number(imgs.numbers, score.item, display.width/11, display.top_offset+32) - - # game over messages - if over then - var concl_img : Image - if won then - concl_img = imgs.you_won_img - else - concl_img = imgs.you_lost_img - end - display.blit_centered( concl_img, display.width/2, 60+display.top_offset ) - - if ready_to_start_over then - display.blit_centered( imgs.start_over_img, display.width/2, 100+display.top_offset ) - end - end - end -end - -redef interface Display - fun top_offset: Int do return 48 -end diff --git a/examples/mnit_dino/src/splash.nit b/examples/mnit_dino/src/splash.nit deleted file mode 100644 index 49936de..0000000 --- a/examples/mnit_dino/src/splash.nit +++ /dev/null @@ -1,53 +0,0 @@ -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# Copyright 2012-2013 Alexis Laferrière -# -# 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. - -module splash - -import graphism - -class SplashScreen - var splash_title : Image - var splash_text : Image - var splash_head : Image - var splash_play : Image - fun splash_play_path : String is abstract - - init( app : App ) - do - splash_title = app.load_image( "images/splash_title.png" ) - splash_text = app.load_image( "images/splash_text.png" ) - splash_head = app.load_image( "images/splash_head.png" ) - splash_play = app.load_image( splash_play_path ) - end - - # manages entire display draw (including flipping) - fun draw( display : Display, ready : Bool ) - do - var dc = display.width/2 - - display.begin - - display.clear( 0.0, 0.5, 0.1 ) - - display.blit_centered(splash_head, dc, display.height/2+64+display.top_offset) - display.blit_centered(splash_title, dc, 32+display.top_offset) - display.blit_centered(splash_text, dc, 128+display.top_offset) - - if ready then display.blit_centered( splash_play, dc, display.height-64 ) - - display.finish - end -end diff --git a/examples/mnit_dino/tools/svg-to-pngs b/examples/mnit_dino/tools/svg-to-pngs deleted file mode 100755 index 1d3182a..0000000 --- a/examples/mnit_dino/tools/svg-to-pngs +++ /dev/null @@ -1,126 +0,0 @@ -#!/bin/bash - -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# Copyright 2012-2013 Alexis Laferrière -# -# 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. - -# This script extracts pngs from a single svg for all objects with ids -# beginning by 0. Requires Inkscape. - -# there are some trick used do to inconsistency in inkscape input and output values -# the document must be resized to fit all objects - -dir=`dirname $0` -log=$dir/`basename $0 .sh`.log - -echo $0 executed at `date` > $log - -if [ $# -ne 2 ] -then - echo "Usage: $0 source.svg destination/folder/" - exit -fi - -sourceFile="$1" -destinationFolder="$2" -if [ ! -f $sourceFile ] -then - echo "Source file \"$sourceFile\" not found." - exit -fi - -if [ ! -d $destinationFolder ] -then - echo "Destination folder \"$destinationFolder\" not found, creating it." - mkdir -p $destinationFolder -fi - - -query=`inkscape --query-all $sourceFile` -min_x=10000 -min_y=10000 -for line in $query; do - ld=(${line//,/ }) - - x=${ld[1]} - y=${ld[2]} - w=${ld[3]} - h=${ld[4]} - # remove e notation - if echo $y | grep e &> /dev/null; then - y=0 - fi - if echo $x | grep e &> /dev/null; then - x=0 - fi - - echo "$x < $min_x" | bc &> /dev/null - if [ $? ]; then - min_x=$x - fi - - y=`echo $y-$h|bc` - echo "$y < $min_y" | bc &> /dev/null - if [ $? ]; then - min_y=$y - fi -done - -full_h=`inkscape "-f$sourceFile" -C -H 2>> $log` - -for line in $query; do #`inkscape --query-all $sourceFile | grep ^0`; do - if echo $line | grep ^0 &> /dev/null; then - ld=(${line//,/ }) - id=${ld[0]} #${line:0: $[`expr index "$line" ,` - 1] } - name=${line:1: $[`expr index "$line" ,` - 2] } - - x=${ld[1]} - y=${ld[2]} - w=${ld[3]} - h=${ld[4]} - - # remove e notation - if echo $y | grep e &> /dev/null; then - y=0 - fi - if echo $x | grep e &> /dev/null; then - x=0 - fi - - # corrected dim for pow(2) - i=`bc <> $log - cw=$i - ch=$i - dw=`echo \($cw-$w\)/2|bc` - dh=`echo \($ch-$h\)/2|bc` - cx=`echo $x + \($cw-$w\)/2|bc` - cy=`echo $y + \($ch-$h\)/2|bc` - - # corrects value of y. - y=`echo $full_h - $y | bc` - - echo "x=$x y=$y w=$w h=$h" &>> $log - echo "cx=$cx cy=$cy cw=$cw ch=$ch" &>> $log - i=`echo "$i * 2" | bc` - inkscape -z -C "-f$sourceFile" "-i$id" -j "-a`echo $x-$dw|bc`:`echo $y-$h-$dh|bc`:`echo $x+$w+$dw|bc`:`echo $y+$dh|bc`" "-e$destinationFolder/$name.png" -b#000000 -y0.0 -d180 -w$i -h$i &>> $log - fi -done