From: Alexis Laferrière Date: Fri, 7 Feb 2014 16:42:42 +0000 (-0500) Subject: examples/dino: replace closure by a custom sorter X-Git-Tag: v0.6.5~58^2~3 X-Git-Url: http://nitlanguage.org?hp=dcb1f37c02494a5740f0283b490261e25c705725 examples/dino: replace closure by a custom sorter Signed-off-by: Alexis Laferrière --- diff --git a/examples/mnit_dino/src/game_logic.nit b/examples/mnit_dino/src/game_logic.nit index abcee06..74b8673 100644 --- a/examples/mnit_dino/src/game_logic.nit +++ b/examples/mnit_dino/src/game_logic.nit @@ -39,6 +39,8 @@ class Game protected var random_radius_diff : Int = random_radius_max - random_radius_min + var entities_sorter = new EntitiesSorter + init( cavemen_nbr : Int ) do srand @@ -86,8 +88,7 @@ class Game end # sort for blitting, firsts and in the back - # FIXME: remove closure - entities.sort !cmp( a, b ) = b.pos.y <=> a.pos.y + entities_sorter.sort entities return turn end @@ -337,3 +338,10 @@ class Javelin end end end + +# Sort entities on screen in order of Y, entities in the back are drawn first +class EntitiesSorter + super AbstractSorter[Entity] + + redef fun compare(a, b) do return b.pos.y <=> a.pos.y +end