3
* Copyright (C) 2001 Bruno Coudoin
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#include "gcompris/gcompris.h"
26
#define SOUNDLISTFILE PACKAGE
28
GcomprisBoard *gcomprisBoard = NULL;
29
gboolean board_paused = TRUE;
31
static void start_board (GcomprisBoard *agcomprisBoard);
32
static void pause_board (gboolean pause);
33
static void end_board (void);
34
static gboolean is_our_board (GcomprisBoard *gcomprisBoard);
35
static void set_level (guint level);
37
static void game_won(void);
39
#define VERTICAL_SEPARATION 30
40
#define HORIZONTAL_SEPARATION 30
41
#define TEXT_COLOR "white"
43
static GnomeCanvasGroup *boardRootItem = NULL;
45
static GnomeCanvasItem *erase_create_item(GnomeCanvasGroup *parent);
46
static void erase_destroy_all_items(void);
47
static void erase_next_level(void);
48
static gint item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data);
50
static int number_of_item = 0;
51
static int number_of_item_x = 0;
52
static int number_of_item_y = 0;
54
// List of images to use in the game
55
static gchar *imageList[] =
57
"gcompris/animals/bear001.jpg",
58
"gcompris/animals/malaybear002.jpg",
59
"gcompris/animals/polabear011.jpg",
60
"gcompris/animals/spectbear001.jpg",
61
"gcompris/animals/joybear001.jpg",
62
"gcompris/animals/polarbear001.jpg",
63
"gcompris/animals/joybear002.jpg",
64
"gcompris/animals/poolbears001.jpg"
66
#define NUMBER_OF_IMAGES 8
68
/* Description of this plugin */
74
N_("Move the mouse to erase the area and discover the background"),
75
"Bruno Coudoin <bruno.coudoin@free.fr>",
92
* Main entry point mandatory for each Gcompris's game
93
* ---------------------------------------------------
98
*get_bplugin_info(void)
104
* in : boolean TRUE = PAUSE : FALSE = CONTINUE
107
static void pause_board (gboolean pause)
109
if(gcomprisBoard==NULL)
112
if(gamewon == TRUE && pause == FALSE) /* the game is won */
117
board_paused = pause;
122
static void start_board (GcomprisBoard *agcomprisBoard)
125
if(agcomprisBoard!=NULL)
127
gcomprisBoard=agcomprisBoard;
128
gcomprisBoard->level=1;
129
gcomprisBoard->maxlevel=2;
130
gcomprisBoard->sublevel=1;
131
gcomprisBoard->number_of_sublevel=1; /* Go to next level after this number of 'play' */
132
gcompris_bar_set(GCOMPRIS_BAR_LEVEL);
140
/* ======================================= */
141
static void end_board ()
143
if(gcomprisBoard!=NULL)
146
erase_destroy_all_items();
148
gcomprisBoard = NULL;
151
/* ======================================= */
152
static void set_level (guint level)
155
if(gcomprisBoard!=NULL)
157
gcomprisBoard->level=level;
158
gcomprisBoard->sublevel=1;
162
/* ======================================= */
163
gboolean is_our_board (GcomprisBoard *gcomprisBoard)
167
if(g_strcasecmp(gcomprisBoard->type, "erase")==0)
169
/* Set the plugin entry */
170
gcomprisBoard->plugin=&menu_bp;
178
/*-------------------------------------------------------------------------------*/
179
/*-------------------------------------------------------------------------------*/
180
/* set initial values for the next level */
181
static void erase_next_level()
184
gcompris_set_background(gnome_canvas_root(gcomprisBoard->canvas),
185
imageList[RAND(0, NUMBER_OF_IMAGES-1)]);
187
gcompris_bar_set_level(gcomprisBoard);
189
erase_destroy_all_items();
192
/* Select level difficulty */
193
number_of_item_x = gcomprisBoard->level*5;
194
number_of_item_y = gcomprisBoard->level*5;
196
/* Try the next level */
197
erase_create_item(gnome_canvas_root(gcomprisBoard->canvas));
199
/* ==================================== */
200
/* Destroy all the items */
201
static void erase_destroy_all_items()
203
if(boardRootItem!=NULL)
204
gtk_object_destroy (GTK_OBJECT(boardRootItem));
206
boardRootItem = NULL;
208
/* ==================================== */
209
static GnomeCanvasItem *erase_create_item(GnomeCanvasGroup *parent)
212
GnomeCanvasItem *item = NULL;
214
boardRootItem = GNOME_CANVAS_GROUP(
215
gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
216
gnome_canvas_group_get_type (),
224
for(i=0; i<BOARDWIDTH; i+=BOARDWIDTH/number_of_item_x)
226
for(j=0; j<BOARDHEIGHT; j+=BOARDHEIGHT/number_of_item_y)
229
item = gnome_canvas_item_new (boardRootItem,
230
gnome_canvas_rect_get_type (),
233
"x2", (double) i+BOARDWIDTH/number_of_item_x,
234
"y2", (double) j+BOARDHEIGHT/number_of_item_y,
235
"fill_color", "blue",
236
"outline_color", "green",
237
"width_units", (double)1,
240
gtk_signal_connect(GTK_OBJECT(item), "event", (GtkSignalFunc) item_event, NULL);
247
/* ==================================== */
248
static void game_won()
250
gcomprisBoard->sublevel++;
252
if(gcomprisBoard->sublevel>gcomprisBoard->number_of_sublevel) {
253
/* Try the next level */
254
gcomprisBoard->sublevel=1;
255
gcomprisBoard->level++;
256
if(gcomprisBoard->level>gcomprisBoard->maxlevel) { // the current board is finished : bail out
257
board_finished(BOARD_FINISHED_RANDOM);
260
gcompris_play_sound (SOUNDLISTFILE, "bonus");
265
/* ==================================== */
267
item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
269
double item_x, item_y;
270
item_x = event->button.x;
271
item_y = event->button.y;
272
gnome_canvas_item_w2i(item->parent, &item_x, &item_y);
277
gtk_object_destroy(GTK_OBJECT(item));
279
if(--number_of_item == 0)
282
erase_destroy_all_items();
283
gcompris_display_bonus(gamewon, BONUS_SMILEY);