[gnome-games/gnibbles-clutter] Initial commit including the work I did over the past 2 weeks
- From: Guillaume Béland <guillaubel src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/gnibbles-clutter] Initial commit including the work I did over the past 2 weeks
- Date: Wed, 20 May 2009 21:44:59 -0400 (EDT)
commit 05095a21f4ad1b8ab399b82cd5159bfb0419d463
Author: Guillaume Beland <guillaubel svn gnome org>
Date: Wed May 20 21:33:54 2009 -0400
Initial commit including the work I did over the past 2 weeks
Mostly, the board and level are now clutter-based and I began a primeraly work
on worm. For a more detailled evolution of this work, see the now obselete
github repository at this adress :
http://github.com/guillaumebel/nibbles-clutter/tree/master
---
gnibbles/board.c | 302 +++++++++++++++++++++++++++++++++++++
gnibbles/board.h | 43 ++++++
gnibbles/level.c | 126 +++++++++++++++
gnibbles/level.h | 42 +++++
gnibbles/pix/wall-small-empty.svg | 159 +++++++++++++++++++
gnibbles/worm-clutter.c | 122 +++++++++++++++
gnibbles/worm-clutter.h | 80 ++++++++++
7 files changed, 874 insertions(+), 0 deletions(-)
diff --git a/gnibbles/board.c b/gnibbles/board.c
new file mode 100644
index 0000000..e676a6d
--- /dev/null
+++ b/gnibbles/board.c
@@ -0,0 +1,302 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/*
+ * Gnome Nibbles: Gnome Worm Game
+ * Written by Sean MacIsaac <sjm acm org>, Ian Peters <itp gnu org>,
+ * Guillaume Beland <guillaume beland gmail com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <config.h>
+
+#include <stdlib.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+#include <glib/gi18n.h>
+#include <gdk/gdk.h>
+#include <libgames-support/games-runtime.h>
+
+#include <clutter-gtk/clutter-gtk.h>
+
+#include "main.h"
+#include "gnibbles.h"
+#include "properties.h"
+#include "board.h"
+
+static GdkPixbuf* load_pixmap_file (const gchar * pixmap,
+ gint xsize, gint ysize);
+static void load_pixmap ();
+
+GdkPixbuf *wall_pixmaps[19] = { NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL
+};
+
+extern GnibblesProperties *properties;
+
+
+GnibblesBoard *
+gnibbles_board_new (gint t_w, gint t_h)
+{
+ ClutterColor stage_color = {0x00,0x00,0x00,0xff};
+
+ GnibblesBoard *board = g_new (GnibblesBoard, 1);
+ board->width = t_w;
+ board->height = t_h;
+ board->level = NULL;
+ board->surface =NULL;
+ board->clutter_widget = gtk_clutter_embed_new ();
+
+ ClutterActor *stage;
+
+ load_pixmap ();
+
+ stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (board->clutter_widget));
+ clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
+
+ clutter_stage_set_user_resizable (CLUTTER_STAGE(stage), FALSE);
+ clutter_actor_set_size (CLUTTER_ACTOR (stage),
+ properties->tilesize * BOARDWIDTH,
+ properties->tilesize * BOARDHEIGHT);
+ clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), FALSE);
+ clutter_actor_show (stage);
+
+ gchar *filename;
+ const char *dirname;
+
+ dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
+ filename = g_build_filename (dirname, "wall-small-empty.svg", NULL);
+
+ /* Using ClutterScript to set special texture property such as "repeat-x",
+ * "repeat-y" and "keep-aspect-ratio" */
+ gchar texture_script[200];
+
+ g_sprintf (texture_script, "["
+ " {"
+ " \"id\" : \"surface\","
+ " \"type\" : \"ClutterTexture\","
+ " \"filename\" : \"%s\","
+ " \"x\" : 0,"
+ " \"y\" : 0,"
+ " \"width\" : %d,"
+ " \"height\" : %d,"
+ " \"keep-aspect-ratio\" : true"
+ " \"visible\" : true,"
+ " \"repeat-x\" : true,"
+ " \"repeat-y\" : true"
+ " }"
+ "]",
+ filename,
+ properties->tilesize,
+ properties->tilesize);
+
+ ClutterScript *script = clutter_script_new ();
+
+ clutter_script_load_from_data (script, texture_script, -1, NULL);
+ clutter_script_get_objects (script, "surface", &(board->surface), NULL);
+
+ clutter_actor_set_size (CLUTTER_ACTOR (board->surface),
+ properties->tilesize * BOARDWIDTH,
+ properties->tilesize * BOARDHEIGHT);
+ clutter_container_add_actor (CLUTTER_CONTAINER (stage), board->surface);
+ clutter_actor_show (board->surface);
+
+ g_object_unref (script);
+ return board;
+}
+
+ClutterActor *
+gnibbles_board_get_stage (GnibblesBoard *board)
+{
+ return gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(board->clutter_widget));
+}
+
+void
+gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level)
+{
+ gint i,j;
+ gint x_pos, y_pos;
+ ClutterActor *tmp;
+ gboolean wall = TRUE;
+
+ if (board->level)
+ g_object_unref (board->level);
+
+ board->level = clutter_group_new ();
+
+ /* Load walls onto the surface*/
+ for (i = 0; i < BOARDHEIGHT; i++) {
+ y_pos = i * properties->tilesize;
+ for (j = 0; j < BOARDWIDTH; j++) {
+ wall = TRUE;
+ switch (level->walls[j][i]) {
+ case 'a': // empty space
+ wall = FALSE;
+ break; // break right away
+ case 'b': // straight up
+ tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[1]);
+ break;
+ case 'c': // straight side
+ tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[2]);
+ break;
+ case 'd': // corner bottom left
+ tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[3]);
+ break;
+ case 'e': // corner bottom right
+ tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[4]);
+ break;
+ case 'f': // corner up left
+ tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[5]);
+ break;
+ case 'g': // corner up right
+ tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[6]);
+ break;
+ case 'h': // tee up
+ tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[7]);
+ break;
+ case 'i': // tee right
+ tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[8]);
+ break;
+ case 'j': // tee left
+ tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[9]);
+ break;
+ case 'k': // tee down
+ tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[10]);
+ break;
+ case 'l': // cross
+ tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[11]);
+ break;
+ default:
+ wall = FALSE;
+ break;
+ }
+
+ if (wall == TRUE) {
+ x_pos = j * properties->tilesize;
+
+ clutter_actor_set_size (CLUTTER_ACTOR(tmp),
+ properties->tilesize,
+ properties->tilesize);
+
+ clutter_actor_set_position (CLUTTER_ACTOR (tmp), x_pos, y_pos);
+ clutter_actor_show (CLUTTER_ACTOR (tmp));
+ clutter_container_add_actor (CLUTTER_CONTAINER (board->level), tmp);
+ }
+ }
+ }
+
+ ClutterActor *stage = gnibbles_board_get_stage (board);
+ clutter_container_add_actor (CLUTTER_CONTAINER (stage), board->level);
+ //raise the level above the surface
+ clutter_actor_raise (board->level,board->surface);
+}
+
+void
+gnibbles_board_resize (GnibblesBoard *board, gint newtile)
+{
+ int i;
+ int x_pos;
+ int y_pos;
+ int count;
+
+ ClutterActor *tmp;
+ ClutterActor *stage = gnibbles_board_get_stage (board);
+
+ clutter_actor_set_size (stage,
+ BOARDWIDTH * newtile,
+ BOARDHEIGHT * newtile);
+ clutter_actor_set_size (board->surface,
+ BOARDWIDTH * newtile,
+ BOARDHEIGHT * newtile);
+
+ if (!board->level)
+ return;
+
+ count = clutter_group_get_n_children (CLUTTER_GROUP (board->level));
+
+ for (i = 0; i < count; i++) {
+ tmp = clutter_group_get_nth_child (CLUTTER_GROUP (board->level), 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);
+ clutter_actor_set_size (tmp ,newtile, newtile);
+ }
+}
+
+static void
+load_pixmap ()
+{
+
+ gchar *small_files[] = {
+ "wall-empty.svg",
+ "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",
+ "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 < 19; i++) {
+ if (wall_pixmaps[i])
+ g_object_unref (wall_pixmaps[i]);
+
+ wall_pixmaps[i] = load_pixmap_file (small_files[i],
+ 4 * properties->tilesize,
+ 4 * properties->tilesize);
+ }
+}
+
+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_size (filename, xsize, ysize, NULL);
+ g_free (filename);
+
+ return image;
+}
+
+
diff --git a/gnibbles/board.h b/gnibbles/board.h
new file mode 100644
index 0000000..6851b91
--- /dev/null
+++ b/gnibbles/board.h
@@ -0,0 +1,43 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/*
+ * Gnome Nibbles: Gnome Worm Game
+ * Written by Sean MacIsaac <sjm acm org>, Ian Peters <itp gnu org>
+ * Guillaume Beland <guillaume beland gmail com>
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#include <gtk/gtk.h>
+#include <clutter/clutter.h>
+
+#include "level.h"
+
+typedef struct {
+ gint width;
+ gint height;
+ GtkWidget *clutter_widget;
+ ClutterActor *surface;
+ ClutterActor *level;
+} GnibblesBoard;
+
+GnibblesBoard* gnibbles_board_new (gint t_w, gint t_h);
+ClutterActor* gnibbles_board_get_stage (GnibblesBoard *board);
+void gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level);
+void gnibbles_board_resize (GnibblesBoard *board, gint newtile);
+
+#endif
diff --git a/gnibbles/level.c b/gnibbles/level.c
new file mode 100644
index 0000000..01bdfee
--- /dev/null
+++ b/gnibbles/level.c
@@ -0,0 +1,126 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/*
+ * Gnome Nibbles: Gnome Worm Game
+ * Written by Sean MacIsaac <sjm acm org>, Ian Peters <itp gnu org>
+ Guillaume Beland <guillaume beland gmail com>
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdlib.h>
+#include <glib/gi18n.h>
+#include "level.h"
+
+
+GnibblesLevel *
+gnibbles_level_new (gint level)
+{
+ GnibblesLevel *lvl = g_new (GnibblesLevel, 1);
+ lvl->level = level;
+ gchar *tmp = NULL;
+ const char *dirname;
+ gchar *filename;
+ FILE *in;
+ gchar tmpboard [BOARDWIDTH +2];
+ gint i,j;
+
+ tmp = g_strdup_printf("level%03d.gnl", level);
+
+ dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_GAMES_DIRECTORY);
+ filename = g_build_filename (dirname, tmp, NULL);
+
+ g_free (tmp);
+
+ if ((in = fopen (filename, "r")) == NULL) {
+ char *message =
+ g_strdup_printf (_
+ ("Nibbles couldn't load level file:\n%s\n\n"
+ "Please check your Nibbles installation"), filename);
+ //gnibbles_error (window, message);
+ g_free (message);
+ }
+
+ for (i = 0; i < BOARDHEIGHT; i++) {
+ if (!fgets (tmpboard, sizeof (tmpboard), in)) {
+ char *message =
+ g_strdup_printf (_
+ ("Level file appears to be damaged:\n%s\n\n"
+ "Please check your Nibbles installation"), filename);
+ //gnibbles_error (window, message);
+ g_free (message);
+ break;
+ }
+
+ for (j = 0; j < BOARDWIDTH; j++) {
+ lvl->walls[j][i] = tmpboard[j];
+ switch (lvl->walls[j][i]) {
+ case 'm':
+ lvl->walls[j][i] = EMPTYCHAR;
+ //if (count < properties->numworms)
+ // gnibbles_worm_set_start (worms[count++], j, i, WORMUP);
+ break;
+ case 'n':
+ lvl->walls[j][i] = EMPTYCHAR;
+ //if (count < properties->numworms)
+ // gnibbles_worm_set_start (worms[count++], j, i, WORMLEFT);
+ break;
+ case 'o':
+ lvl->walls[j][i] = EMPTYCHAR;
+ //if (count < properties->numworms)
+ // gnibbles_worm_set_start (worms[count++], j, i, WORMDOWN);
+ break;
+ case 'p':
+ lvl->walls[j][i] = EMPTYCHAR;
+ //if (count < properties->numworms)
+ // gnibbles_worm_set_start (worms[count++], j, i, WORMRIGHT);
+ break;
+ case 'Q':
+ //gnibbles_warpmanager_add_warp (warpmanager, j - 1, i - 1, -1, -1);
+ break;
+ case 'R':
+ case 'S':
+ case 'T':
+ case 'U':
+ case 'V':
+ case 'W':
+ case 'X':
+ case 'Y':
+ case 'Z':
+ //gnibbles_warpmanager_add_warp
+ // (warpmanager, j - 1, i - 1, -board[j][i], 0);
+ break;
+ case 'r':
+ case 's':
+ case 't':
+ case 'u':
+ case 'v':
+ case 'w':
+ case 'x':
+ case 'y':
+ case 'z':
+ //gnibbles_warpmanager_add_warp
+ // (warpmanager, -(board[j][i] - 'a' + 'A'), 0, j, i);
+ lvl->walls[j][i] = EMPTYCHAR;
+ break;
+ }
+ }
+ }
+
+ g_free (filename);
+ fclose (in);
+
+ return lvl;
+}
+
diff --git a/gnibbles/level.h b/gnibbles/level.h
new file mode 100644
index 0000000..53245eb
--- /dev/null
+++ b/gnibbles/level.h
@@ -0,0 +1,42 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/*
+ * Gnome Nibbles: Gnome Worm Game
+ * Written by Sean MacIsaac <sjm acm org>, Ian Peters <itp gnu org>
+ * Guillaume Beland <guillaume beland gmail com>
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef LEVEL_H_
+#define LEVEL_H_
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+#include <libgames-support/games-runtime.h>
+
+#define BOARDWIDTH 92
+#define BOARDHEIGHT 66
+
+#define EMPTYCHAR 'a'
+#define WORMCHAR 'w'
+
+typedef struct {
+ gchar walls[BOARDWIDTH][BOARDHEIGHT];
+ gint level;
+} GnibblesLevel;
+
+GnibblesLevel *gnibbles_level_new (gint level);
+#endif
diff --git a/gnibbles/pix/wall-small-empty.svg b/gnibbles/pix/wall-small-empty.svg
new file mode 100644
index 0000000..3ac3c78
--- /dev/null
+++ b/gnibbles/pix/wall-small-empty.svg
@@ -0,0 +1,159 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<!-- (C) Copyright 2004 Theo van Klaveren -->
+
+<!--
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THEO VAN KLAVEREN ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THEO VAN KLAVEREN OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ id="svg1"
+ sodipodi:version="0.32"
+ inkscape:version="0.46+devel"
+ width="10"
+ height="10"
+ sodipodi:docname="wall-empty.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape"
+ version="1.0">
+ <metadata
+ id="metadata6">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <defs
+ id="defs3">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 88.58268 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="177.16536 : 88.58268 : 1"
+ inkscape:persp3d-origin="88.58268 : 59.05512 : 1"
+ id="perspective19" />
+ <linearGradient
+ id="linearGradient2057">
+ <stop
+ style="stop-color:#506040;stop-opacity:1.0000000;"
+ offset="0.0000000"
+ id="stop2059" />
+ <stop
+ style="stop-color:#405030;stop-opacity:1.0000000;"
+ offset="0.25000000"
+ id="stop2067" />
+ <stop
+ style="stop-color:#304020;stop-opacity:1.0000000;"
+ offset="0.37500000"
+ id="stop2077" />
+ <stop
+ style="stop-color:#405030;stop-opacity:1.0000000;"
+ offset="0.50000000"
+ id="stop2069" />
+ <stop
+ style="stop-color:#506040;stop-opacity:1.0000000;"
+ offset="0.62500000"
+ id="stop2075" />
+ <stop
+ style="stop-color:#405030;stop-opacity:1.0000000;"
+ offset="0.75000000"
+ id="stop2071" />
+ <stop
+ style="stop-color:#304020;stop-opacity:1.0000000;"
+ offset="1.0000000"
+ id="stop2061" />
+ </linearGradient>
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="16"
+ inkscape:cx="-11.83197"
+ inkscape:cy="3.2425041"
+ inkscape:window-width="1022"
+ inkscape:window-height="694"
+ showgrid="true"
+ snaptogrid="true"
+ inkscape:window-x="0"
+ inkscape:window-y="21"
+ inkscape:current-layer="svg1" />
+ <g
+ id="g21"
+ transform="matrix(0.05644776,0,0,0.05644776,0.00273405,-0.00129949)">
+ <rect
+ y="-2.8421709e-14"
+ x="0"
+ height="177.16536"
+ width="177.092"
+ id="rect841"
+ style="fill:#405030;fill-opacity:1;fill-rule:evenodd;stroke:none" />
+ <rect
+ transform="matrix(0.707107,0.707107,-0.707107,0.707107,0,0)"
+ y="-128.38464"
+ x="93.097198"
+ height="256.82111"
+ width="27.500008"
+ id="rect2843"
+ style="fill:#304020;fill-opacity:0.62745098" />
+ <rect
+ transform="matrix(0.707107,0.707107,-0.707107,0.707107,0,0)"
+ y="-128.38464"
+ x="129.90062"
+ height="256.82111"
+ width="27.500008"
+ id="rect2845"
+ style="fill:#506040;fill-opacity:0.81568627" />
+ <rect
+ transform="matrix(0.707107,0.707107,-0.707107,0.707107,0,0)"
+ y="-114.24298"
+ x="218.13184"
+ height="256.8223"
+ width="27.500107"
+ id="rect3611"
+ style="fill:#304020;fill-opacity:0.62745098" />
+ <rect
+ transform="matrix(0.707107,0.707107,-0.707107,0.707107,0,0)"
+ y="-114.24306"
+ x="4.8668756"
+ height="256.8223"
+ width="27.500107"
+ id="rect3613"
+ style="fill:#506040;fill-opacity:0.81568627" />
+ </g>
+</svg>
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
new file mode 100644
index 0000000..3328f04
--- /dev/null
+++ b/gnibbles/worm-clutter.c
@@ -0,0 +1,122 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/*
+ * Gnome Nibbles: Gnome Worm Game
+ * Written by Sean MacIsaac <sjm acm org>, Ian Peters <itp gnu org>
+ * Guillaume Béland <guillaume beland gmail com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "properties.h"
+#include "worm-clutter.h"
+
+extern GnibblesProperties *properties;
+
+
+GnibblesCWorm*
+gnibbles_cworm_new (guint number, gint x_s, gint y_s)
+{
+ GnibblesCWorm *worm = g_new (GnibblesCWorm, 1);
+
+ worm->actors = clutter_group_new ();
+ worm->list = NULL;
+ worm->number = number;
+ worm->lives = SLIVES;
+ worm->direction = 1;
+ worm->inverse = FALSE;
+ worm->xstart = x_s;
+ worm->ystart = y_s;
+
+ ClutterActor *actor = clutter_rectangle_new ();
+
+ if (worm->direction == WORMRIGHT || worm->direction == WORMLEFT) {
+ clutter_actor_set_size (CLUTTER_ACTOR (actor),
+ SLENGTH * properties->tilesize,
+ properties->tilesize);
+
+ } else if (worm->direction == WORMDOWN || worm->direction == WORMUP) {
+ clutter_actor_set_size (CLUTTER_ACTOR (actor),
+ properties->tilesize,
+ SLENGTH * properties->tilesize);
+ }
+
+ clutter_actor_set_position (CLUTTER_ACTOR (actor), worm->xstart, worm->ystart);
+ clutter_container_add_actor (CLUTTER_CONTAINER (worm->actors), actor);
+
+ worm->list = g_list_append (worm->list, actor);
+ return worm;
+}
+
+void
+gnibbles_cworm_add_straight_actor (GnibblesCWorm *worm)
+{
+ ClutterActor *straight = clutter_rectangle_new ();
+
+ if (worm->direction == WORMRIGHT || worm->direction == WORMLEFT)
+ clutter_actor_set_size (straight, properties->tilesize ,0);
+ else if (worm->direction == WORMDOWN || worm->direction == WORMUP)
+ clutter_actor_set_size (straight, 0, properties->tilesize);
+
+ if (!worm->inverse)
+ worm->list = g_list_append (worm->list, straight);
+ else
+ worm->list = g_list_prepend (worm->list, straight);
+
+ clutter_container_add_actor (CLUTTER_CONTAINER (worm->actors), straight);
+
+ //TODO: start increasing the size of the actor
+}
+
+void
+gnibbles_cworm_add_corner_actor (GnibblesCWorm *worm)
+{
+ //TODO: rounded corner
+ ClutterActor *corner = clutter_rectangle_new ();
+
+ //TODO: switch to determine how the corner is rounded
+ switch (worm->direction)
+ {
+ case WORMRIGHT:
+ break;
+ case WORMLEFT:
+ break;
+ case WORMDOWN:
+ break;
+ case WORMUP:
+ break;
+ default:
+ clutter_actor_set_size (corner, properties->tilesize, properties->tilesize);
+ break;
+ }
+
+ if (!worm->inverse)
+ worm->list = g_list_append (worm->list, corner);
+ else
+ worm->list = g_list_prepend (worm->list, corner);
+
+ clutter_container_add_actor (CLUTTER_CONTAINER (worm->actors), corner);
+}
+
+void
+gnibbles_cworm_remove_actor (GnibblesCWorm *worm)
+{
+ if (!worm->inverse)
+ worm->list = g_list_remove_link (worm->list, g_list_first (worm->list));
+ else
+ worm->list = g_list_remove_link (worm->list, g_list_last (worm->list));
+}
+
+
diff --git a/gnibbles/worm-clutter.h b/gnibbles/worm-clutter.h
new file mode 100644
index 0000000..3d63121
--- /dev/null
+++ b/gnibbles/worm-clutter.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/*
+ * Gnome Nibbles: Gnome Worm Game
+ * Written by Sean MacIsaac <sjm acm org>, Ian Peters <itp gnu org>
+ * Guillaume Béland <guillaume beland gmail com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef WORM_CLUTTER_H_
+#define WORM_CLUTTER_H_
+
+#include <gtk/gtk.h>
+#include <clutter/clutter.h>
+
+#define WORMNONE 0
+#define WORMRIGHT 1
+#define WORMDOWN 2
+#define WORMLEFT 3
+#define WORMUP 4
+#define SLENGTH 5
+#define SLIVES 10
+#define ERASESIZE 6
+#define ERASETIME 500
+
+#define GROWFACTOR 4
+
+typedef struct {
+ ClutterActor *actors;
+ GList *list;
+ gint xstart, ystart;
+ gint direction;
+ gint direction_start;
+ gint length;
+ gint lives;
+ guint score;
+ guint number;
+ gboolean inverse;
+} GnibblesCWorm;
+
+typedef struct {
+ ClutterActor *actor;
+ gint direction;
+} WormStraight;
+
+typedef struct {
+ ClutterActor *actor;
+ gint direction;
+} WormCorner;
+
+GnibblesCWorm * gnibbles_cworm_new (guint number, gint x_s, gint y_s);
+void gnibbles_cworm_add_straight_actor (GnibblesCWorm *worm);
+void gnibbles_cworm_add_corner_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_handle_keypress (GnibblesCWorm * worm, guint keyval);
+void gnibbles_cworm_position_move_head (GnibblesCWorm * worm, gint *x, gint *y);
+gint gnibbles_cworm_test_move_head (GnibblesCWorm * worm);
+gint gnibbles_cworm_can_move_to (GnibblesCWorm * worm, gint x, gint y);
+gint gnibbles_cworm_is_move_safe (GnibblesCWorm * worm);
+gint gnibbles_cworm_lose_life (GnibblesCWorm * worm);
+void gnibbles_cworm_reset (GnibblesCWorm * worm);
+void gnibbles_cworm_ai_move (GnibblesCWorm * worm);
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]