/* Toggle the given lock */ static void toggle_lock(GooCanvasItem *item) { gboolean status = TRUE; double y1 = 0; gint min = 0; guint animate_speed = 0; /* If there is already an animation do nothing else set animation to avoid deadlock */ if(animation) return; animation = TRUE; gc_sound_play_ogg ("sounds/bleep.wav", NULL); if(item == lock_left_item) { status = lock_left_up; lock_left_up = !lock_left_up; y1 = BASE_LINE - LOCK_HEIGHT_MAX; min = BASE_LINE - LOCK_HEIGHT_MIN; animate_speed = ANIMATE_SPEED; } else if(item == lock_right_item) { status = lock_right_up; lock_right_up = !lock_right_up; y1 = BASE_LINE - LOCK_HEIGHT_MAX; min = BASE_LINE - LOCK_RHEIGHT_MIN; animate_speed = ANIMATE_SPEED; } else if(item == canallock_left_item) { status = canallock_left_up; canallock_left_up = !canallock_left_up; y1 = SUBCANAL_BASE_LINE - SUBCANAL_HEIGHT; min = SUBCANAL_BASE_LINE - CANALLOCK_HEIGHT_MIN; animate_speed = ANIMATE_SPEED; } else if(item == canallock_right_item) { status = canallock_right_up; canallock_right_up = !canallock_right_up; y1 = SUBCANAL_BASE_LINE - SUBCANAL_HEIGHT; min = SUBCANAL_BASE_LINE - CANALLOCK_HEIGHT_MIN; animate_speed = ANIMATE_SPEED; } timer_item = item; timer_item_limit_y = (status ? min : y1); timer_step_y1 = (status ? 2 : -2); timer_step_x1 = 0; gc_item_focus_remove(tuxboat_item, NULL); timer_id = gtk_timeout_add (animate_speed, (GtkFunction) animate_step, NULL); }
/* ==================================== */ 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; }
void listPiecesClear() { guint i, j; for(i=0; i<g_list_length(listPieces); i++) { Piece *piece = g_list_nth_data(listPieces, i); for(j=0; j<g_list_length(piece->listitem); j++) { GooCanvasItem *item = g_list_nth_data(piece->listitem, j); g_signal_handlers_disconnect_by_func(item, (GCallback) item_event, piece); gc_item_focus_remove(item, NULL); } g_free(piece); } g_list_free(listPieces); listPieces = NULL; }
/* Update the water level if necessary */ static void update_water() { gboolean status = TRUE; double y1 = 0; gint min = BASE_LINE - LEFT_CANAL_HEIGHT; /* If there is already an animation do nothing else set animation to avoid deadlock */ if(animation) return; animation = TRUE; if((!canallock_left_up && !lock_water_low) || (!canallock_right_up && lock_water_low)) { status = !lock_water_low; lock_water_low = !lock_water_low; y1 = BASE_LINE - RIGHT_CANAL_HEIGHT; } else { /* The water level is correct */ animation = FALSE; return; } timer_item = canal_middle_item; timer_item_limit_y = (status ? min : y1); timer_step_y1 = (status ? 2 : -2); timer_step_x1 = 0; gc_item_focus_remove(tuxboat_item, NULL); timer_id = gtk_timeout_add (ANIMATE_SPEED, (GtkFunction) animate_step, NULL); }
/* Move the boat to the next possible position */ static void move_boat() { /* If there is already an animation do nothing * else set animation to avoid deadlock */ if(animation) return; animation = TRUE; if(boat_position == BOAT_POS_LEFT && !lock_left_up) { boat_position = BOAT_POS_MIDDLE; timer_item_limit_x = LEFT_CANAL_WIDTH + (MIDDLE_CANAL_WIDTH - tuxboat_width)/2; timer_step_x1 = 2; g_object_set (tuxboat_item, "svg-id", "#BOAT", NULL); } else if(boat_position == BOAT_POS_MIDDLE && !lock_left_up) { boat_position = BOAT_POS_LEFT; timer_item_limit_x = (LEFT_CANAL_WIDTH - tuxboat_width)/2; timer_step_x1 = -2; if (from == 1) { gamewon = TRUE; from = 0; } g_object_set (tuxboat_item, "svg-id", "#BOAT", NULL); } else if(boat_position == BOAT_POS_MIDDLE && !lock_right_up) { boat_position = BOAT_POS_RIGHT; timer_item_limit_x = LEFT_CANAL_WIDTH + MIDDLE_CANAL_WIDTH + (RIGHT_CANAL_WIDTH - tuxboat_width)/2; timer_step_x1 = 2; if (from == 0) { gamewon = TRUE; from = 1; } g_object_set (tuxboat_item, "svg-id", "#BOAT", NULL); } else if(boat_position == BOAT_POS_RIGHT && !lock_right_up) { boat_position = BOAT_POS_MIDDLE; timer_item_limit_x = LEFT_CANAL_WIDTH + (MIDDLE_CANAL_WIDTH - tuxboat_width)/2; timer_step_x1 = -2; g_object_set (tuxboat_item, "svg-id", "#BOAT", NULL); } else { /* No possible move */ gc_sound_play_ogg ("sounds/crash.ogg", NULL); animation = FALSE; return; } gc_item_focus_remove(tuxboat_item, NULL); gc_sound_play_ogg ("sounds/eraser2.wav", NULL); timer_item = tuxboat_item; timer_step_y1 = 0; timer_id = gtk_timeout_add (ANIMATE_SPEED, (GtkFunction) animate_step, NULL); }