/* ======================================= */ static void process_ok() { mark_pieces(); if(gamewon) gc_bonus_display(gamewon, GC_BONUS_SMILEY); }
static void movePos(int x1, int y1, int x2,int y2, int richting) { int ret,wall,i,bo=1; ret=1; wall=Maze[x1][y1]; if (wall&richting) { gc_sound_play_ogg ("sounds/brick.wav", NULL); ret=0; } if (ret) { gc_sound_play_ogg ("sounds/prompt.wav", NULL); if (Maze[x2][y2]&SET) { for (i=(ind); i>=0 && bo; i--) { if(position[i][0]==x2 && position[i][1]==y2) { bo=0; move_image(mazegroup,x2,y2,tuxgroup); // draw_rect(mazegroup,x2,y2,"blue"); } else { Maze[position[i][0]][position[i][1]]&=~SET; draw_rect(mazegroup, position[i][0], position[i][1], "red"); draw_combined_rect(mazegroup, position[i-1][0],position[i-1][1], position[i][0],position[i][1], "red"); ind--; } } } else { ind++; position[ind][0]=x2; position[ind][1]=y2; Maze[x2][y2]|=SET; if (position[ind][0]==(breedte-1) && position[ind][1]==(end)) { gamewon = TRUE; twoDdisplay(); gc_bonus_display(gamewon, GC_BONUS_LION); } else { draw_combined_rect(mazegroup, x1, y1, x2, y2, "green"); draw_rect(mazegroup,x1,y1,"green"); move_image(mazegroup,x2,y2,tuxgroup); } } } }
/* ==================================== */ static gboolean animate_step() { if(!gcomprisBoard) return FALSE; GooCanvasBounds bounds; goo_canvas_item_get_bounds(timer_item, &bounds); if(GOO_IS_CANVAS_SVG(timer_item)) goo_canvas_item_translate(timer_item, timer_step_x1, timer_step_y1); else if(GOO_IS_CANVAS_RECT(timer_item)) g_object_set(timer_item, "x", bounds.x1 + timer_step_x1, "y", bounds.y1 + timer_step_y1, "height", bounds.y2 - bounds.y1 - timer_step_y1, NULL); /* Special case for raising/lowering the boat */ if(boat_position==BOAT_POS_MIDDLE && timer_item==canal_middle_item) { goo_canvas_item_translate(tuxboat_item, 0, timer_step_y1); gc_item_focus_remove(tuxboat_item, NULL); } if((bounds.y1 >= timer_item_limit_y && timer_step_y1 > 0) || (bounds.y1 <= timer_item_limit_y && timer_step_y1 < 0)) { gtk_timeout_remove (timer_id); timer_id = 0; animation = FALSE; update_water(); gc_item_focus_init(tuxboat_item, NULL); g_object_set (tuxboat_item, "svg-id", "#BOAT_NO_SAIL", NULL); } else if((bounds.x1 >= timer_item_limit_x && timer_step_x1 > 0) || (bounds.x1 <= timer_item_limit_x && timer_step_x1 < 0)) { gtk_timeout_remove (timer_id); timer_id = 0; animation = FALSE; update_water(); if (gamewon) { gc_bonus_display(TRUE, GC_BONUS_FLOWER); gamewon = FALSE; } gc_item_focus_init(tuxboat_item, NULL); g_object_set (tuxboat_item, "svg-id", "#BOAT_NO_SAIL", NULL); } return TRUE; }
static void player_win() { gc_sound_play_ogg ("sounds/bonus.wav", NULL); /* Try the next level */ if (tux_pairs <= player_pairs) gcomprisBoard->level++; if(gcomprisBoard->level>gcomprisBoard->maxlevel) gcomprisBoard->level = gcomprisBoard->maxlevel; gc_bonus_display((tux_pairs <= player_pairs), GC_BONUS_LION); }
/* ==================================== */ void moneyactivity_process_ok() { if(board_paused) /*return FALSE*/; if(price_target >= money_widget_get_total(seller_money) - 0.001 && price_target <= money_widget_get_total(seller_money) + 0.001 ) { gamewon = TRUE; gc_bonus_display(gamewon, GC_BONUS_SMILEY); } }
/* ===================================================================== * * =====================================================================*/ static gboolean ok_timeout() { timer_id = 0; gc_bonus_display(gamewon, GC_BONUS_SMILEY); if (!gamewon) errors--; if (errors >= 1) update_clock(); g_object_set (highlight_image_item, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); return FALSE; }
static void test_win (GooCanvasItem **board) { int i; for (i = 0; i < 15; i++) if (!board[i] || (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (board[i]), "piece_num")) != i)) return; gamewon = TRUE; fifteen_destroy_all_items(); gc_bonus_display(gamewon, GC_BONUS_SMILEY); }
static void player_win(GooCanvasItem *item) { gletters_destroy_item(item); gc_sound_play_ogg ("sounds/flip.wav", NULL); gcomprisBoard->sublevel++; if(gcomprisBoard->sublevel > gcomprisBoard->number_of_sublevel) { /* Try the next level */ gcomprisBoard->level++; if(gcomprisBoard->level>gcomprisBoard->maxlevel) gcomprisBoard->level = gcomprisBoard->maxlevel; gamewon = TRUE; gletters_destroy_all_items(); gc_bonus_display(gamewon, GC_BONUS_SMILEY); } else { gc_score_set(gcomprisBoard->sublevel); /* Drop a new item now to speed up the game */ if(g_list_length(item_list)==0) { if (drop_items_id) { /* Remove pending new item creation to sync the falls */ g_source_remove (drop_items_id); drop_items_id = 0; } if(!drop_items_id) { drop_items_id = g_timeout_add (0, gletters_drop_items, NULL); } } } }
/* ==================================== */ static gboolean process_ok_timeout() { gc_bonus_display(gamewon, GC_BONUS_FLOWER); return FALSE; }
static gboolean ok_timeout() { gc_bonus_display(gamewon, GC_BONUS_SMILEY); g_timeout_add(TIME_CLICK_TO_BONUS*5, quit_after_delay, NULL); return FALSE; }
/* ===================================================================== * Periodically recalculate some submarine parameters, with a larger delay * =====================================================================*/ static gboolean update_timeout_slow() { gdouble delta_assiette; if(!boardRootItem) return FALSE; if(board_paused) return TRUE; /* speed : don't reach instantly the ordered speed */ if (speed_ordered != submarine_horizontal_speed) { submarine_horizontal_speed += (speed_ordered-submarine_horizontal_speed)/10.0; if (fabs(speed_ordered - submarine_horizontal_speed) < 0.1) submarine_horizontal_speed = speed_ordered; } /* assiette */ delta_assiette = (ballast_ar_air - ballast_av_air)/200.0 + (barre_av_angle - barre_ar_angle)/5.0*submarine_horizontal_speed; assiette -= delta_assiette*UPDATE_DELAY/10000.0; if (assiette < -30.0) assiette = -30.0; if (assiette > 30.0) assiette = 30.0; /* If surfacing, diminish the 'assiette' */ if ( depth <= 5.0 + SURFACE_DEPTH) { assiette *= depth/(depth+1.0); } /* update some dynamic parameters */ /* resulting_weight > 0 ==> the sub goes deeper regleur : this is the qty of water */ resulting_weight = weight - ballast_av_air - ballast_ar_air + regleur; submarine_vertical_speed = resulting_weight/300.0 + submarine_horizontal_speed*sin(DEG_TO_RAD(-assiette)); /* if depth rudders are in the same direction */ if (barre_ar_angle != 0.0 && barre_av_angle != 0.0) { if (fabs(barre_ar_angle)/barre_ar_angle == fabs(barre_av_angle)/barre_av_angle) { gdouble a = (fabs(barre_ar_angle) > fabs(barre_av_angle)) ? barre_av_angle : barre_ar_angle; submarine_vertical_speed += a * submarine_horizontal_speed/30.0; } } /* position & depth */ submarine_x += submarine_horizontal_speed * cos(DEG_TO_RAD(assiette)) * UPDATE_DELAY_SLOW/1000.0; depth += submarine_vertical_speed * UPDATE_DELAY_SLOW/1000.0; if (depth < SURFACE_DEPTH) depth = SURFACE_DEPTH; if (depth > MAX_DEPTH) depth = MAX_DEPTH; // show an alert if some parameters reach the limit if (depth >= MAX_DEPTH-20.0 || assiette == -30.0 || assiette == 30.0 || air == 0.0 || battery == 0.0) g_object_set (alert_submarine, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); else g_object_set (alert_submarine, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); /* if the submarine dives, stop charging air tanks and batteries */ if ( depth >= SURFACE_DEPTH+10.0 ) { if (air_charging) { air_charging = FALSE; gc_item_rotate_with_center(air_compressor_item, 0, TRIGGER_CENTER_X, TRIGGER_CENTER_Y ); } if (battery_charging) { battery_charging = FALSE; gc_item_rotate_with_center(battery_charger_item, 0, TRIGGER_CENTER_X, TRIGGER_CENTER_Y ); } } /* if the submarine is too close from right, put it on the left */ if ( submarine_x > WRAP_X ) { /* Check its within the gate range */ GooCanvasBounds bounds; goo_canvas_item_get_bounds (submarine_item, &bounds); if(bounds.y1 < gate_top_current_y || bounds.y2 > gate_bottom_y) { /* It's a crash */ submarine_explosion(); } else { gamewon = TRUE; /* Let the user play indefinitly at level 3 */ if(gcomprisBoard->level<3) gc_bonus_display(gamewon, GC_BONUS_SMILEY); else { submarine_x = SUBMARINE_INITIAL_X; depth = SUBMARINE_INITIAL_DEPTH; } } } /* Open the door */ if(treasure_captured && gate_top_current_y > gate_top_y) open_door(); /* display the submarine */ goo_canvas_item_set_simple_transform(submarine_item, submarine_x - submarine_width/2.0, depth + SURFACE_DEPTH - submarine_height/2.0, 1, -assiette); /* the frigate */ { GooCanvasBounds bounds; goo_canvas_item_get_bounds(frigate_item, &bounds); //goo_canvas_item_translate(frigate_item, - FRIGATE_SPEED * UPDATE_DELAY_SLOW/1000.0, 0.0); /* detects a collision between the frigate and the submarine */ if (depth <= 30.0 && !submarine_destroyed) if ( (submarine_x - submarine_width <= bounds.x1 && submarine_x >= bounds.x2) || (submarine_x - submarine_width >= bounds.x1 && submarine_x - submarine_width <= bounds.x2) || (submarine_x >= bounds.x1 && submarine_x <= bounds.x2) ) { submarine_explosion(); } /* wraps the destroyer if it reached the left side (and disappeared for a long time)*/ //if (bounds.x2 < -300.0) //gc_item_absolute_move( frigate_item, BOARDWIDTH, bounds.y1 ); } /* whale detection */ { gdouble dist1, dist2, dist3; dist1 = hypot( submarine_x -submarine_width/2 -whale_x, depth+SURFACE_IN_BACKGROUND-whale_y); dist2 = hypot(submarine_x - submarine_width - whale_x, depth+SURFACE_IN_BACKGROUND-whale_y); dist3 = hypot(submarine_x - whale_x, depth+SURFACE_IN_BACKGROUND-whale_y); /* magnetic detection (dist1) or collision with the whale (dist2 & dist3) */ if ( (dist1 < WHALE_DETECTION_RADIUS || dist2 < WHALE_DETECTION_RADIUS || dist3 < WHALE_DETECTION_RADIUS) && !submarine_destroyed ) { g_object_set (whale, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); g_object_set (big_explosion, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); submarine_explosion(); } } /* treasure detection */ { gdouble dist1, dist2, dist3; dist1 = hypot( submarine_x -submarine_width/2 -treasure_x, depth+SURFACE_IN_BACKGROUND-treasure_y); dist2 = hypot(submarine_x - submarine_width - treasure_x, depth+SURFACE_IN_BACKGROUND-treasure_y); dist3 = hypot(submarine_x - treasure_x, depth+SURFACE_IN_BACKGROUND-treasure_y); /* magnetic detection (dist1) or collision with the treasure (dist2 & dist3) */ if ( (dist1 < TREASURE_DETECTION_RADIUS || dist2 < TREASURE_DETECTION_RADIUS || dist3 < TREASURE_DETECTION_RADIUS) && !treasure_captured ) { gc_sound_play_ogg("sounds/tuxok.wav", NULL); g_object_set (treasure, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); treasure_captured = TRUE; open_door(); } } return TRUE; }
static void bonus() { gc_bonus_display(gamewon, GC_BONUS_SMILEY); animate_id = 0; }
/* ==================================== */ static gint item_event(GooCanvasItem *item, GooCanvasItem *target, GdkEvent *event, PieceItem *data) { double item_x, item_y; if(!gcomprisBoard) return FALSE; if(board_paused) return FALSE; if(data && !data->on_top) return FALSE; switch (event->type) { case GDK_ENTER_NOTIFY: g_object_set(item, "stroke-color", "white", "line-width", (double)3, NULL); break; case GDK_LEAVE_NOTIFY: g_object_set(item, "stroke-color", "black", "line-width", (double)1, NULL); break; case GDK_BUTTON_PRESS: switch(event->button.button) { case 1: gc_sound_play_ogg ("sounds/bleep.wav", NULL); gc_drag_offset_save(event); goo_canvas_item_raise(data->group, NULL); break; } break; case GDK_MOTION_NOTIFY: gc_drag_item_move(event, data->group); break; case GDK_BUTTON_RELEASE: { gint i; gint tmpi, tmpj; double tmpx, tmpy; PieceItem *piece_src; PieceItem *piece_dst; gint col = 0, line; item_x = event->button.x; item_y = event->button.y; goo_canvas_convert_from_item_space(goo_canvas_item_get_canvas(item), item, &item_x, &item_y); /* Search the column (x) where this item is ungrabbed */ for(i=0; i<=number_of_item_x; i++) if(position[i][0]->x < item_x && position[i+1][0]->x > item_x) col = i; /* Bad drop / Outside of column area */ /* Bad drop / On the same column */ if(col<0 || col > number_of_item_x || col == data->i) { gc_sound_play_ogg ("sounds/eraser2.wav", NULL); /* Return to the original position */ gc_item_absolute_move (data->group, data->x , data->y); return FALSE; } /* Now search the free line (y) */ line = number_of_item_y; for(i=number_of_item_y-1; i>=0; i--) if(position[col][i]->color == -1) line = i; /* Bad drop / Too many pieces here */ if(line >= number_of_item_y) { gc_sound_play_ogg ("sounds/eraser2.wav", NULL); /* Return to the original position */ gc_item_absolute_move (data->group, data->x , data->y); return FALSE; } /* Update ontop values for the piece under the grabbed one */ if(data->j>0) position[data->i][data->j-1]->on_top = TRUE; /* Update ontop values for the piece under the ungrabbed one */ if(line>0) position[col][line-1]->on_top = FALSE; /* Move the piece */ piece_dst = position[col][line]; piece_src = data; gc_item_absolute_move (data->group, piece_dst->x , piece_dst->y); gc_sound_play_ogg ("sounds/scroll.wav", NULL); /* Swap values in the pieces */ tmpx = data->x; tmpy = data->y; piece_src->x = piece_dst->x; piece_src->y = piece_dst->y; piece_dst->x = tmpx; piece_dst->y = tmpy; tmpi = data->i; tmpj = data->j; position[tmpi][tmpj]->i = piece_dst->i; position[tmpi][tmpj]->j = piece_dst->j; piece_dst->i = tmpi; piece_dst->j = tmpj; position[piece_src->i][piece_src->j] = piece_src; position[piece_dst->i][piece_dst->j] = piece_dst; // dump_solution(); if(is_completed()) { gamewon = TRUE; hanoi_destroy_all_items(); gc_bonus_display(gamewon, GC_BONUS_SMILEY); } } break; default: break; } return FALSE; }