examples/dino: replace closure by a custom sorter
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 7 Feb 2014 16:42:42 +0000 (11:42 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 3 Mar 2014 14:39:13 +0000 (09:39 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

examples/mnit_dino/src/game_logic.nit

index abcee06..74b8673 100644 (file)
@@ -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