[gnome-games/gnibbles-clutter] Fixed keypress queue and dequeue



commit aa73540f5e5ce942ead96eaa32f1cd72adab546b
Author: Guillaume Beland <guillaume beland gmail com>
Date:   Sat Jul 18 14:18:27 2009 -0400

    Fixed keypress queue and dequeue

 gnibbles/boni.c         |   10 +++++-----
 gnibbles/bonus.c        |    6 +++---
 gnibbles/bonus.h        |    2 --
 gnibbles/warp.c         |    4 +---
 gnibbles/warpmanager.c  |    2 +-
 gnibbles/worm-clutter.c |   23 ++++++++++++++---------
 6 files changed, 24 insertions(+), 23 deletions(-)
---
diff --git a/gnibbles/boni.c b/gnibbles/boni.c
index 5a3f4f1..bcacf9a 100644
--- a/gnibbles/boni.c
+++ b/gnibbles/boni.c
@@ -40,7 +40,7 @@ gnibbles_boni_new (void)
   int i;
   GnibblesBoni *tmp;
 
-  tmp = (GnibblesBoni *) g_malloc (sizeof (GnibblesBoni));
+  tmp = g_new (GnibblesBoni, 1);
   for (i = 0; i < MAXBONUSES; i++)
     tmp->bonuses[i] = NULL;
   tmp->numbonuses = 0;
@@ -76,7 +76,7 @@ gnibbles_boni_add_bonus (GnibblesBoni * boni, gint t_x, gint t_y,
   level->walls[t_x][t_y + 1] = t_type + 'A';
   level->walls[t_x + 1][t_y + 1] = t_type + 'A';
 
-  gnibbles_bonus_draw_clutter (boni->bonuses[boni->numbonuses]);
+  gnibbles_bonus_draw (boni->bonuses[boni->numbonuses]);
   
   boni->numbonuses++;
   if (t_type != BONUSREGULAR)
@@ -103,7 +103,7 @@ gnibbles_boni_add_bonus_final (GnibblesBoni * boni, gint t_x, gint t_y,
   level->walls[t_x][t_y + 1] = t_type + 'A';
   level->walls[t_x + 1][t_y + 1] = t_type + 'A';
 
-  gnibbles_bonus_draw_clutter (boni->bonuses[boni->numbonuses]);
+  gnibbles_bonus_draw (boni->bonuses[boni->numbonuses]);
   boni->numbonuses++;
   if (t_type != BONUSREGULAR)
     games_sound_play ("appear");
@@ -153,7 +153,7 @@ gnibbles_boni_remove_bonus (GnibblesBoni * boni, gint x, gint y)
       level->walls[boni->bonuses[i]->x][boni->bonuses[i]->y + 1] = EMPTYCHAR;
       level->walls[boni->bonuses[i]->x + 1][boni->bonuses[i]->y + 1]	= EMPTYCHAR;
 
-      gnibbles_bonus_erase_clutter (boni->bonuses[i]);
+      gnibbles_bonus_erase (boni->bonuses[i]);
       boni->bonuses[i] = boni->bonuses[--boni->numbonuses];
       return;
     }
@@ -179,7 +179,7 @@ gnibbles_boni_remove_bonus_final (GnibblesBoni * boni, gint x, gint y)
       level->walls[boni->bonuses[i]->x][boni->bonuses[i]->y + 1] = EMPTYCHAR;
       level->walls[boni->bonuses[i]->x + 1][boni->bonuses[i]->y + 1] = EMPTYCHAR;
 
-      gnibbles_bonus_erase_clutter (boni->bonuses[i]);
+      gnibbles_bonus_erase (boni->bonuses[i]);
       boni->bonuses[i] = boni->bonuses[--boni->numbonuses];
       return;
     }
