Commit 07a30ddb authored by Bruno Coudoin's avatar Bruno Coudoin

relloked clockgame. shapegame can be edited

parent aedf6dd8
......@@ -65,7 +65,7 @@ static void destroy_board();
#define HORIZONTAL_SEPARATION 20
#define VERTICAL_SEPARATION 20
static const char* background_images[] = {"gcompris/animals/tiger1_by_Ralf_Schmode","gcompris/animals/tigerdrink001.jpg","gcompris/animals/tigercub003.jpg", "gcompris/animals/tigerplay001.jpg"};
static char* background_images[] = {"gcompris/animals/tiger1_by_Ralf_Schmode","gcompris/animals/tigerdrink001.jpg","gcompris/animals/tigercub003.jpg", "gcompris/animals/tigerplay001.jpg"};
static const char oper_values[] = {'+', '-', 'x', ':', '='};
static const int num_values[] = {1,2,3,4,5,6,7,8,9,10,25,50,100};
#define NUM_VALUES 13
......@@ -588,6 +588,7 @@ static gint item_event_oper(GnomeCanvasItem *item, GdkEvent *event, gpointer dat
token_count++;
gtk_signal_connect(GTK_OBJECT(tmp_item), "event", (GtkSignalFunc) item_event_oper_moved, GINT_TO_POINTER(token_count));
break;
default : break;
}
return FALSE;
}
......@@ -606,6 +607,7 @@ static gint item_event_oper_moved(GnomeCanvasItem *item, GdkEvent *event, gpoint
update_line_calcul();
}
break;
default : break;
}
return FALSE;
}
......
/* gcompris - clockgame.c
*
* Time-stamp: <2001/12/26 21:46:37 bruno>
* Time-stamp: <2002/01/05 22:20:18 bruno>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -132,12 +132,12 @@ static void start_board (GcomprisBoard *agcomprisBoard)
{
gcomprisBoard=agcomprisBoard;
gcompris_set_background(gnome_canvas_root(gcomprisBoard->canvas), "gcompris/gcompris-bg.jpg");
gcompris_set_background(gnome_canvas_root(gcomprisBoard->canvas), "clockgame/clockgame-bg.jpg");
/* set initial values for this level */
/* set initial values for this level adjusted to fit the watch background */
cx = gcomprisBoard->width/2;
cy = gcomprisBoard->height*0.4;
cy = gcomprisBoard->height*0.4 + 42;
clock_size = gcomprisBoard->height*0.3;
gcomprisBoard->level=1;
......@@ -316,7 +316,7 @@ static void display_minute(guint minute)
canvasPoints->coords[3]=cy - needle_size * cos(ang);
gnome_canvas_item_set (minute_item,
"points", canvasPoints,
"fill_color", "green",
"fill_color", "red",
"width_units", (double)1,
"width_pixels", (uint) 4,
"last_arrowhead", TRUE,
......@@ -348,7 +348,7 @@ static void display_second(guint second)
canvasPoints->coords[3]=cy - needle_size * cos(ang);
gnome_canvas_item_set (second_item,
"points", canvasPoints,
"fill_color", "red",
"fill_color_rgba", 0x68c46f00,
"width_units", (double)1,
"width_pixels", (uint) 4,
"last_arrowhead", TRUE,
......@@ -394,7 +394,7 @@ static GnomeCanvasItem *clockgame_create_item(GnomeCanvasGroup *parent)
canvasPoints->coords[0]=cx + (needle_size-hour_point_size) * sin(ang);
canvasPoints->coords[1]=cy - (needle_size-hour_point_size) * cos(ang);
color="darkblue";
color_text="green";
color_text="red";
font = gdk_font;
}
else
......@@ -402,8 +402,8 @@ static GnomeCanvasItem *clockgame_create_item(GnomeCanvasGroup *parent)
/* Minute point */
canvasPoints->coords[0]=cx + (needle_size-min_point_size) * sin(ang);
canvasPoints->coords[1]=cy - (needle_size-min_point_size) * cos(ang);
color="green";
color_text="lightgreen";
color="red";
color_text="red";
font = gdk_font_small;
}
......@@ -533,10 +533,10 @@ static GnomeCanvasItem *clockgame_create_item(GnomeCanvasGroup *parent)
gnome_canvas_text_get_type (),
"text", _("Set the clock to:"),
"font_gdk", gdk_font_big3,
"x", (double) cx,
"y", (double) cy + needle_size + needle_size / 3,
"x", (double) gcomprisBoard->width*0.15,
"y", (double) cy + needle_size + needle_size / 3 - 30,
"anchor", GTK_ANCHOR_CENTER,
"fill_color", "green",
"fill_color", "white",
NULL);
item_list = g_list_append (item_list, item);
......@@ -545,10 +545,10 @@ static GnomeCanvasItem *clockgame_create_item(GnomeCanvasGroup *parent)
gnome_canvas_text_get_type (),
"text", "",
"font_gdk", gdk_font_big3,
"x", (double) cx,
"y", (double) cy + needle_size + needle_size / 3 + 30,
"x", (double) gcomprisBoard->width*0.15,
"y", (double) cy + needle_size + needle_size / 3,
"anchor", GTK_ANCHOR_CENTER,
"fill_color", "green",
"fill_color", "white",
NULL);
display_digital_time(time_to_find_item, &timeToFind);
item_list = g_list_append (item_list, time_to_find_item);
......
......@@ -148,7 +148,7 @@ static void menu_start (GcomprisBoard *agcomprisBoard)
/* set initial values for this level */
gcomprisBoard->level = 1;
gcomprisBoard->maxlevel=1;
gcompris_bar_set(GCOMPRIS_BAR_HELP|GCOMPRIS_BAR_CONFIG);
gcompris_bar_set(GCOMPRIS_BAR_HELP|GCOMPRIS_BAR_CONFIG|GCOMPRIS_BAR_ABOUT);
menu_pause(FALSE);
......
......@@ -23,6 +23,8 @@
#define SOUNDLISTFILE PACKAGE
static int gamewon;
static GList *item_list = NULL;
static GList *item2del_list = NULL;
......@@ -89,6 +91,9 @@ static void paratrooper_destroy_item(CloudItem *clouditem);
static void paratrooper_destroy_items(void);
static void paratrooper_destroy_all_items(void);
static void paratrooper_next_level(void);
static gint item_event(GnomeCanvasItem *item, GdkEvent *event, void *data);
static void next_state();
static double speed = 0.0;
static double imageZoom = 0.0;
......@@ -137,6 +142,7 @@ static void pause_board (gboolean pause)
if(gcomprisBoard==NULL)
return;
printf("paratrooper pause = %d won=%d\n", pause, gamewon);
if(pause)
{
if (dummy_id) {
......@@ -154,6 +160,17 @@ static void pause_board (gboolean pause)
}
else
{
if(gamewon == TRUE) /* the game is won */
{
gcomprisBoard->level++;
if(gcomprisBoard->level>gcomprisBoard->maxlevel) { // the current board is finished : bail out
board_finished(BOARD_FINISHED_RANDOM);
return;
}
printf("paratrooper pause start next level\n");
}
// Unpause code
if(!drop_cloud_id) {
drop_cloud_id = gtk_timeout_add (1000,
(GtkFunction) paratrooper_drop_clouds, NULL);
......@@ -164,6 +181,9 @@ static void pause_board (gboolean pause)
if(paratrooperItem.status!=TUX_INPLANE && paratrooperItem.status!=TUX_LANDED) {
drop_tux_id = gtk_timeout_add (1000, (GtkFunction) paratrooper_move_tux, NULL);
}
if(gamewon == TRUE) /* the game is won */
paratrooper_next_level();
}
}
......@@ -302,42 +322,7 @@ gint key_press(guint keyval)
return TRUE;
}
switch(paratrooperItem.status)
{
case TUX_INPLANE:
gnome_canvas_item_move(paratrooperItem.rootitem, plane_x+100, 0);
paratrooperItem.x += plane_x+100;
gnome_canvas_item_show(paratrooperItem.paratrooper);
paratrooperItem.status = TUX_DROPPING;
drop_tux_id = gtk_timeout_add (10, (GtkFunction) paratrooper_move_tux, NULL);
break;
case TUX_DROPPING:
gnome_canvas_item_lower_to_bottom(paratrooperItem.parachute);
gnome_canvas_item_show(paratrooperItem.parachute);
paratrooperItem.speed /= 3;
paratrooperItem.status = TUX_FLYING;
break;
case TUX_LANDED:
gcomprisBoard->level++;
if(gcomprisBoard->level>gcomprisBoard->maxlevel) { // the current board is finished : bail out
board_finished(BOARD_FINISHED_RANDOM);
return TRUE;
}
paratrooper_next_level();
break;
case TUX_CRASHED:
/* Restart */
gnome_canvas_item_move(paratrooperItem.rootitem, -paratrooperItem.x, -paratrooperItem.y+60);
paratrooperItem.status = TUX_INPLANE;
paratrooperItem.x = 0;
paratrooperItem.y = 60;
paratrooperItem.speed = 3;
gnome_canvas_item_hide(paratrooperItem.paratrooper);
gnome_canvas_item_show(planeitem);
break;
default:
break;
}
next_state();
return TRUE;
}
......@@ -374,7 +359,6 @@ help ()
"<br>Click on any keyboard key to let Tux jump. Another keypress will open the "
"'parachute'."
));
}
}
......@@ -389,6 +373,8 @@ static void paratrooper_next_level()
GdkPixbuf *pixmap = NULL;
char *str = NULL;
gamewon = FALSE;
gcompris_bar_set_level(gcomprisBoard);
paratrooper_destroy_all_items();
......@@ -416,6 +402,9 @@ static void paratrooper_next_level()
"width_set", TRUE,
"height_set", TRUE,
NULL);
gtk_signal_connect(GTK_OBJECT(planeitem), "event",
(GtkSignalFunc) item_event,
NULL);
gdk_pixbuf_unref(pixmap);
windspeed = (3 + rand()%gcomprisBoard->level);
......@@ -495,6 +484,9 @@ static void paratrooper_next_level()
NULL);
gnome_canvas_item_hide(paratrooperItem.paratrooper);
gdk_pixbuf_unref(pixmap);
gtk_signal_connect(GTK_OBJECT(paratrooperItem.paratrooper), "event",
(GtkSignalFunc) item_event,
NULL);
g_free(str);
str = g_strdup_printf("%s%s", pixmapsdir, "parachute.png");
......@@ -560,7 +552,7 @@ static void paratrooper_move_cloud(CloudItem *clouditem)
{
item2del_list = g_list_append (item2del_list, clouditem);
/* Drop a new cloud */
/* Move cloud rearm */
drop_cloud_id = gtk_timeout_add (200,
(GtkFunction) paratrooper_drop_clouds, NULL);
}
......@@ -678,6 +670,7 @@ static gint paratrooper_move_tux (GtkWidget *widget, gpointer data)
gnome_canvas_item_hide(paratrooperItem.parachute);
paratrooperItem.status = TUX_LANDED;
gcompris_play_sound (SOUNDLISTFILE, "bonus");
next_state();
}
else
{
......@@ -689,6 +682,7 @@ static gint paratrooper_move_tux (GtkWidget *widget, gpointer data)
gnome_canvas_item_hide(paratrooperItem.parachute);
paratrooperItem.status = TUX_CRASHED;
gcompris_play_sound (SOUNDLISTFILE, "crash");
next_state();
}
}
}
......@@ -771,6 +765,69 @@ static gint paratrooper_drop_clouds (GtkWidget *widget, gpointer data)
}
/*
* This is the state machine of the paratrooper
*/
void next_state()
{
switch(paratrooperItem.status)
{
case TUX_INPLANE:
gnome_canvas_item_move(paratrooperItem.rootitem, plane_x+100, 0);
paratrooperItem.x += plane_x+100;
gnome_canvas_item_show(paratrooperItem.paratrooper);
paratrooperItem.status = TUX_DROPPING;
drop_tux_id = gtk_timeout_add (10, (GtkFunction) paratrooper_move_tux, NULL);
break;
case TUX_DROPPING:
gnome_canvas_item_lower_to_bottom(paratrooperItem.parachute);
gnome_canvas_item_show(paratrooperItem.parachute);
paratrooperItem.speed /= 3;
paratrooperItem.status = TUX_FLYING;
break;
case TUX_LANDED:
gamewon = TRUE;
gcompris_display_bonus(gamewon, BONUS_RANDOM);
break;
case TUX_CRASHED:
/* Restart */
gnome_canvas_item_move(paratrooperItem.rootitem, -paratrooperItem.x, -paratrooperItem.y+60);
paratrooperItem.status = TUX_INPLANE;
paratrooperItem.x = 0;
paratrooperItem.y = 60;
paratrooperItem.speed = 3;
gnome_canvas_item_hide(paratrooperItem.paratrooper);
gnome_canvas_item_show(planeitem);
break;
default:
break;
}
}
static gint
item_event(GnomeCanvasItem *item, GdkEvent *event, void *data)
{
if(!get_board_playing())
return FALSE;
switch (event->type)
{
case GDK_BUTTON_PRESS:
next_state();
break;
default:
break;
}
return FALSE;
}
/* Local Variables: */
/* mode:c */
......
/* gcompris - planegame.c
*
* Time-stamp: <2001/12/26 21:45:04 bruno>
* Time-stamp: <2002/01/07 00:12:30 bruno>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -497,9 +497,9 @@ static gint planegame_move_items (GtkWidget *widget, gpointer data)
/* move the plane */
planegame_move_plane(planeitem);
dummy_id = gtk_timeout_add (speed,
(GtkFunction) planegame_move_items, NULL);
printf("ICI\n");
// dummy_id = gtk_timeout_add (speed,
// (GtkFunction) planegame_move_items, NULL);
return(FALSE);
}
......@@ -592,8 +592,8 @@ static gint planegame_drop_items (GtkWidget *widget, gpointer data)
{
planegame_add_new_item();
drop_items_id = gtk_timeout_add (fallSpeed,
(GtkFunction) planegame_drop_items, NULL);
// drop_items_id = gtk_timeout_add (fallSpeed,
// (GtkFunction) planegame_drop_items, NULL);
return (FALSE);
}
......
/* gcompris - shapegame.c
*
* Time-stamp: <2001/12/26 21:44:18 bruno>
* Time-stamp: <2002/01/06 02:11:18 bruno>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -47,25 +47,26 @@ typedef enum
/* Let's define the structure for a single shape */
typedef struct _Shape Shape;
struct _Shape {
char *name; /* name of the shape */
char *pixmapfile; /* relative pixmap file name of the shape */
GnomeCanvasPoints* points; /* OR list of points for this shape */
char *targetfile; /* OPTIONAL relative pixmap file name of the target shape, by default
a red point is displayed */
double x; /* x coordinate */
double y; /* y coordinate */
double w; /* width */
double h; /* height */
double zoomx; /* x zoom factor */
double zoomy; /* y zoom factor */
gint position; /* depth position 0=bottom other=intermediate */
ShapeType type; /* Type of shape */
GnomeCanvasItem *item; /* Canvas item for this shape */
Shape *icon_shape; /* Temporary Canvas icon shape for this shape */
GnomeCanvasItem *bad_item; /* Temporary bad placed Canvas item for this shape */
gboolean found; /* The user found this item */
char *name; /* name of the shape */
char *pixmapfile; /* relative pixmap file name of the shape */
GnomeCanvasPoints* points; /* OR list of points for this shape */
char *targetfile; /* OPTIONAL relative pixmap file name of the target shape, by default
a red point is displayed */
double x; /* x coordinate */
double y; /* y coordinate */
double w; /* width */
double h; /* height */
double zoomx; /* x zoom factor */
double zoomy; /* y zoom factor */
gint position; /* depth position 0=bottom other=intermediate */
ShapeType type; /* Type of shape */
GnomeCanvasItem *item; /* Canvas item for this shape */
Shape *icon_shape; /* Temporary Canvas icon shape for this shape */
GnomeCanvasItem *bad_item; /* Temporary bad placed Canvas item for this shape */
gboolean found; /* The user found this item */
GnomeCanvasItem *target_point; /* Target point item for this shape */
};
gchar *colorlist [] =
......@@ -818,6 +819,103 @@ item_event(GnomeCanvasItem *item, GdkEvent *event, Shape *shape)
return FALSE;
}
/*
* Special mode to edit the board by moving the target point
*/
static gint
item_event_edition(GnomeCanvasItem *item, GdkEvent *event, Shape *shape)
{
static double x, y;
double new_x, new_y;
GdkCursor *fleur;
static int dragging;
double item_x, item_y;
if(!get_board_playing())
return FALSE;
if(shape==NULL) {
g_warning("Shape is NULL : Should not happen");
return FALSE;
}
item_x = event->button.x;
item_y = event->button.y;
gnome_canvas_item_w2i(item->parent, &item_x, &item_y);
switch (event->type)
{
case GDK_BUTTON_PRESS:
switch(event->button.button)
{
case 1:
if (event->button.state & GDK_SHIFT_MASK)
{
/* Cheat code to save an XML file */
write_xml_file("/tmp/gcompris-board.xml");
}
else
{
x = item_x;
y = item_y;
item = shape->target_point;
fleur = gdk_cursor_new(GDK_FLEUR);
gnome_canvas_item_grab(item,
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
fleur,
event->button.time);
gdk_cursor_destroy(fleur);
dragging = TRUE;
}
break;
default:
break;
}
break;
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK))
{
new_x = item_x;
new_y = item_y;
gnome_canvas_item_move(item, new_x - x, new_y - y);
gnome_canvas_item_move(shape->item, new_x - x, new_y - y);
// Update the shape's coordinate
shape->x = shape->x + new_x - x;
shape->y = shape->y + new_y - y;
x = new_x;
y = new_y;
}
break;
case GDK_BUTTON_RELEASE:
if(dragging)
{
gnome_canvas_item_ungrab(item, event->button.time);
gnome_canvas_item_raise_to_top(item);
dragging = FALSE;
}
break;
default:
break;
}
return FALSE;
}
static void
setup_item(GnomeCanvasItem *item, Shape *shape)
{
......@@ -880,6 +978,10 @@ add_shape_to_canvas(Shape *shape)
"outline_color", "black",
"width_pixels", 0,
NULL);
shape->target_point = item;
gtk_signal_connect(GTK_OBJECT(item), "event",
(GtkSignalFunc) item_event_edition,
shape);
}
gnome_canvas_item_lower_to_bottom(item);
item_list = g_list_append (item_list, item);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment