/* ===================================================================== * * =====================================================================*/ static void highlight_selected(int c) { int x, y; g_assert(c>=0 && c<8); x = (X[c*2] + X[c*2+1]) /2; y = (Y[(int)(c/4)*2] + Y[(int)(c/4)*2+1]) /2; x -= highlight_width/2; y -= highlight_height; g_object_set (highlight_image_item, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); gc_item_absolute_move(highlight_image_item, x, y); }
// if plate = 1 , move to plate g (left) // if plate = -1, move to plate d (right) // if plate = 0 , move to the item list void scale_item_move_to(ScaleItem *item, int plate) { ScaleItem *scale; GList *list; gboolean found; int index; if(plate != 0) { if(item->plate) item->plate_index = -1; else gc_sound_play_ogg ("sounds/eraser1.wav", NULL); // find the first free place in the plate for(index=0; index < 2 * PLATE_SIZE; index++) { found = FALSE; for(list = item_list; list; list = list->next) { scale = list->data; if(scale->plate_index == index && scale->plate == plate) found=TRUE; } if(!found) { // move to the plate gdouble x = (plate == 1 ? balance_left_x : balance_right_x); gdouble y = (plate == 1 ? balance_left_y + last_delta : balance_right_y - last_delta); item->plate = plate; item->plate_index = index; /* Reparent */ g_object_ref(item->item); goo_canvas_item_remove(item->item); goo_canvas_item_add_child ((plate == 1 ? group_g : group_d), item->item, -1); g_object_unref(item->item); gc_item_absolute_move(item->item, x + (index % PLATE_SIZE) * ITEM_W, y + PLATE_Y - ITEM_H + 5 - (index >= PLATE_SIZE ? ITEM_H : 0)); break; } } if(found) // can't find place plate=0; } if(plate==0) { // move the item to the list if(item->plate) gc_sound_play_ogg ("sounds/eraser1.wav", NULL); item->plate = 0; /* Reparent */ g_object_ref(item->item); goo_canvas_item_remove(item->item); goo_canvas_item_add_child (group_m, item->item, -1); g_object_unref(item->item); gc_item_absolute_move(item->item, item->x, item->y); goo_canvas_item_raise(item->item, NULL); } scale_anim_plate(); if (!gamewon) gc_item_focus_init(item->item, NULL); }
/* ===================================================================== * Periodically recalculate some submarine parameters, with a slow delay * =====================================================================*/ static gboolean update_timeout_very_slow() { /* charging */ if(!boardRootItem) return FALSE; if(board_paused) return TRUE; if (air_charging && depth < SURFACE_DEPTH+5.0) { air += 100.0*UPDATE_DELAY_VERY_SLOW/1000.0; setAir(air); } if (battery_charging && depth < SURFACE_DEPTH+5.0) { if (battery < 0.3*battery) battery += 500.0*UPDATE_DELAY_VERY_SLOW/1000.0; else if (battery < 0.6*battery) battery += 200.0*UPDATE_DELAY_VERY_SLOW/1000.0; else if (battery < 0.8*battery) battery += 100.0*UPDATE_DELAY_VERY_SLOW/1000.0; else battery += 50.0*UPDATE_DELAY_VERY_SLOW/1000.0; } /* battery */ battery -= submarine_horizontal_speed * submarine_horizontal_speed/3.0 * UPDATE_DELAY_VERY_SLOW/1000.0; if (battery < 0.0) { battery = 0.0; speed_ordered = 0; setSpeed(speed_ordered); } setBattery( battery ); /* bubbling */ if ( (ballast_av_purge_open && ballast_av_air > 0.0) || ( ballast_av_chasse_open && ballast_av_air == MAX_BALLAST ) ) { gc_item_absolute_move( bubbling[0], submarine_x + submarine_width/2, depth - 30.0); g_object_set ( bubbling[0] , "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); gc_sound_play_ogg ("sounds/bubble.wav", NULL); } else g_object_set ( bubbling[0] , "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); if ( (ballast_ar_purge_open && ballast_ar_air > 0.0) || ( ballast_ar_chasse_open && ballast_ar_air == MAX_BALLAST ) ) { gc_item_absolute_move( bubbling[2], submarine_x - submarine_width/2, depth - 30.0); gc_sound_play_ogg ("sounds/bubble.wav", NULL); g_object_set ( bubbling[2] , "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); } else g_object_set ( bubbling[2] , "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); if (regleur_purge_open && regleur < MAX_REGLEUR) { gc_item_absolute_move( bubbling[1], submarine_x, depth - 30.0); gc_sound_play_ogg ("sounds/bubble.wav", NULL); g_object_set ( bubbling[1] , "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); } else g_object_set ( bubbling[1] , "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); return TRUE; }
/* ==================================== */ 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; }