[gnome-games/gnibbles-clutter-rebased: 34/129] Code refactoting, some improvment on worm, warp and bonus actors added to the
- From: Jason Clinton <jclinton src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games/gnibbles-clutter-rebased: 34/129] Code refactoting, some improvment on worm, warp and bonus actors added to the
- Date: Mon, 12 Oct 2009 21:29:05 +0000 (UTC)
commit 7e7c078b8cd54d041ef65c651c2caae8a1ea069f
Author: Guillaume Beland <guillaume beland gmail com>
Date: Fri Jun 26 14:26:51 2009 -0400
Code refactoting, some improvment on worm, warp and bonus actors added to the
stage
gnibbles/bonus.c | 5 +-
gnibbles/gnibbles.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++
gnibbles/gnibbles.h | 2 +
gnibbles/main.c | 138 +++++---------------------------
gnibbles/warp.c | 6 +-
gnibbles/worm-clutter.c | 14 ++--
6 files changed, 243 insertions(+), 129 deletions(-)
---
diff --git a/gnibbles/bonus.c b/gnibbles/bonus.c
index 89fe8f5..fa4a651 100644
--- a/gnibbles/bonus.c
+++ b/gnibbles/bonus.c
@@ -28,9 +28,11 @@
#include "gnibbles.h"
#include "bonus.h"
#include "properties.h"
+#include "board.h"
extern GdkPixbuf *boni_pixmaps[];
extern GnibblesProperties *properties;
+extern GnibblesBoard *clutter_board;
GnibblesBonus *
gnibbles_bonus_new (gint t_x, gint t_y, gint t_type,
@@ -58,7 +60,8 @@ gnibbles_bonus_draw (GnibblesBonus * bonus)
clutter_actor_set_position (CLUTTER_ACTOR (bonus->actor),
bonus->x * properties->tilesize,
bonus->y * properties->tilesize);
-
+ ClutterActor *stage = gnibbles_board_get_stage (clutter_board);
+ clutter_container_add_actor (CLUTTER_CONTAINER (stage), bonus->actor);
gnibbles_draw_big_pixmap (bonus->type, bonus->x, bonus->y);
}
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 00fe38a..c5fb3d4 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -27,6 +27,7 @@
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <clutter/clutter.h>
#include <libgames-support/games-gtk-compat.h>
#include <libgames-support/games-runtime.h>
@@ -42,6 +43,7 @@
#include "warpmanager.h"
#include "properties.h"
#include "scoreboard.h"
+#include "level.h"
#include "worm-clutter.h"
@@ -57,6 +59,7 @@ GnibblesWarpManager *warpmanager;
GdkPixmap *buffer_pixmap = NULL;
GdkPixbuf *logo_pixmap = NULL;
+//old pixbuf
GdkPixbuf *bonus_pixmaps[9] = { NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL
};
@@ -66,9 +69,24 @@ GdkPixbuf *small_pixmaps[19] = { NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL
};
+// clutter-related pixbuf
+GdkPixbuf *wall_pixmaps[11] = { NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL,
+ NULL
+};
+
+GdkPixbuf *worm_pixmaps[7] = { NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL
+};
+
+GdkPixbuf *boni_pixmaps[9] = { NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL
+};
+
extern GtkWidget *drawing_area;
extern gchar board[BOARDWIDTH][BOARDHEIGHT];
+extern GnibblesLevel *level;
extern GnibblesProperties *properties;
@@ -78,6 +96,98 @@ extern GnibblesScoreboard *scoreboard;
extern guint properties->tilesize, properties->tilesize;
*/
+static GdkPixbuf *
+gnibbles_clutter_load_pixmap_file (const gchar * pixmap, gint xsize, gint ysize)
+{
+ GdkPixbuf *image;
+ gchar *filename;
+ const char *dirname;
+
+ dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
+ filename = g_build_filename (dirname, pixmap, NULL);
+
+ if (!filename) {
+ char *message =
+ g_strdup_printf (_("Nibbles couldn't find pixmap file:\n%s\n\n"
+ "Please check your Nibbles installation"), pixmap);
+ //gnibbles_error (window, message;
+ g_free(message);
+ }
+
+ image = gdk_pixbuf_new_from_file_at_scale (filename, xsize, ysize, TRUE, NULL);
+ g_free (filename);
+
+ return image;
+}
+
+void
+gnibbles_clutter_load_pixmap (gint tilesize)
+{
+ gchar *bonus_files[] = {
+ "blank.svg",
+ "diamond.svg",
+ "bonus1.svg",
+ "bonus2.svg",
+ "life.svg",
+ "bonus3.svg",
+ "bonus4.svg",
+ "bonus5.svg",
+ "questionmark.svg"
+ };
+
+ gchar *small_files[] = {
+ "wall-straight-up.svg",
+ "wall-straight-side.svg",
+ "wall-corner-bottom-left.svg",
+ "wall-corner-bottom-right.svg",
+ "wall-corner-top-left.svg",
+ "wall-corner-top-right.svg",
+ "wall-tee-up.svg",
+ "wall-tee-right.svg",
+ "wall-tee-left.svg",
+ "wall-tee-down.svg",
+ "wall-cross.svg"
+ };
+
+ gchar *worm_files[] = {
+ "snake-red.svg",
+ "snake-green.svg",
+ "snake-blue.svg",
+ "snake-yellow.svg",
+ "snake-cyan.svg",
+ "snake-magenta.svg",
+ "snake-grey.svg"
+ };
+
+ int i;
+
+ for (i = 0; i < 9; i++) {
+ if (boni_pixmaps[i])
+ g_object_unref (boni_pixmaps[i]);
+
+ boni_pixmaps[i] = gnibbles_clutter_load_pixmap_file (bonus_files[i],
+ 4 * tilesize,
+ 4 * tilesize);
+ }
+
+ for (i = 0; i < 11; i++) {
+ if (wall_pixmaps[i])
+ g_object_unref (wall_pixmaps[i]);
+
+ wall_pixmaps[i] = gnibbles_clutter_load_pixmap_file (small_files[i],
+ 2 * tilesize,
+ 2 * tilesize);
+ }
+
+ for (i = 0; i < 7; i++) {
+ if (worm_pixmaps[i])
+ g_object_unref (worm_pixmaps[i]);
+
+ worm_pixmaps[i] = gnibbles_clutter_load_pixmap_file (worm_files[i],
+ tilesize, tilesize);
+ }
+}
+
static void
gnibbles_error (GtkWidget * window, gchar * message)
{
@@ -378,6 +488,103 @@ gnibbles_init (void)
}
void
+gnibbles_clutter_add_bonus (gint regular)
+{
+ gint x, y, good;
+
+#ifdef GGZ_CLIENT
+ if (!network_is_host ()) {
+ return;
+ }
+#endif
+
+ if (regular) {
+ good = 0;
+ } else {
+ good = rand () % 50;
+ if (good)
+ return;
+ }
+
+ do {
+ good = 1;
+ x = rand () % (BOARDWIDTH - 1);
+ y = rand () % (BOARDHEIGHT - 1);
+ if (level->walls[x][y] != EMPTYCHAR)
+ good = 0;
+ if (level->walls[x + 1][y] != EMPTYCHAR)
+ good = 0;
+ if (level->walls[x][y + 1] != EMPTYCHAR)
+ good = 0;
+ if (level->walls[x + 1][y + 1] != EMPTYCHAR)
+ good = 0;
+ } while (!good);
+
+ if (regular) {
+ if ((rand () % 7 == 0) && properties->fakes)
+ gnibbles_boni_add_bonus (boni, x, y, BONUSREGULAR, 1, 300);
+ good = 0;
+ while (!good) {
+ good = 1;
+ x = rand () % (BOARDWIDTH - 1);
+ y = rand () % (BOARDHEIGHT - 1);
+ if (level->walls[x][y] != EMPTYCHAR)
+ good = 0;
+ if (level->walls[x + 1][y] != EMPTYCHAR)
+ good = 0;
+ if (level->walls[x][y + 1] != EMPTYCHAR)
+ good = 0;
+ if (level->walls[x + 1][y + 1] != EMPTYCHAR)
+ good = 0;
+ }
+ gnibbles_boni_add_bonus (boni, x, y, BONUSREGULAR, 0, 300);
+ } else if (boni->missed <= MAXMISSED) {
+ good = rand () % 7;
+
+ if (good)
+ good = 0;
+ else
+ good = 1;
+
+ if (good && !properties->fakes)
+ return;
+
+ switch (rand () % 21) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ gnibbles_boni_add_bonus (boni, x, y, BONUSHALF, good, 200);
+ break;
+ case 10:
+ case 11:
+ case 12:
+ case 13:
+ case 14:
+ gnibbles_boni_add_bonus (boni, x, y, BONUSDOUBLE, good, 150);
+ break;
+ case 15:
+ gnibbles_boni_add_bonus (boni, x, y, BONUSLIFE, good, 100);
+ break;
+ case 16:
+ case 17:
+ case 18:
+ case 19:
+ case 20:
+ if (properties->numworms > 1)
+ gnibbles_boni_add_bonus (boni, x, y, BONUSREVERSE, good, 150);
+ break;
+ }
+ }
+}
+
+void
gnibbles_add_bonus (gint regular)
{
gint x, y, good;
diff --git a/gnibbles/gnibbles.h b/gnibbles/gnibbles.h
index fc4c818..05e71d3 100644
--- a/gnibbles/gnibbles.h
+++ b/gnibbles/gnibbles.h
@@ -61,10 +61,12 @@ void gnibbles_draw_pixmap (gint which, gint x, gint y);
void gnibbles_draw_big_pixmap (gint which, gint x, gint y);
void gnibbles_draw_pixmap_buffer (gint which, gint x, gint y);
void gnibbles_draw_big_pixmap_buffer (gint which, gint x, gint y);
+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_init (void);
+void gnibbles_clutter_add_bonus (gint regular);
void gnibbles_add_bonus (gint regular);
gint gnibbles_move_worms (void);
gint gnibbles_get_winner (void);
diff --git a/gnibbles/main.c b/gnibbles/main.c
index 2c646eb..2b96982 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -86,23 +86,11 @@ extern GdkPixbuf *logo_pixmap;
GnibblesProperties *properties;
+GnibblesBoard *clutter_board;
GnibblesLevel *level;
GnibblesScoreboard *scoreboard;
-GdkPixbuf *wall_pixmaps[11] = { NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL,
- NULL
-};
-
-GdkPixbuf *worm_pixmaps[7] = { NULL, NULL, NULL, NULL, NULL,
- NULL, NULL
-};
-
-GdkPixbuf *boni_pixmaps[9] = { NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL
-};
-
extern GnibblesCWorm *cworms[];
extern GnibblesBoni *boni;
@@ -141,97 +129,6 @@ static GtkAction *scores_action;
static GtkAction *fullscreen_action;
static GtkAction *leave_fullscreen_action;
-static GdkPixbuf *
-load_pixmap_file (const gchar * pixmap, gint xsize, gint ysize)
-{
- GdkPixbuf *image;
- gchar *filename;
- const char *dirname;
-
- dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
- filename = g_build_filename (dirname, pixmap, NULL);
-
- if (!filename) {
- char *message =
- g_strdup_printf (_("Nibbles couldn't find pixmap file:\n%s\n\n"
- "Please check your Nibbles installation"), pixmap);
- //gnibbles_error (window, message;
- g_free(message);
- }
-
- image = gdk_pixbuf_new_from_file_at_scale (filename, xsize, ysize, TRUE, NULL);
- g_free (filename);
-
- return image;
-}
-
-void
-load_pixmap (gint tilesize)
-{
- gchar *bonus_files[] = {
- "blank.svg",
- "diamond.svg",
- "bonus1.svg",
- "bonus2.svg",
- "life.svg",
- "bonus3.svg",
- "bonus4.svg",
- "bonus5.svg",
- "questionmark.svg"
- };
-
- gchar *small_files[] = {
- "wall-straight-up.svg",
- "wall-straight-side.svg",
- "wall-corner-bottom-left.svg",
- "wall-corner-bottom-right.svg",
- "wall-corner-top-left.svg",
- "wall-corner-top-right.svg",
- "wall-tee-up.svg",
- "wall-tee-right.svg",
- "wall-tee-left.svg",
- "wall-tee-down.svg",
- "wall-cross.svg"
- };
-
- gchar *worm_files[] = {
- "snake-red.svg",
- "snake-green.svg",
- "snake-blue.svg",
- "snake-yellow.svg",
- "snake-cyan.svg",
- "snake-magenta.svg",
- "snake-grey.svg"
- };
-
- int i;
-
- for (i = 0; i < 9; i++) {
- if (boni_pixmaps[i])
- g_object_unref (boni_pixmaps[i]);
-
- boni_pixmaps[i] = load_pixmap_file (bonus_files[i],
- 4 * tilesize,
- 4 * tilesize);
- }
-
- for (i = 0; i < 11; i++) {
- if (wall_pixmaps[i])
- g_object_unref (wall_pixmaps[i]);
-
- wall_pixmaps[i] = load_pixmap_file (small_files[i],
- 2 * tilesize,
- 2 * tilesize);
- }
-
- for (i = 0; i < 7; i++) {
- if (worm_pixmaps[i])
- g_object_unref (worm_pixmaps[i]);
-
- worm_pixmaps[i] = load_pixmap_file (worm_files[i], tilesize,tilesize);
- }
-}
-
static void
hide_cursor (void)
{
@@ -448,8 +345,8 @@ configure_event_cb (GtkWidget * widget, GdkEventConfigure * event, gpointer data
int i;
if (data) {
- GnibblesBoard *board = (GnibblesBoard *)data;
- gnibbles_board_resize (board, tilesize);
+ GnibblesBoard *clutter_board = (GnibblesBoard *)data;
+ gnibbles_board_resize (clutter_board, tilesize);
for (i=0; i<properties->numworms; i++)
gnibbles_cworm_resize (cworms[i], tilesize);
}
@@ -982,7 +879,7 @@ create_menus (GtkUIManager * ui_manager)
}
static void
-setup_window_clutter (GnibblesBoard *board)
+setup_window_clutter (GnibblesBoard *clutter_board)
{
GtkWidget *vbox;
GtkWidget *main_vbox;
@@ -1025,14 +922,14 @@ setup_window_clutter (GnibblesBoard *board)
gtk_widget_show (packing);
- gtk_container_add (GTK_CONTAINER (packing), board->clutter_widget);
+ gtk_container_add (GTK_CONTAINER (packing), clutter_board->clutter_widget);
#ifdef GGZ_CLIENT
chat = create_chat_widget ();
gtk_box_pack_start (GTK_BOX (vbox), chat, FALSE, TRUE, 0);
#endif
- g_signal_connect (G_OBJECT (board->clutter_widget), "configure_event",
- G_CALLBACK (configure_event_cb), board);
+ g_signal_connect (G_OBJECT (clutter_board->clutter_widget), "configure_event",
+ G_CALLBACK (configure_event_cb), clutter_board);
g_signal_connect (G_OBJECT (window), "focus_out_event",
G_CALLBACK (show_cursor_cb), NULL);
@@ -1162,7 +1059,7 @@ setup_window (void)
}
static void
-render_logo_clutter (GnibblesBoard *board)
+render_logo_clutter (GnibblesBoard *clutter_board)
{
guint width, height;
@@ -1171,7 +1068,7 @@ render_logo_clutter (GnibblesBoard *board)
ClutterActor *desc;
ClutterColor actor_color = {0xff,0xff,0xff,0xff};
- ClutterActor *stage = gnibbles_board_get_stage (board);
+ ClutterActor *stage = gnibbles_board_get_stage (clutter_board);
clutter_actor_get_size (CLUTTER_ACTOR (stage), &width, &height);
@@ -1303,7 +1200,10 @@ move_worm_cb (ClutterTimeline *timeline, gint msecs, gpointer data)
gnibbles_cworm_move_straight_worm (cworms[i]);
} else if (nbr_actor >= 2) {
gnibbles_cworm_move_tail (cworms[i]);
- gnibbles_cworm_move_head (cworms[i]);
+ if (g_list_length (cworms[i]->list) == 1)
+ gnibbles_cworm_move_straight_worm (cworms[i]);
+ else
+ gnibbles_cworm_move_head (cworms[i]);
} else if (nbr_actor < 1) {
//worm's dead
return;
@@ -1383,17 +1283,17 @@ main (int argc, char **argv)
// clutter fun
gtk_clutter_init (&argc, &argv);
- load_pixmap (properties->tilesize);
- GnibblesBoard *board = gnibbles_board_new (BOARDWIDTH, BOARDHEIGHT);
- setup_window_clutter (board);
+ gnibbles_clutter_load_pixmap (properties->tilesize);
+ clutter_board = gnibbles_board_new (BOARDWIDTH, BOARDHEIGHT);
+ setup_window_clutter (clutter_board);
- ClutterActor *stage = gnibbles_board_get_stage (board);
+ ClutterActor *stage = gnibbles_board_get_stage (clutter_board);
int i;
level = gnibbles_level_new (5);
- gnibbles_board_load_level (board, level);
+ gnibbles_board_load_level (clutter_board, level);
for (i = 0; i < properties->numworms; i++) {
clutter_container_add_actor (CLUTTER_CONTAINER (stage), cworms[i]->actors);
@@ -1406,7 +1306,7 @@ main (int argc, char **argv)
g_signal_connect (timeline, "new-frame", G_CALLBACK (move_worm_cb), NULL);
clutter_timeline_start (timeline);
- //render_logo_clutter (board);
+ //render_logo_clutter (clutter_board);
gtk_main ();
diff --git a/gnibbles/warp.c b/gnibbles/warp.c
index cff6e63..58084c6 100644
--- a/gnibbles/warp.c
+++ b/gnibbles/warp.c
@@ -26,9 +26,12 @@
#include "gnibbles.h"
#include "warp.h"
#include "properties.h"
+#include "board.h"
extern GnibblesProperties *properties;
extern GdkPixbuf *boni_pixmaps[];
+extern GnibblesBoard *clutter_board;
+
GnibblesWarp *
gnibbles_warp_new (gint t_x, gint t_y, gint t_wx, gint t_wy)
{
@@ -53,6 +56,7 @@ gnibbles_warp_draw_buffer (GnibblesWarp * warp)
clutter_actor_set_position (CLUTTER_ACTOR (warp->actor),
properties->tilesize * warp->x,
properties->tilesize * warp->y);
-
+ ClutterActor *stage = gnibbles_board_get_stage (clutter_board);
+ clutter_container_add_actor (CLUTTER_CONTAINER (stage), warp->actor);
gnibbles_draw_big_pixmap_buffer (WARP, warp->x, warp->y);
}
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index ff117cd..f69cf3e 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -171,7 +171,7 @@ gnibbles_cworm_add_actor (GnibblesCWorm *worm)
worm->yhead -= size;
} else {
- clutter_actor_set_size (CLUTTER_ACTOR (actor), properties->tilesize, 0);
+ clutter_actor_set_size (CLUTTER_ACTOR (actor), properties->tilesize, 0);
}
g_object_set_property (G_OBJECT (actor), "repeat-y", &val);
@@ -181,7 +181,6 @@ gnibbles_cworm_add_actor (GnibblesCWorm *worm)
worm->xhead * properties->tilesize,
worm->yhead * properties->tilesize);
-
clutter_container_add_actor (CLUTTER_CONTAINER (worm->actors), actor);
worm->list = g_list_prepend (worm->list, actor);
}
@@ -231,7 +230,7 @@ gnibbles_cworm_resize (GnibblesCWorm *worm, gint newtile)
ClutterActor *tmp;
count = clutter_group_get_n_children (CLUTTER_GROUP (worm->actors));
- load_pixmap (newtile);
+ gnibbles_clutter_load_pixmap (newtile);
g_value_init (&val, G_TYPE_BOOLEAN);
@@ -380,8 +379,8 @@ gnibbles_cworm_move_head (GnibblesCWorm *worm)
clutter_actor_get_size (CLUTTER_ACTOR (head), &w, &h);
clutter_actor_get_position (CLUTTER_ACTOR (head), &x, &y);
- size = w < h ? h : w;
- size = size + properties->tilesize;
+ size = w < h ? floorf (h) : floorf (w);
+ size = floorf (size + properties->tilesize);
// set the size of the head actor
switch (worm->direction) {
@@ -437,8 +436,8 @@ gnibbles_cworm_move_tail (GnibblesCWorm *worm)
clutter_actor_get_size (CLUTTER_ACTOR (tail), &w, &h);
clutter_actor_get_position (CLUTTER_ACTOR (tail), &x, &y);
- size = w < h ? h : w;
- size = size - properties->tilesize;
+ size = w < h ? floorf (h) : floorf (w);
+ size = floorf (size - properties->tilesize);
if (size <= 0) {
gnibbles_cworm_remove_actor (worm);
@@ -500,7 +499,6 @@ gnibbles_cworm_get_length (GnibblesCWorm *worm)
tmp_size = w > h ? roundf(w) : roundf(h);
size += roundf (tmp_size / properties->tilesize);
}
-
return size;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]