[gnome-games/gnibbles-clutter] WOrking on keypress handler and reseting the worm after its death
- From: Guillaume Béland <guillaubel src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/gnibbles-clutter] WOrking on keypress handler and reseting the worm after its death
- Date: Tue, 14 Jul 2009 22:30:55 +0000 (UTC)
commit c6472f683fbb0d223246c673137e6ceab075d5f4
Author: Guillaume Beland <guillaume beland gmail com>
Date: Tue Jul 14 18:29:57 2009 -0400
WOrking on keypress handler and reseting the worm after its death
gnibbles/gnibbles.c | 5 ++-
gnibbles/gnibbles.h | 2 +-
gnibbles/main.c | 11 ++++++---
gnibbles/worm-clutter.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
gnibbles/worm-clutter.h | 2 +-
5 files changed, 65 insertions(+), 8 deletions(-)
---
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index a69af21..2076f03 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -459,16 +459,17 @@ gnibbles_get_winner (void)
return -1;
}
-gint
+gboolean
gnibbles_keypress_worms (guint keyval)
{
gint i;
gint numworms = ggz_network_mode ? 1 : properties->numworms;
- for (i = 0; i < numworms; i++)
+ for (i = 0; i < numworms; i++) {
if (gnibbles_worm_handle_keypress (worms[i], keyval)) {
return TRUE;
}
+ }
return FALSE;
}
diff --git a/gnibbles/gnibbles.h b/gnibbles/gnibbles.h
index 7b53796..0346773 100644
--- a/gnibbles/gnibbles.h
+++ b/gnibbles/gnibbles.h
@@ -69,7 +69,7 @@ void gnibbles_init (void);
void gnibbles_add_bonus (gint regular);
gint gnibbles_move_worms (void);
gint gnibbles_get_winner (void);
-gint gnibbles_keypress_worms (guint keyval);
+gboolean gnibbles_keypress_worms (guint keyval);
void gnibbles_undraw_worms (gint data);
void gnibbles_show_scores (GtkWidget * window, gint pos);
void gnibbles_log_score (GtkWidget * window);
diff --git a/gnibbles/main.c b/gnibbles/main.c
index 3f4046e..707ec69 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -252,12 +252,15 @@ about_cb (GtkAction * action, gpointer data)
g_free (license);
}
-static gint
-key_press_cb (GtkWidget * widget, GdkEventKey * event)
+static gboolean
+key_press_cb (ClutterActor *actor, ClutterEvent *event, gpointer data)
{
hide_cursor ();
- return gnibbles_keypress_worms (event->keyval);
+ if (!(event->type == CLUTTER_KEY_PRESS))
+ return FALSE;
+
+ return gnibbles_keypress_worms (event->key.keyval);
}
static gboolean
@@ -321,7 +324,7 @@ new_game_2_cb (GtkWidget * widget, gpointer data)
if (!paused) {
if (!keyboard_id)
keyboard_id = g_signal_connect (G_OBJECT (gnibbles_board_get_stage (board)),
- "key_press_event",
+ "key-press-event",
G_CALLBACK (key_press_cb), NULL);
#ifdef GGZ_CLIENT
if (!main_id && ggz_network_mode && network_is_host ()) {
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 6e65a00..9ab54e3 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -298,6 +298,18 @@ gnibbles_worm_get_tail_direction (GnibblesWorm *worm)
return dir;
}
+static gint
+gnibbles_worm_get_actor_length (ClutterActor *actor) {
+ gint size;
+ gfloat w,h;
+
+ clutter_actor_get_size (CLUTTER_ACTOR (actor), &w, &h);
+ size = w > h ? roundf(w) : roundf(h);
+ size = roundf (size / properties->tilesize);
+
+ return size;
+}
+
GnibblesWorm*
gnibbles_worm_new (guint number, guint t_xhead,
guint t_yhead, gint t_direction)
@@ -435,6 +447,47 @@ gnibbles_worm_inverse (gpointer data)
tmp = worm->yhead;
}
+void
+gnibbles_worm_reset (GnibblesWorm * worm)
+{
+ ClutterActor *tail_actor = NULL;
+ gint length = gnibbles_worm_get_length (worm);
+ gint actor_length;
+ gint tail_dir;
+ gint i;
+
+ while (length != 0) {
+ //while (actor_length != 0)
+ tail_dir = gnibbles_worm_get_tail_direction (worm);
+ tail_actor = gnibbles_worm_get_tail_actor (worm);
+ actor_length = gnibbles_worm_get_actor_length (tail_actor);
+ switch (tail_dir) {
+ case WORMUP:
+ for (i = 0; i < actor_length; i++)
+ level->walls[worm->xtail][worm->ytail--] = EMPTYCHAR;
+ break;
+ case WORMDOWN:
+ for (i = 0; i < actor_length; i++)
+ level->walls[worm->xtail][worm->ytail++] = EMPTYCHAR;
+ break;
+ case WORMLEFT:
+ for (i = 0; i < actor_length; i++)
+ level->walls[worm->xtail--][worm->ytail] = EMPTYCHAR;
+ break;
+ case WORMRIGHT:
+ for (i = 0; i < actor_length; i++)
+ level->walls[worm->xtail++][worm->ytail] = EMPTYCHAR;
+ break;
+ default:
+ break;
+ }
+ length--;
+ }
+ gnibbles_worm_new (worm->number, worm->xstart, worm->ystart, worm->direction_start);
+ gnibbles_worm_destroy (worm);
+
+}
+
void
gnibbles_worm_resize (GnibblesWorm *worm, gint newtile)
{
diff --git a/gnibbles/worm-clutter.h b/gnibbles/worm-clutter.h
index 5c49022..5269694 100644
--- a/gnibbles/worm-clutter.h
+++ b/gnibbles/worm-clutter.h
@@ -68,7 +68,7 @@ void gnibbles_worm_destroy (GnibblesWorm * worm);
void gnibbles_worm_inverse (gpointer data);
void gnibbles_worm_resize (GnibblesWorm *worm, gint newtile);
-
+void gnibbles_worm_reset (GnibblesWorm *worm);
void gnibbles_worm_move_straight_worm (GnibblesWorm *worm);
void gnibbles_worm_move_head (GnibblesWorm *worm);
void gnibbles_worm_move_tail (GnibblesWorm *worm);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]