[gnome-games/gnibbles-clutter-rebased: 10/129] Some work on resizing worm & creating/displaying them properly
- From: Jason Clinton <jclinton src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games/gnibbles-clutter-rebased: 10/129] Some work on resizing worm & creating/displaying them properly
- Date: Mon, 12 Oct 2009 21:27:04 +0000 (UTC)
commit 0259ec136ce6b5262b83c0eefbed4ad1b11b5387
Author: Guillaume Beland <guillaume beland gmail com>
Date: Thu May 28 21:56:53 2009 -0400
Some work on resizing worm & creating/displaying them properly
gnibbles/board.c | 8 +++--
gnibbles/level.c | 12 +++++--
gnibbles/main.c | 17 +++------
gnibbles/worm-clutter.c | 81 ++++++++++++++++++++++++++++++++++++-----------
gnibbles/worm-clutter.h | 7 ++--
5 files changed, 85 insertions(+), 40 deletions(-)
---
diff --git a/gnibbles/board.c b/gnibbles/board.c
index 1458bf9..4ccb73f 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -176,6 +176,11 @@ gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level)
void
gnibbles_board_resize (GnibblesBoard *board, gint newtile)
{
+ if (!board->level)
+ return;
+ if (!board->surface)
+ return;
+
int i;
int x_pos;
int y_pos;
@@ -191,9 +196,6 @@ gnibbles_board_resize (GnibblesBoard *board, gint newtile)
BOARDWIDTH * newtile,
BOARDHEIGHT * newtile);
- if (!board->level)
- return;
-
count = clutter_group_get_n_children (CLUTTER_GROUP (board->level));
for (i = 0; i < count; i++) {
diff --git a/gnibbles/level.c b/gnibbles/level.c
index f7b7cb2..8b64004 100644
--- a/gnibbles/level.c
+++ b/gnibbles/level.c
@@ -59,6 +59,10 @@ gnibbles_level_new (gint level)
g_free (message);
}
+ for (i = 0; i < properties->numworms; i++)
+ if (cworms[i])
+ gnibbles_cworm_destroy (cworms[i]);
+
for (i = 0; i < BOARDHEIGHT; i++) {
if (!fgets (tmpboard, sizeof (tmpboard), in)) {
char *message =
@@ -76,22 +80,22 @@ gnibbles_level_new (gint level)
case 'm':
lvl->walls[j][i] = EMPTYCHAR;
if (count < properties->numworms)
- gnibbles_cworm_set_start (cworms[count++], j, i, WORMUP);
+ cworms[count] = gnibbles_cworm_new (count++, j, i, WORMUP);
break;
case 'n':
lvl->walls[j][i] = EMPTYCHAR;
if (count < properties->numworms)
- gnibbles_cworm_set_start (cworms[count++], j, i, WORMLEFT);
+ cworms[count] = gnibbles_cworm_new (count++, j, i, WORMDOWN);
break;
case 'o':
lvl->walls[j][i] = EMPTYCHAR;
if (count < properties->numworms)
- gnibbles_cworm_set_start (cworms[count++], j, i, WORMDOWN);
+ cworms[count] = gnibbles_cworm_new (count++, j, i, WORMLEFT);
break;
case 'p':
lvl->walls[j][i] = EMPTYCHAR;
if (count < properties->numworms)
- gnibbles_cworm_set_start (cworms[count++], j, i, WORMRIGHT);
+ cworms[count] = gnibbles_cworm_new (count++, j, i, WORMRIGHT);
break;
case 'Q':
//gnibbles_warpmanager_add_warp (warpmanager, j - 1, i - 1, -1, -1);
diff --git a/gnibbles/main.c b/gnibbles/main.c
index 2aae522..d08f553 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -157,7 +157,7 @@ load_pixmap_file (const gchar * pixmap, gint xsize, gint ysize)
g_free(message);
}
- image = gdk_pixbuf_new_from_file_at_size (filename, xsize, ysize, NULL);
+ image = gdk_pixbuf_new_from_file_at_scale (filename, xsize, ysize, TRUE, NULL);
g_free (filename);
return image;
@@ -217,8 +217,8 @@ load_pixmap ()
g_object_unref (wall_pixmaps[i]);
wall_pixmaps[i] = load_pixmap_file (small_files[i],
- 4 * properties->tilesize,
- 4 * properties->tilesize);
+ 2 * properties->tilesize,
+ 2 * properties->tilesize);
}
for (i = 0; i < 7; i++) {
@@ -445,9 +445,12 @@ configure_event_cb (GtkWidget * widget, GdkEventConfigure * event, gpointer data
ts_y--;
tilesize = MIN (ts_x, ts_y);
+ int i;
if (data) {
GnibblesBoard *board = (GnibblesBoard *)data;
gnibbles_board_resize (board, tilesize);
+ for (i=0; i<properties->numworms; i++)
+ gnibbles_cworm_resize (cworms[i], tilesize);
}
/* But, has the tile size changed? */
@@ -1336,14 +1339,6 @@ main (int argc, char **argv)
int i;
- for (i = 0; i < properties->numworms; i++)
- if (cworms[i])
- gnibbles_cworm_destroy (cworms[i]);
-
- for (i = 0; i < properties->numworms; i++) {
- cworms[i] = gnibbles_cworm_new (i);
- }
-
gnibbles_board_load_level (board, gnibbles_level_new (1));
for (i = 0; i < properties->numworms; i++) {
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index dead4fd..06e2865 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -36,7 +36,8 @@ extern GnibblesProperties *properties;
extern GdkPixbuf *worm_pixmaps[];
GnibblesCWorm*
-gnibbles_cworm_new (guint number)
+gnibbles_cworm_new (guint number, guint t_xhead,
+ guint t_yhead, gint t_direction)
{
GnibblesCWorm *worm = g_new (GnibblesCWorm, 1);
@@ -47,7 +48,13 @@ gnibbles_cworm_new (guint number)
worm->direction = 1;
worm->inverse = FALSE;
- worm->direction = WORMDOWN;
+ worm->xhead = t_xhead;
+ worm->xstart = t_xhead;
+ worm->yhead = t_yhead;
+ worm->ystart = t_yhead;
+ worm->direction = t_direction;
+ worm->direction_start = t_direction;
+
gnibbles_cworm_add_straight_actor (worm);
return worm;
@@ -59,14 +66,16 @@ gnibbles_cworm_add_straight_actor (GnibblesCWorm *worm)
ClutterActor *actor = NULL;
GValue val = {0,};
gint size;
+
actor = gtk_clutter_texture_new_from_pixbuf (worm_pixmaps[worm->number]);
g_value_init (&val, G_TYPE_BOOLEAN);
- g_value_set_boolean ( &val, TRUE);
+ g_value_set_boolean (&val, TRUE);
clutter_actor_set_position (CLUTTER_ACTOR (actor),
- worm->xhead,
- worm->yhead);
+ worm->xhead * properties->tilesize,
+ worm->yhead * properties->tilesize);
+
g_object_set_property (G_OBJECT (actor), "keep-aspect-ratio", &val);
ClutterActor *tmp = NULL;
@@ -99,8 +108,8 @@ gnibbles_cworm_add_straight_actor (GnibblesCWorm *worm)
if (!tmp)
clutter_actor_set_size (CLUTTER_ACTOR (actor),
- properties->tilesize * size,
- properties->tilesize);
+ properties->tilesize * size,
+ properties->tilesize);
else
clutter_actor_set_size (CLUTTER_ACTOR (actor), 0, properties->tilesize);
@@ -163,18 +172,6 @@ gnibbles_cworm_remove_actor (GnibblesCWorm *worm)
clutter_container_remove_actor (CLUTTER_CONTAINER (worm->actors), tmp);
}
-void
-gnibbles_cworm_set_start (GnibblesCWorm * worm, guint t_xhead,
- guint t_yhead, gint t_direction)
-{
- worm->xhead = t_xhead;
- worm->xstart = t_xhead;
- worm->yhead = t_yhead;
- worm->ystart = t_yhead;
- worm->direction = t_direction;
- worm->direction_start = t_direction;
-}
-
gint
gnibbles_cworm_lose_life (GnibblesCWorm * worm)
{
@@ -184,3 +181,49 @@ gnibbles_cworm_lose_life (GnibblesCWorm * worm)
return 0;
}
+void
+gnibbles_cworm_resize (GnibblesCWorm *worm, gint newtile)
+{
+ if (!worm)
+ return;
+ if (!worm->actors)
+ return;
+
+ int i;
+ int x_pos;
+ int y_pos;
+ int count;
+ guint w,h;
+ guint size;
+ gboolean direction;
+ GValue val = {0,};
+ ClutterActor *tmp;
+
+ count = clutter_group_get_n_children (CLUTTER_GROUP (worm->actors));
+
+ for (i = 0; i < count; i++) {
+ tmp = clutter_group_get_nth_child (CLUTTER_GROUP (worm->actors), i);
+ clutter_actor_get_position (tmp, &x_pos, &y_pos);
+
+ clutter_actor_set_position (tmp,
+ (x_pos / properties->tilesize) * newtile,
+ (y_pos / properties->tilesize) * newtile);
+
+ g_value_init (&val, G_TYPE_BOOLEAN);
+ g_object_get_property (G_OBJECT (tmp), "repeat-x", &val);
+ direction = g_value_get_boolean (&val);
+
+ clutter_actor_get_size (CLUTTER_ACTOR (tmp), &w, &h);
+ size = w < h ? h : w;
+ size = size / newtile;
+
+ if (direction)
+ clutter_actor_set_size (tmp, newtile * size, newtile);
+ else
+ clutter_actor_set_size (tmp, newtile, newtile * size);
+
+ //TODO: Resize/Reload pixbuf
+ //gtk_clutter_texture_set_from_pixbuf (CLUTTER_TEXTURE (tmp), worm_pixmaps[worm->number]);
+ }
+
+}
diff --git a/gnibbles/worm-clutter.h b/gnibbles/worm-clutter.h
index 3e459c3..1cea665 100644
--- a/gnibbles/worm-clutter.h
+++ b/gnibbles/worm-clutter.h
@@ -62,13 +62,14 @@ typedef struct {
gint direction;
} WormCorner;
-GnibblesCWorm * gnibbles_cworm_new (guint number);
+GnibblesCWorm * gnibbles_cworm_new (guint number, guint t_xhead,
+ guint t_yhead, gint t_direction);
+
void gnibbles_cworm_add_straight_actor (GnibblesCWorm *worm);
void gnibbles_cworm_remove_actor (GnibblesCWorm *worm);
void gnibbles_cworm_destroy (GnibblesCWorm * worm);
-void gnibbles_cworm_set_start (GnibblesCWorm * worm, guint t_xhead,
- guint t_yhead, gint t_direction);
gint gnibbles_cworm_lose_life (GnibblesCWorm * worm);
+void gnibbles_cworm_resize (GnibblesCWorm *worm, gint newtile);
gint gnibbles_cworm_handle_keypress (GnibblesCWorm * worm, guint keyval);
gint gnibbles_cworm_can_move_to (GnibblesCWorm * worm, gint x, gint y);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]