[gnome-nibbles/wip/vala: 17/64] Add multiple worm colors
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/wip/vala: 17/64] Add multiple worm colors
- Date: Sun, 9 Aug 2015 12:52:50 +0000 (UTC)
commit ec197874bd4b84a28e0ca92bd91330d6b7c57409
Author: Iulian Radu <iulian radu67 gmail com>
Date: Sun Jun 28 23:09:04 2015 +0300
Add multiple worm colors
data/org.gnome.nibbles.gschema.xml | 111 +++++++++++++++++++
data/pix/{snake-grey.svg => snake-gray.svg} | 0
src/games-gridframe.h | 2 +-
src/gnome-nibbles.vala | 40 ++++----
src/nibbles-game.vala | 24 ++--
src/nibbles-view.vala | 152 ++++++++++++++++-----------
src/worm.vala | 20 ++--
7 files changed, 244 insertions(+), 105 deletions(-)
---
diff --git a/data/org.gnome.nibbles.gschema.xml b/data/org.gnome.nibbles.gschema.xml
index 7be2d8c..686663a 100644
--- a/data/org.gnome.nibbles.gschema.xml
+++ b/data/org.gnome.nibbles.gschema.xml
@@ -34,6 +34,11 @@
<summary>Color to use for worm</summary>
<description>Color to use for worm.</description>
</key>
+ <key name="move-relative" type="b">
+ <default>false</default>
+ <summary>Use relative movement</summary>
+ <description>Use relative movement (ie. left or right only).</description>
+ </key>
<key name="key-up" type="i">
<default>65362</default>
<summary>Move up</summary>
@@ -61,6 +66,11 @@
<summary>Color to use for worm</summary>
<description>Color to use for worm.</description>
</key>
+ <key name="move-relative" type="b">
+ <default>false</default>
+ <summary>Use relative movement</summary>
+ <description>Use relative movement (ie. left or right only).</description>
+ </key>
<key name="key-up" type="i">
<default>65362</default>
<summary>Move up</summary>
@@ -88,6 +98,107 @@
<summary>Color to use for worm</summary>
<description>Color to use for worm.</description>
</key>
+ <key name="move-relative" type="b">
+ <default>false</default>
+ <summary>Use relative movement</summary>
+ <description>Use relative movement (ie. left or right only).</description>
+ </key>
+ <key name="key-up" type="i">
+ <default>65362</default>
+ <summary>Move up</summary>
+ <description>Key to use for motion up.</description>
+ </key>
+ <key name="key-down" type="i">
+ <default>65364</default>
+ <summary>Move down</summary>
+ <description>Key to use for motion down.</description>
+ </key>
+ <key name="key-left" type="i">
+ <default>65361</default>
+ <summary>Move left</summary>
+ <description>Key to use for motion left.</description>
+ </key>
+ <key name="key-right" type="i">
+ <default>65363</default>
+ <summary>Move right</summary>
+ <description>Key to use for motion right.</description>
+ </key>
+ </schema>
+ <schema id="org.gnome.nibbles.worm3" path="/org/gnome/nibbles/worm3/">
+ <key name="color" type="s">
+ <default>'yellow'</default>
+ <summary>Color to use for worm</summary>
+ <description>Color to use for worm.</description>
+ </key>
+ <key name="move-relative" type="b">
+ <default>false</default>
+ <summary>Use relative movement</summary>
+ <description>Use relative movement (ie. left or right only).</description>
+ </key>
+ <key name="key-up" type="i">
+ <default>65362</default>
+ <summary>Move up</summary>
+ <description>Key to use for motion up.</description>
+ </key>
+ <key name="key-down" type="i">
+ <default>65364</default>
+ <summary>Move down</summary>
+ <description>Key to use for motion down.</description>
+ </key>
+ <key name="key-left" type="i">
+ <default>65361</default>
+ <summary>Move left</summary>
+ <description>Key to use for motion left.</description>
+ </key>
+ <key name="key-right" type="i">
+ <default>65363</default>
+ <summary>Move right</summary>
+ <description>Key to use for motion right.</description>
+ </key>
+ </schema>
+ <schema id="org.gnome.nibbles.worm4" path="/org/gnome/nibbles/worm4/">
+ <key name="color" type="s">
+ <default>'cyan'</default>
+ <summary>Color to use for worm</summary>
+ <description>Color to use for worm.</description>
+ </key>
+ <key name="move-relative" type="b">
+ <default>false</default>
+ <summary>Use relative movement</summary>
+ <description>Use relative movement (ie. left or right only).</description>
+ </key>
+ <key name="key-up" type="i">
+ <default>65362</default>
+ <summary>Move up</summary>
+ <description>Key to use for motion up.</description>
+ </key>
+ <key name="key-down" type="i">
+ <default>65364</default>
+ <summary>Move down</summary>
+ <description>Key to use for motion down.</description>
+ </key>
+ <key name="key-left" type="i">
+ <default>65361</default>
+ <summary>Move left</summary>
+ <description>Key to use for motion left.</description>
+ </key>
+ <key name="key-right" type="i">
+ <default>65363</default>
+ <summary>Move right</summary>
+ <description>Key to use for motion right.</description>
+ </key>
+ </schema>
+ <schema id="org.gnome.nibbles.worm5" path="/org/gnome/nibbles/worm5/">
+ <key name="color" type="s">
+ <default>'purple'</default>
+ <summary>Color to use for worm</summary>
+ <description>Color to use for worm.</description>
+ </key>
+ <key name="move-relative" type="b">
+ <default>false</default>
+ <summary>Use relative movement</summary>
+ <description>Use relative movement (ie. left or right only).</description>
+ </key>
<key name="key-up" type="i">
<default>65362</default>
<summary>Move up</summary>
diff --git a/data/pix/snake-grey.svg b/data/pix/snake-gray.svg
similarity index 100%
rename from data/pix/snake-grey.svg
rename to data/pix/snake-gray.svg
diff --git a/src/games-gridframe.h b/src/games-gridframe.h
index 1a67a9c..2a8b32c 100644
--- a/src/games-gridframe.h
+++ b/src/games-gridframe.h
@@ -1,5 +1,5 @@
/* games-gridframe.h: Create a container that guarantees that the internal
- * allocated space is a fixed multiple of an integer.
+ * allocated space is a fixed multiple of an integer.
*
* Copyright 2004 by Callum McKenzie
*
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 7c461dd..1b33139 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -1,24 +1,22 @@
-using Gtk;
-
public class Nibbles : Gtk.Application
{
- private GLib.Settings settings;
- private Gee.ArrayList<GLib.Settings> worm_settings;
+ private Settings settings;
+ private Gee.ArrayList<Settings> worm_settings;
private bool is_maximized;
private bool is_tiled;
private int window_width;
private int window_height;
- private ApplicationWindow window;
- private HeaderBar headerbar;
- private Stack main_stack;
+ private Gtk.ApplicationWindow window;
+ private Gtk.HeaderBar headerbar;
+ private Gtk.Stack main_stack;
private GamesGridFrame frame;
private NibblesView? view;
private NibblesGame? game = null;
- private const GLib.ActionEntry action_entries[] =
+ private const ActionEntry action_entries[] =
{
{"start-game", start_game_cb},
{"quit", quit}
@@ -39,7 +37,7 @@ public class Nibbles : Gtk.Application
add_main_option_entries (option_entries);
}
- protected override int handle_local_options (GLib.VariantDict options)
+ protected override int handle_local_options (VariantDict options)
{
if (options.contains ("version"))
{
@@ -58,26 +56,26 @@ public class Nibbles : Gtk.Application
add_action_entries (action_entries, this);
- settings = new GLib.Settings ("org.gnome.nibbles");
- worm_settings = new Gee.ArrayList<GLib.Settings> ();
+ settings = new Settings ("org.gnome.nibbles");
+ worm_settings = new Gee.ArrayList<Settings> ();
for (int i = 0; i < NibblesGame.NUMWORMS; i++)
{
var name = "org.gnome.nibbles.worm%d".printf(i);
- worm_settings.add (new GLib.Settings (name));
+ worm_settings.add (new Settings (name));
}
set_accels_for_action ("app.quit", {"<Primary>q"});
- var builder = new Builder.from_resource ("/org/gnome/nibbles/ui/gnome-nibbles.ui");
- window = builder.get_object ("nibbles-window") as ApplicationWindow;
+ var builder = new Gtk.Builder.from_resource ("/org/gnome/nibbles/ui/gnome-nibbles.ui");
+ window = builder.get_object ("nibbles-window") as Gtk.ApplicationWindow;
window.size_allocate.connect (size_allocate_cb);
window.window_state_event.connect (window_state_event_cb);
window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
if (settings.get_boolean ("window-is-maximized"))
window.maximize ();
- headerbar = builder.get_object ("headerbar") as HeaderBar;
- main_stack = builder.get_object ("main_stack") as Stack;
+ headerbar = builder.get_object ("headerbar") as Gtk.HeaderBar;
+ main_stack = builder.get_object ("main_stack") as Gtk.Stack;
window.set_titlebar (headerbar);
add_window (window);
@@ -102,7 +100,7 @@ public class Nibbles : Gtk.Application
* * Window events
\*/
- private void size_allocate_cb (Allocation allocation)
+ private void size_allocate_cb (Gtk.Allocation allocation)
{
if (is_maximized || is_tiled)
return;
@@ -192,7 +190,7 @@ public class Nibbles : Gtk.Application
foreach (var worm in game.worms)
{
- var actors = view.worm_actors.lookup (worm);
+ var actors = view.worm_actors.get (worm);
if (actors.get_stage () == null) {
view.stage.add_child (actors);
}
@@ -232,9 +230,9 @@ public class Nibbles : Gtk.Application
catch (Error e)
{
var dialog = new Gtk.MessageDialog (null,
- DialogFlags.MODAL,
- MessageType.ERROR,
- ButtonsType.NONE,
+ Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.ERROR,
+ Gtk.ButtonsType.NONE,
"Unable to initialize Clutter:\n%s", e.message);
dialog.set_title (Environment.get_application_name ());
dialog.run ();
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index d919bad..251e100 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -5,10 +5,7 @@ public class NibblesGame : Object
public const int MINIMUM_TILE_SIZE = 7;
- public const int DEFAULTGAMEDELAY = 35;
public const int GAMEDELAY = 35;
- public const int NETDELAY = 2;
- public const int BONUSDELAY = 100;
public const int NUMWORMS = 2;
@@ -29,37 +26,35 @@ public class NibblesGame : Object
public signal void worm_moved (Worm worm);
- public HashTable<Worm, WormProperties?> worm_props;
+ public Gee.HashMap<Worm, WormProperties?> worm_props;
public NibblesGame (Settings settings)
{
walls = new int[WIDTH, HEIGHT];
worms = new Gee.LinkedList<Worm> ();
- worm_props = new HashTable<Worm, WormProperties?> (direct_hash, direct_equal);
+ worm_props = new Gee.HashMap<Worm, WormProperties?> ();
load_properties (settings);
}
public void start ()
{
add_worms ();
- Timeout.add (game_speed * (GAMEDELAY + NETDELAY), main_loop_cb);
+ var id = Timeout.add (game_speed * GAMEDELAY, main_loop_cb);
+ Source.set_name_by_id (id, "[Nibbles] main_loop_cb");
}
public void add_worms ()
{
stderr.printf("[Debug] Loading worms\n");
- stderr.printf("[Debug] worms: %d\n", worms.size);
- foreach (var worm in worms) {
- stderr.printf("[Debug] worm size %d\n", worm.list.size);
+ foreach (var worm in worms)
worm.spawn (walls);
- }
}
public void move_worms ()
{
foreach (var worm in worms)
{
- if (worm.stop)
+ if (worm.is_stopped)
continue;
foreach (var other_worm in worms)
@@ -104,21 +99,26 @@ public class NibblesGame : Object
foreach (var worm in worms)
{
var properties = WormProperties ();
+ properties.color = NibblesView.colorval_from_name (worm_settings[worm.id].get_string ("color"));
properties.up = worm_settings[worm.id].get_int ("key-up");
properties.down = worm_settings[worm.id].get_int ("key-down");
properties.left = worm_settings[worm.id].get_int ("key-left");
properties.right = worm_settings[worm.id].get_int ("key-right");
- worm_props.insert (worm, properties);
+ worm_props.set (worm, properties);
}
}
public bool handle_keypress (uint keyval)
{
foreach (var worm in worms)
+ {
if (worm.human)
+ {
if (worm.handle_keypress (keyval, worm_props))
return true;
+ }
+ }
return false;
}
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 06d6c46..30aaab1 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -1,14 +1,26 @@
+public enum Color
+{
+ RED,
+ GREEN,
+ BLUE,
+ YELLOW,
+ CYAN,
+ PURPLE,
+ GRAY
+}
+
public class NibblesView : GtkClutter.Embed
{
/* Game being played */
- private NibblesGame? _game = null;
- public NibblesGame? game
+ private NibblesGame _game;
+ public NibblesGame game
{
get { return _game; }
set
{
if (_game != null)
SignalHandler.disconnect_matched (_game, SignalMatchType.DATA, 0, 0, null, null, this);
+
_game = value;
}
}
@@ -21,8 +33,11 @@ public class NibblesView : GtkClutter.Embed
public Gdk.Pixbuf worm_pixmaps[7];
private Gdk.Pixbuf boni_pixmaps[9];
- // public Gee.ArrayList<GtkClutter.Actor> worm_actors;
- public HashTable<Worm, WormActor> worm_actors;
+ public Gee.HashMap<Worm, WormActor> worm_actors;
+
+ public const int NUM_COLORS = 7;
+
+ private static Gee.HashMap<string, Color> color_lookup;
public NibblesView (NibblesGame game)
{
@@ -59,7 +74,16 @@ public class NibblesView : GtkClutter.Embed
error ("Failed to load textures: %s", e.message);
}
- worm_actors = new HashTable<Worm, WormActor> (direct_hash, direct_equal);
+ worm_actors = new Gee.HashMap<Worm, WormActor> ();
+ color_lookup = new Gee.HashMap<string, Color> ();
+ color_lookup.set ("red", Color.RED);
+ color_lookup.set ("green", Color.GREEN);
+ color_lookup.set ("blue", Color.BLUE);
+ color_lookup.set ("yellow", Color.YELLOW);
+ color_lookup.set ("cyan", Color.CYAN);
+ color_lookup.set ("purple", Color.PURPLE);
+ color_lookup.set ("gray", Color.GRAY);
+
load_pixmap ();
stage.add_child (surface);
@@ -81,7 +105,8 @@ public class NibblesView : GtkClutter.Embed
filename = Path.build_filename (PKGDATADIR, "levels", level_name, null);
FileStream file;
- if ((file = FileStream.open (filename, "r")) == null) {
+ if ((file = FileStream.open (filename, "r")) == null)
+ {
/* Fatal console error when the game's data files are missing. */
error (_("Nibbles couldn't find pixmap file: %s"), filename);
}
@@ -98,7 +123,7 @@ public class NibblesView : GtkClutter.Embed
for (int j = 0; j < NibblesGame.WIDTH; j++)
{
- game.walls[j, i] = tmpboard get(j);
+ game.walls[j, i] = tmpboard.get(j);
switch (game.walls[j, i])
{
case 'm':
@@ -106,15 +131,12 @@ public class NibblesView : GtkClutter.Embed
if (count < game.numworms)
{
var worm = new Worm (count++, WormDirection.UP);
- worm.added.connect (worm_added_cb);
- worm.moved.connect (worm_moved_cb);
- worm.rescaled.connect (worm_rescaled_cb);
- worm.died.connect (worm_died_cb);
+ connect_signals (worm);
worm.set_start (j, i);
game.worms.add (worm);
var actors = new WormActor ();
- worm_actors.insert (worm, actors);
+ worm_actors.set (worm, actors);
}
break;
case 'n':
@@ -122,15 +144,12 @@ public class NibblesView : GtkClutter.Embed
if (count < game.numworms)
{
var worm = new Worm (count++, WormDirection.LEFT);
- worm.added.connect (worm_added_cb);
- worm.moved.connect (worm_moved_cb);
- worm.rescaled.connect (worm_rescaled_cb);
- worm.died.connect (worm_died_cb);
+ connect_signals (worm);
worm.set_start (j, i);
game.worms.add (worm);
var actors = new WormActor ();
- worm_actors.insert (worm, actors);
+ worm_actors.set (worm, actors);
}
break;
case 'o':
@@ -138,15 +157,12 @@ public class NibblesView : GtkClutter.Embed
if (count < game.numworms)
{
var worm = new Worm (count++, WormDirection.DOWN);
- worm.added.connect (worm_added_cb);
- worm.moved.connect (worm_moved_cb);
- worm.rescaled.connect (worm_rescaled_cb);
- worm.died.connect (worm_died_cb);
+ connect_signals (worm);
worm.set_start (j, i);
game.worms.add (worm);
var actors = new WormActor ();
- worm_actors.insert (worm, actors);
+ worm_actors.set (worm, actors);
}
break;
case 'p':
@@ -154,15 +170,12 @@ public class NibblesView : GtkClutter.Embed
if (count < game.numworms)
{
var worm = new Worm (count++, WormDirection.RIGHT);
- worm.added.connect (worm_added_cb);
- worm.moved.connect (worm_moved_cb);
- worm.rescaled.connect (worm_rescaled_cb);
- worm.died.connect (worm_died_cb);
+ connect_signals (worm);
worm.set_start (j, i);
game.worms.add (worm);
var actors = new WormActor ();
- worm_actors.insert (worm, actors);
+ worm_actors.set (worm, actors);
}
break;
default:
@@ -191,7 +204,7 @@ public class NibblesView : GtkClutter.Embed
{
image = new Gdk.Pixbuf.from_file_at_scale (filename, xsize, ysize, true);
}
- catch (GLib.Error e)
+ catch (Error e)
{
warning ("Failed to load pixmap file: %s", e.message);
}
@@ -200,7 +213,8 @@ public class NibblesView : GtkClutter.Embed
private void load_pixmap ()
{
- string[] bonus_files = {
+ string[] bonus_files =
+ {
"diamond.svg",
"bonus1.svg",
"bonus2.svg",
@@ -211,7 +225,8 @@ public class NibblesView : GtkClutter.Embed
"questionmark.svg"
};
- string[] small_files = {
+ string[] small_files =
+ {
"wall-straight-up.svg",
"wall-straight-side.svg",
"wall-corner-bottom-left.svg",
@@ -225,7 +240,8 @@ public class NibblesView : GtkClutter.Embed
"wall-cross.svg"
};
- string[] worm_files = {
+ string[] worm_files =
+ {
"snake-red.svg",
"snake-green.svg",
"snake-blue.svg",
@@ -235,17 +251,20 @@ public class NibblesView : GtkClutter.Embed
"snake-grey.svg"
};
- for (int i = 0; i < 8; i++) {
+ for (int i = 0; i < 8; i++)
+ {
boni_pixmaps[i] = load_pixmap_file (bonus_files[i],
2 * game.tile_size, 2 * game.tile_size);
}
- for (int i = 0; i < 11; i++) {
+ for (int i = 0; i < 11; i++)
+ {
wall_pixmaps[i] = load_pixmap_file (small_files[i],
2 * game.tile_size, 2 * game.tile_size);
}
- for (int i = 0; i < 7; i++) {
+ for (int i = 0; i < 7; i++)
+ {
worm_pixmaps[i] = load_pixmap_file (worm_files[i],
game.tile_size, game.tile_size);
}
@@ -323,7 +342,8 @@ public class NibblesView : GtkClutter.Embed
}
catch (Error e)
{
- error (e.message);
+ /* Error message when a level cannot be loaded. */
+ error (_("Error loading level: %s"), e.message);
}
if (is_wall)
@@ -376,18 +396,26 @@ public class NibblesView : GtkClutter.Embed
}
}
+ private void connect_signals (Worm worm)
+ {
+ worm.added.connect (worm_added_cb);
+ worm.moved.connect (worm_moved_cb);
+ worm.rescaled.connect (worm_rescaled_cb);
+ worm.died.connect (worm_died_cb);
+ }
+
public void worm_added_cb (Worm worm)
{
var actor = new GtkClutter.Texture ();
try
{
- actor.set_from_pixbuf (worm_pixmaps[0]);
+ actor.set_from_pixbuf (worm_pixmaps[game.worm_props.get (worm).color]);
}
catch (Clutter.TextureError e)
{
error ("Failed to set texture: %s", e.message);
}
- catch (GLib.Error e)
+ catch (Error e)
{
error ("Failed to set texture: %s", e.message);
}
@@ -395,20 +423,13 @@ public class NibblesView : GtkClutter.Embed
actor.set_size (game.tile_size, game.tile_size);
actor.set_position (worm.list.first ().x * game.tile_size, worm.list.first ().y * game.tile_size);
- var actors = worm_actors.lookup (worm);
+ var actors = worm_actors.get (worm);
actors.add_child (actor);
-
- for (int i = 0; i < 13; i++) {
- for (int j = 0; j < 20; j++)
- stderr.printf("%c ", game.walls[j, i]);
- stderr.printf("\n");
- }
- stderr.printf("\n");
}
public void worm_moved_cb (Worm worm)
{
- var actors = worm_actors.lookup (worm);
+ var actors = worm_actors.get (worm);
/* Make the worms last actor (the tail) the new head. Then remove it
* and add it again so the head is always the last child added */
@@ -416,19 +437,12 @@ public class NibblesView : GtkClutter.Embed
tail_actor.set_position (worm.list.first ().x * game.tile_size, worm.list.first ().y *
game.tile_size);
actors.remove_child (tail_actor);
actors.add_child (tail_actor);
-
- for (int i = 0; i < 13; i++) {
- for (int j = 0; j < 20; j++)
- stderr.printf("%c ", game.walls[j, i]);
- stderr.printf("\n");
- }
- stderr.printf("\n");
}
public void worm_rescaled_cb (Worm worm, int tile_size)
{
float x_pos, y_pos;
- var actors = worm_actors.lookup (worm);
+ var actors = worm_actors.get (worm);
if (actors == null)
return;
@@ -445,30 +459,30 @@ public class NibblesView : GtkClutter.Embed
{
float x, y;
var group = new Clutter.Actor ();
- var actors = worm_actors.lookup (worm);
+ var actors = worm_actors.get (worm);
foreach (var actor in actors.get_children ())
{
stderr.printf("[Debug] Before\n");
- GtkClutter.Texture tmp = new GtkClutter.Texture ();
- var color = game.worm_props.lookup (worm).color;
+ GtkClutter.Texture texture = new GtkClutter.Texture ();
+ var color = game.worm_props.get (worm).color;
try
{
- tmp.set_from_pixbuf (worm_pixmaps[color]);
+ texture.set_from_pixbuf (worm_pixmaps[color]);
}
catch (Clutter.TextureError e)
{
error ("Failed to set texture: %s", e.message);
}
- catch (GLib.Error e)
+ catch (Error e)
{
error ("Failed to set texture: %s", e.message);
}
actor.get_position (out x, out y);
- tmp.set_position (x, y);
- tmp.set_size (game.tile_size, game.tile_size);
- group.add_child (tmp);
+ texture.set_position (x, y);
+ texture.set_size (game.tile_size, game.tile_size);
+ group.add_child (texture);
stderr.printf("[Debug] After\n");
}
@@ -484,6 +498,20 @@ public class NibblesView : GtkClutter.Embed
group.set_opacity (0);
group.restore_easing_state ();
}
+
+ public static Color colorval_from_name (string name)
+ {
+ return color_lookup.get (name);
+ }
+
+ // public static string colorval_name (Color colorval)
+ // {
+ // foreach (var entry in color_lookup.entries)
+ // if (entry.value == colorval)
+ // return entry.key;
+
+ // return "unknown";
+ // }
}
public class WormActor : Clutter.Actor
diff --git a/src/worm.vala b/src/worm.vala
index 8872a9d..ec14419 100644
--- a/src/worm.vala
+++ b/src/worm.vala
@@ -32,7 +32,7 @@ public class Worm : Object
public bool human;
public bool keypress = false;
- public bool stop = false;
+ public bool is_stopped = false;
public int lives { get; private set; }
private WormDirection _direction;
@@ -122,7 +122,6 @@ public class Worm : Object
break;
}
- stderr.printf("[Debug] x %d y %d\n", position.x, position.y);
/* Add a new body piece */
list.offer_head (position);
/* Mark the tile as occupied by the worm's body */
@@ -175,7 +174,7 @@ public class Worm : Object
public void die (int[,] walls)
{
- stop = true;
+ is_stopped = true;
lose_life ();
died ();
@@ -189,7 +188,7 @@ public class Worm : Object
key_queue.clear ();
- stop = false;
+ is_stopped = false;
}
private Position position_move ()
@@ -225,7 +224,7 @@ public class Worm : Object
return position;
}
- public bool handle_keypress (uint keyval, HashTable<Worm, WormProperties?> worm_props)
+ public bool handle_keypress (uint keyval, Gee.HashMap<Worm, WormProperties?> worm_props)
{
WormProperties properties;
uint propsUp, propsDown, propsLeft, propsRight, keyvalUpper;
@@ -233,7 +232,7 @@ public class Worm : Object
if (lives <= 0)
return false;
- properties = worm_props.lookup (this);
+ properties = worm_props.get (this);
propsUp = upper_key (properties.up);
propsLeft = upper_key (properties.left);
propsDown = upper_key (properties.down);
@@ -245,15 +244,18 @@ public class Worm : Object
handle_direction (WormDirection.UP);
return true;
}
- if ((keyvalUpper == propsDown) && (direction != WormDirection.UP)) {
+ if ((keyvalUpper == propsDown) && (direction != WormDirection.UP))
+ {
handle_direction (WormDirection.DOWN);
return true;
}
- if ((keyvalUpper == propsRight) && (direction != WormDirection.LEFT)) {
+ if ((keyvalUpper == propsRight) && (direction != WormDirection.LEFT))
+ {
handle_direction (WormDirection.RIGHT);
return true;
}
- if ((keyvalUpper == propsLeft) && (direction != WormDirection.RIGHT)) {
+ if ((keyvalUpper == propsLeft) && (direction != WormDirection.RIGHT))
+ {
handle_direction (WormDirection.LEFT);
return true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]