[gnome-games/gnibbles-clutter] Started to tie different part of the game together & more work on worm
- From: Guillaume Béland <guillaubel src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/gnibbles-clutter] Started to tie different part of the game together & more work on worm
- Date: Fri, 26 Jun 2009 23:30:36 +0000 (UTC)
commit 88c2318f8fbe13bebbcaab5d00087a4764ce37a2
Author: Guillaume Beland <guillaume beland gmail com>
Date: Fri Jun 26 19:23:03 2009 -0400
Started to tie different part of the game together & more work on worm
-Added a bunch of "gnibbles-clutter" version of game related function
-Added a function to shrink the worm
gnibbles/gnibbles.c | 28 +++++++++++
gnibbles/gnibbles.h | 1 +
gnibbles/main.c | 125 +++++++++++++++++++++++++++++++++++++++++++----
gnibbles/main.h | 2 +-
gnibbles/worm-clutter.c | 68 +++++++++++++++++++++++++
gnibbles/worm-clutter.h | 2 +
6 files changed, 215 insertions(+), 11 deletions(-)
---
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 7544d4b..6fa9d12 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -42,6 +42,7 @@
#include "warpmanager.h"
#include "properties.h"
#include "scoreboard.h"
+#include "board.h"
#include "level.h"
#include "worm-clutter.h"
@@ -86,6 +87,7 @@ extern GtkWidget *drawing_area;
extern gchar board[BOARDWIDTH][BOARDHEIGHT];
extern GnibblesLevel *level;
+extern GnibblesBoard *clutter_board;
extern GnibblesProperties *properties;
@@ -466,6 +468,32 @@ gnibbles_load_level (GtkWidget * window, gint level)
}
void
+gnibbles_clutter_init ()
+{
+ gint i;
+
+ for (i = 0; i < properties->numworms; i++)
+ if (cworms[i])
+ gnibbles_cworm_destroy (cworms[i]);
+
+ gnibbles_scoreboard_clear (scoreboard);
+
+ for (i = 0; i < properties->numworms; i++) {
+ worms[i] = gnibbles_worm_new (i);
+ gnibbles_scoreboard_register (scoreboard, worms[i],
+ colorval_name (properties->wormprops[i]->color));
+ }
+
+ ClutterActor *stage = gnibbles_board_get_stage (clutter_board);
+ for (i = 0; i < properties->numworms; i++) {
+ clutter_container_add_actor (CLUTTER_CONTAINER (stage), cworms[i]->actors);
+ clutter_actor_raise_top (cworms[i]->actors);
+ }
+
+ gnibbles_scoreboard_update (scoreboard);
+}
+
+void
gnibbles_init (void)
{
gint i;
diff --git a/gnibbles/gnibbles.h b/gnibbles/gnibbles.h
index 05e71d3..a2e6acc 100644
--- a/gnibbles/gnibbles.h
+++ b/gnibbles/gnibbles.h
@@ -65,6 +65,7 @@ void gnibbles_clutter_load_pixmap (gint tilesize);
void gnibbles_load_pixmap (GtkWidget * window);
void gnibbles_load_logo (GtkWidget * window);
void gnibbles_load_level (GtkWidget * window, gint level);
+void gnibbles_clutter_init ();
void gnibbles_init (void);
void gnibbles_clutter_add_bonus (gint regular);
void gnibbles_add_bonus (gint regular);
diff --git a/gnibbles/main.c b/gnibbles/main.c
index b457668..e419ccf 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -403,6 +403,40 @@ network_loop (gpointer data)
#endif
static gint
+new_game_clutter_2_cb (GtkWidget * widget, gpointer data)
+{
+ if (!paused) {
+ if (!keyboard_id)
+ keyboard_id = g_signal_connect (G_OBJECT (window),
+ "key_press_event",
+ G_CALLBACK (key_press_cb), NULL);
+#ifdef GGZ_CLIENT
+ if (!main_id && ggz_network_mode && network_is_host ()) {
+ main_id = g_timeout_add (GAMEDELAY * (properties->gamespeed + NETDELAY),
+ (GSourceFunc) network_loop, NULL);
+ } else
+#endif
+ if (!main_id && !ggz_network_mode) {
+ main_id = g_timeout_add (GAMEDELAY * properties->gamespeed,
+ (GSourceFunc) main_loop, NULL);
+ }
+#ifdef GGZ_CLIENT
+ if (!add_bonus_id && network_is_host ()) {
+#else
+ if (!add_bonus_id) {
+#endif
+ add_bonus_id = g_timeout_add (BONUSDELAY *
+ properties->gamespeed,
+ (GSourceFunc) add_bonus_cb, NULL);
+ }
+ }
+
+ dummy_id = 0;
+
+ return (FALSE);
+}
+
+static gint
new_game_2_cb (GtkWidget * widget, gpointer data)
{
if (!paused) {
@@ -437,6 +471,67 @@ new_game_2_cb (GtkWidget * widget, gpointer data)
}
gint
+new_game_clutter (void)
+{
+ gtk_action_set_sensitive (new_network_action, FALSE);
+
+ if (ggz_network_mode) {
+ gtk_action_set_sensitive (pause_action, FALSE);
+ } else {
+ gtk_action_set_sensitive (pause_action, TRUE);
+ }
+ gtk_action_set_sensitive (end_game_action, TRUE);
+ gtk_action_set_sensitive (preferences_action, !ggz_network_mode);
+
+ if (game_running ()) {
+ end_game (FALSE);
+ main_id = 0;
+ }
+
+ gnibbles_clutter_init ();
+
+ if (ggz_network_mode || !properties->random) {
+ current_level = properties->startlevel;
+ } else {
+ current_level = rand () % MAXLEVEL + 1;
+ }
+
+ //zero_board ();
+ level = gnibbles_level_new (current_level);
+ gnibbles_board_load_level (clutter_board, level);
+ gnibbles_clutter_add_bonus (1);
+
+ paused = 0;
+ gtk_action_set_visible (pause_action, !paused);
+ gtk_action_set_visible (resume_action, paused);
+ gtk_action_set_visible (player_list_action, ggz_network_mode);
+
+ if (erase_id) {
+ g_source_remove (erase_id);
+ erase_id = 0;
+ }
+
+ if (restart_id) {
+ g_source_remove (restart_id);
+ restart_id = 0;
+ }
+
+ if (add_bonus_id) {
+ g_source_remove (add_bonus_id);
+ add_bonus_id = 0;
+ }
+
+ if (dummy_id)
+ g_source_remove (dummy_id);
+
+ dummy_id = g_timeout_add_seconds (1, (GSourceFunc) new_game_clutter_2_cb, NULL);
+
+ network_gui_update ();
+
+ return TRUE;
+}
+
+gint
new_game (void)
{
gtk_action_set_sensitive (new_network_action, FALSE);
@@ -503,7 +598,6 @@ new_game_cb (GtkAction * action, gpointer data)
new_game ();
}
-
gint
pause_game_cb (GtkAction * action, gpointer data)
{
@@ -514,16 +608,16 @@ pause_game_cb (GtkAction * action, gpointer data)
if (main_id || erase_id || restart_id || dummy_id) {
paused = 1;
if (main_id) {
- g_source_remove (main_id);
- main_id = 0;
+ g_source_remove (main_id);
+ main_id = 0;
}
if (keyboard_id) {
- g_signal_handler_disconnect (G_OBJECT (window), keyboard_id);
- keyboard_id = 0;
+ g_signal_handler_disconnect (G_OBJECT (window), keyboard_id);
+ keyboard_id = 0;
}
if (add_bonus_id) {
- g_source_remove (add_bonus_id);
- add_bonus_id = 0;
+ g_source_remove (add_bonus_id);
+ add_bonus_id = 0;
}
}
}
@@ -607,11 +701,22 @@ static gint
add_bonus_cb (gpointer data)
{
gnibbles_add_bonus (0);
-
+ gnibbles_clutter_add_bonus (0);
return (TRUE);
}
static gint
+restart_game_clutter (gpointer data)
+{
+ level = gnibbles_level_new (current_level);
+ gnibbles_board_load_level (clutter_board, level);
+ gnibbles_clutter_add_bonus (1);
+ dummy_id = g_timeout_add_seconds (1, (GSourceFunc) new_game_2_cb, NULL);
+ restart_id = 0;
+
+ return FALSE;
+}
+static gint
restart_game (gpointer data)
{
zero_board ();
@@ -879,7 +984,7 @@ create_menus (GtkUIManager * ui_manager)
}
static void
-setup_window_clutter (GnibblesBoard *clutter_board)
+setup_window_clutter ()
{
GtkWidget *vbox;
GtkWidget *main_vbox;
@@ -1276,7 +1381,7 @@ main (int argc, char **argv)
gnibbles_clutter_load_pixmap (properties->tilesize);
clutter_board = gnibbles_board_new (BOARDWIDTH, BOARDHEIGHT);
- setup_window_clutter (clutter_board);
+ setup_window_clutter ();
ClutterActor *stage = gnibbles_board_get_stage (clutter_board);
diff --git a/gnibbles/main.h b/gnibbles/main.h
index 76870ce..ae9ce60 100644
--- a/gnibbles/main.h
+++ b/gnibbles/main.h
@@ -38,9 +38,9 @@ char names[NUMWORMS][17];
gint game_running (void);
gint pause_game_cb (GtkAction * action, gpointer data);
void end_game (gboolean);
+gint new_game_clutter ();
gint new_game (void);
gint main_loop (gpointer data);
-void load_pixmap (gint tilesize);
extern GamesScores *highscores;
extern GtkWidget *notebook;
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 7e6198f..4fd0db1 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -424,6 +424,74 @@ gnibbles_cworm_move_tail (GnibblesCWorm *worm)
}
}
+void
+gnibbles_cworm_shrink (GnibblesCWorm *worm, gint shrinksize)
+{
+ ClutterActor *tmp = NULL;
+ gint nbr_actor;
+ int i;
+ gfloat w,h;
+ gfloat actor_size;
+ gint dir;
+
+ nbr_actor = g_list_length (worm->list);
+
+ //TODO: add animation
+ for (i = 0; i < nbr_actor; i++) {
+ tmp = CLUTTER_ACTOR (g_list_last (worm->list)->data);
+ clutter_actor_get_size (CLUTTER_ACTOR (tmp), &w, &h);
+ actor_size = w < h ? roundf (h) : roundf (w);
+ actor_size /= properties->tilesize;
+
+ if (actor_size > shrinksize) {
+ dir = gnibbles_cworm_get_tail_direction (worm);
+ switch (dir) {
+ case WORMDOWN:
+ worm->ytail += shrinksize;
+ clutter_actor_set_position (CLUTTER_ACTOR (tmp),
+ worm->xtail * properties->tilesize,
+ worm->ytail * properties->tilesize);
+ clutter_actor_set_size (CLUTTER_ACTOR (tmp),
+ properties->tilesize,
+ (actor_size - shrinksize) * properties->tilesize);
+ break;
+ case WORMUP:
+ worm->ytail -= shrinksize;
+ clutter_actor_set_size (CLUTTER_ACTOR (tmp),
+ (actor_size - shrinksize) * properties->tilesize,
+ properties->tilesize);
+ break;
+ case WORMRIGHT:
+ worm->xtail += shrinksize;
+ clutter_actor_set_position (CLUTTER_ACTOR (tmp),
+ worm->xtail * properties->tilesize,
+ worm->ytail * properties->tilesize);
+ clutter_actor_set_size (CLUTTER_ACTOR (tmp),
+ (actor_size - shrinksize) * properties->tilesize,
+ properties->tilesize);
+ break;
+ case WORMLEFT:
+ worm->xtail -= shrinksize;
+ clutter_actor_set_size (CLUTTER_ACTOR (tmp),
+ (actor_size - shrinksize) * properties->tilesize,
+ properties->tilesize);
+ break;
+ default:
+ break;
+ }
+ return;
+ } else if (actor_size == shrinksize) {
+ //remove tail
+ gnibbles_cworm_remove_actor (worm);
+ return;
+ } else {
+ //remove tail, reduce the shrinksize variable by the tail's size
+ gnibbles_cworm_remove_actor (worm);
+ shrinksize -= actor_size;
+ }
+ }
+}
+
gint
gnibbles_cworm_get_length (GnibblesCWorm *worm)
{
diff --git a/gnibbles/worm-clutter.h b/gnibbles/worm-clutter.h
index 697dec2..2133783 100644
--- a/gnibbles/worm-clutter.h
+++ b/gnibbles/worm-clutter.h
@@ -77,6 +77,8 @@ void gnibbles_cworm_move_straight_worm (GnibblesCWorm *worm);
void gnibbles_cworm_move_head (GnibblesCWorm *worm);
void gnibbles_cworm_move_tail (GnibblesCWorm *worm);
+void gnibbles_cworm_grow (GnibblesCWorm *worm);
+void gnibbles_cworm_shrink (GnibblesCWorm *worm, gint shrinksize);
gint gnibbles_cworm_get_length (GnibblesCWorm *worm);
gint gnibbles_cworm_lose_life (GnibblesCWorm * worm);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]