nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
src/doc: move components generation from `doc_model` to `doc_html` phase
[nit.git]
/
examples
/
mnit_dino
/
src
/
game_logic.nit
diff --git
a/examples/mnit_dino/src/game_logic.nit
b/examples/mnit_dino/src/game_logic.nit
index
04ae246
..
8d1a849
100644
(file)
--- a/
examples/mnit_dino/src/game_logic.nit
+++ b/
examples/mnit_dino/src/game_logic.nit
@@
-159,18
+159,30
@@
end
class Entity
super Turnable
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
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
end
class MovingEntity
super Entity
- var going_to : nullable GamePos writable = null
+ var going_to : nullable GamePos = null is writable
fun speed : Int is abstract
fun speed : Int is abstract
@@
-230,6
+242,13
@@
class Dino
if is_alive then
super
end
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
end
end
@@
-243,7
+262,6
@@
class Caveman
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 throw_distance : Int = 400*40+10.rand
var fear_distance : Int = 300*20+8.rand
var flee_distance : Int = 600*60+16.rand
- var run_over_distance = 500
var fear_duration : Int = 80+40.rand
var throw_period : Int = 40+8.rand
var fear_duration : Int = 80+40.rand
var throw_period : Int = 40+8.rand
@@
-259,20
+277,20
@@
class Caveman
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 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
redef fun do_turn( t )
do
if is_alive then
- var dwd = squared_dist_with_dino( t.game )
-
- if dwd < run_over_distance then
- if t.game.dino.is_alive then is_alive = false
+ 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
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
if dwd < fear_distance then
afraid_until = t.nbr + fear_duration
@@
-339,6
+357,12
@@
class Javelin
else
if z <= 0 then
hit_ground = 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
else
# in the air
speed_z += gravity
@@
-362,7
+386,8
@@
class Bush super Entity end
# Sort entities on screen in order of Y, entities in the back are drawn first
class EntitiesSorter
# Sort entities on screen in order of Y, entities in the back are drawn first
class EntitiesSorter
- super AbstractSorter[Entity]
+ super Comparator
+ redef type COMPARED: Entity
redef fun compare(a, b) do return b.pos.y <=> a.pos.y
end
redef fun compare(a, b) do return b.pos.y <=> a.pos.y
end