diff --git a/gnibbles/bonus.c b/gnibbles/bonus.c
index 0ed710e..f64f3bf 100644
--- a/gnibbles/bonus.c
+++ b/gnibbles/bonus.c
@@ -40,7 +40,7 @@ gnibbles_bonus_new (gint t_x, gint t_y, gint t_type,
 {
   GnibblesBonus *tmp;
 
-  tmp = (GnibblesBonus *) malloc (sizeof (GnibblesBonus));
+  tmp = g_new (GnibblesBonus, 1);
 
   tmp->x = t_x;
   tmp->y = t_y;
@@ -53,7 +53,7 @@ gnibbles_bonus_new (gint t_x, gint t_y, gint t_type,
 }
 
 void
-gnibbles_bonus_draw_clutter (GnibblesBonus *bonus)
+gnibbles_bonus_draw (GnibblesBonus *bonus)
 {
   gtk_clutter_texture_set_from_pixbuf (CLUTTER_TEXTURE (bonus->actor),
                                        boni_pixmaps[bonus->type]);
@@ -69,7 +69,7 @@ gnibbles_bonus_draw_clutter (GnibblesBonus *bonus)
 }
 
 void
-gnibbles_bonus_erase_clutter (GnibblesBonus *bonus)
+gnibbles_bonus_erase (GnibblesBonus *bonus)
 {
   clutter_actor_hide (bonus->actor);
 }
diff --git a/gnibbles/bonus.h b/gnibbles/bonus.h
index a127c1c..ab79d86 100644
--- a/gnibbles/bonus.h
+++ b/gnibbles/bonus.h
@@ -46,9 +46,7 @@ GnibblesBonus *gnibbles_bonus_new (gint t_x, gint t_y, gint t_type,
 				   gint t_fake, gint t_countdown);
 
 void gnibbles_bonus_draw (GnibblesBonus * bonus);
-void gnibbles_bonus_draw_clutter (GnibblesBonus *bonus);
 
 void gnibbles_bonus_erase (GnibblesBonus * bonus);
-void gnibbles_bonus_erase_clutter (GnibblesBonus *bonus);
 
 #endif
diff --git a/gnibbles/warp.c b/gnibbles/warp.c
index 9e0b20c..b16cf9e 100644
--- a/gnibbles/warp.c
+++ b/gnibbles/warp.c
@@ -37,7 +37,7 @@ gnibbles_warp_new (gint t_x, gint t_y, gint t_wx, gint t_wy)
 {
   GnibblesWarp *tmp;
 
-  tmp = (GnibblesWarp *) g_malloc (sizeof (GnibblesWarp));
+  tmp = g_new (GnibblesWarp, 1);
 
   tmp->x = t_x;
   tmp->y = t_y;
@@ -62,6 +62,4 @@ gnibbles_warp_draw (GnibblesWarp *warp)
   clutter_actor_animate (warp->actor, CLUTTER_EASE_IN_QUAD, 410,
                          "opacity", 0xff,
                          NULL);
-
-
 }
diff --git a/gnibbles/warpmanager.c b/gnibbles/warpmanager.c
index d212ad6..26f992c 100644
--- a/gnibbles/warpmanager.c
+++ b/gnibbles/warpmanager.c
@@ -39,7 +39,7 @@ gnibbles_warpmanager_new (void)
   int i;
   GnibblesWarpManager *tmp;
 
-  tmp = (GnibblesWarpManager *) g_malloc (sizeof (GnibblesWarpManager));
+  tmp = g_new (GnibblesWarpManager, 1);
   for (i = 0; i < MAXWARPS; i++)
     tmp->warps[i] = NULL;
   tmp->numwarps = 0;
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 16370bc..fff95f3 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -102,7 +102,6 @@ worm_set_direction (int worm, int dir)
       gnibbles_worm_queue_keypress (worms[worm], dir);
       return;
     }
-
     worms[worm]->direction = dir;
     worms[worm]->keypress = 1;
   }
@@ -190,26 +189,26 @@ gnibbles_worm_handle_keypress (GnibblesWorm * worm, guint keyval)
     return TRUE;
   } else {
     if ((keyvalUpper == propsUp) && (worm->direction != WORMDOWN)) {
-      //worm_handle_direction (worm->number, WORMUP);
-      worm->direction = WORMUP;
+      worm_handle_direction (worm->number, WORMUP);
+      //worm->direction = WORMUP;
       gnibbles_worm_add_actor (worm);
       return TRUE;
     }
     if ((keyvalUpper == propsRight) && (worm->direction != WORMLEFT)) {
-      //worm_handle_direction (worm->number, WORMRIGHT);
-      worm->direction = WORMRIGHT;
+      worm_handle_direction (worm->number, WORMRIGHT);
+      //worm->direction = WORMRIGHT;
       gnibbles_worm_add_actor (worm);
       return TRUE;
     }
     if ((keyvalUpper == propsDown) && (worm->direction != WORMUP)) {
-      //worm_handle_direction (worm->number, WORMDOWN);
-      worm->direction = WORMDOWN;
+      worm_handle_direction (worm->number, WORMDOWN);
+      //worm->direction = WORMDOWN;
       gnibbles_worm_add_actor (worm);
       return TRUE;
     }
     if ((keyvalUpper == propsLeft) && (worm->direction != WORMRIGHT)) {
-      //worm_handle_direction (worm->number, WORMLEFT);
-      worm->direction = WORMLEFT;
+      worm_handle_direction (worm->number, WORMLEFT);
+      //worm->direction = WORMLEFT;
       gnibbles_worm_add_actor (worm);
       return TRUE;
     }
@@ -562,6 +561,9 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
   if (!(g_list_length (worm->list) == 1))
     return;
 
+  if (worm->human)
+    worm->keypress = 0;
+
   gfloat x,y;
   ClutterActor *head = gnibbles_worm_get_head_actor (worm);
 
@@ -629,6 +631,9 @@ gnibbles_worm_move_head (GnibblesWorm *worm)
   if (g_list_length (worm->list) <= 1)
     return;
 
+  if (worm->human)
+    worm->keypress = 0;
+  
   gfloat w,h;
   gfloat x,y;
   gfloat size;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]