~ubuntu-branches/ubuntu/trusty/gcompris/trusty

« back to all changes in this revision

Viewing changes to src/boards/canal_lock.c

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2006-12-15 23:08:17 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061215230817-exr5ks1hd73s3tlk
Tags: 8.2.2-1
* New upstream bugfix release, fixes among other things the support for
  the version of gnucap shipped in etch.
* Add missing dependency on python-gtk2 (Closes: #396523).
* Removed reference to non-existent sound file from memory.c (upstream
  fix - impacts 8.2 as well).  
* Now suggests gnuchess, gnucap, and tuxpaint.
* Updated extended description for the main package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 */
19
19
 
20
 
#include <ctype.h>
21
 
#include <math.h>
22
 
#include <assert.h>
23
 
 
24
20
#include "gcompris/gcompris.h"
25
21
 
26
22
#define SOUNDLISTFILE PACKAGE
110
106
  {
111
107
    NULL,
112
108
    NULL,
113
 
    N_("Operate a canal lock"),
114
 
    N_("Tux is in trouble in his ship. He needs to take it through a lock.\nHelp Tux and understand how a canal lock works."),
 
109
    "Operate a canal lock",
 
110
    "Tux is in trouble in his ship. He needs to take it through a lock",
115
111
    "Bruno Coudoin <bruno.coudoin@free.fr>",
116
112
    NULL,
117
113
    NULL,
125
121
    NULL,
126
122
    set_level,
127
123
    NULL,
 
124
    NULL,
 
125
    NULL,
128
126
    NULL
129
127
  };
130
128
 
134
132
 *
135
133
 */
136
134
 
137
 
BoardPlugin
138
 
*get_bplugin_info(void)
139
 
{
140
 
  return &menu_bp;
141
 
}
 
135
GET_BPLUGIN_INFO(canal_lock)
142
136
 
143
137
/*
144
138
 * in : boolean TRUE = PAUSE : FALSE = CONTINUE
172
166
 
173
167
      canal_lock_next_level();
174
168
 
175
 
      gcompris_bar_set(0);
 
169
      gc_bar_set(0);
176
170
 
177
171
      animation = FALSE;
178
172
 
231
225
static void canal_lock_next_level()
232
226
{
233
227
 
234
 
  gcompris_set_background(gnome_canvas_root(gcomprisBoard->canvas),
 
228
  gc_set_background(gnome_canvas_root(gcomprisBoard->canvas),
235
229
                          "canal_lock/canal_lock_bg.png");
236
230
 
237
 
  gcompris_bar_set_level(gcomprisBoard);
 
231
  gc_bar_set_level(gcomprisBoard);
238
232
 
239
233
  canal_lock_destroy_all_items();
240
234
  gamewon = FALSE;
263
257
/* ==================================== */
264
258
static GnomeCanvasItem *canal_lock_create_item(GnomeCanvasGroup *parent)
265
259
{
266
 
  int i,j;
267
 
  GnomeCanvasItem *item = NULL;
268
260
  GdkPixbuf *pixmap = NULL;
269
261
 
270
262
  boardRootItem = GNOME_CANVAS_GROUP(
276
268
                                                            NULL));
277
269
 
278
270
  /* The boat */
279
 
  pixmap = gcompris_load_pixmap("gcompris/misc/tuxboat.png");
 
271
  pixmap = gc_pixmap_load("gcompris/misc/tuxboat.png");
280
272
 
281
273
  tuxboat_item = gnome_canvas_item_new (boardRootItem,
282
274
                                        gnome_canvas_pixbuf_get_type (),
283
 
                                        "pixbuf",  pixmap, 
 
275
                                        "pixbuf",  pixmap,
284
276
                                        "x", (double) (LEFT_CANAL_WIDTH - gdk_pixbuf_get_width(pixmap)) / 2,
285
277
                                        "y", (double) BASE_LINE - LEFT_CANAL_HEIGHT - gdk_pixbuf_get_height(pixmap)*0.9,
286
278
                                        NULL);
288
280
                     (GtkSignalFunc) item_event,
289
281
                     NULL);
290
282
  gtk_signal_connect(GTK_OBJECT(tuxboat_item), "event",
291
 
                     (GtkSignalFunc) gcompris_item_event_focus,
 
283
                     (GtkSignalFunc) gc_item_focus_event,
292
284
                     NULL);
293
285
  tuxboat_width = gdk_pixbuf_get_width(pixmap);
 
286
  gdk_pixbuf_unref(pixmap);
294
287
 
295
288
  /* This is the ground canal */
296
289
  gnome_canvas_item_new (boardRootItem,
409
402
                         NULL);
410
403
 
411
404
  /* And to finish, the 2 canal locks */
412
 
  canallock_left_item = 
 
405
  canallock_left_item =
413
406
    gnome_canvas_item_new (boardRootItem,
414
407
                           gnome_canvas_rect_get_type (),
415
408
                           "x1", (double) LEFT_CANAL_WIDTH + MIDDLE_CANAL_WIDTH * 0.1,
423
416
                     (GtkSignalFunc) item_event,
424
417
                     NULL);
425
418
 
426
 
  canallock_right_item = 
 
419
  canallock_right_item =
427
420
    gnome_canvas_item_new (boardRootItem,
428
421
                           gnome_canvas_rect_get_type (),
429
422
                           "x1", (double) LEFT_CANAL_WIDTH + MIDDLE_CANAL_WIDTH * 0.9,
451
444
    gcomprisBoard->sublevel=1;
452
445
    gcomprisBoard->level++;
453
446
    if(gcomprisBoard->level>gcomprisBoard->maxlevel) { // the current board is finished : bail out
454
 
      board_finished(BOARD_FINISHED_RANDOM);
 
447
      gc_bonus_end_display(BOARD_FINISHED_RANDOM);
455
448
      return;
456
449
    }
457
 
    gcompris_play_ogg ("bonus", NULL);
 
450
    gc_sound_play_ogg ("sounds/bonus.ogg", NULL);
458
451
  }
459
452
  canal_lock_next_level();
460
453
}
463
456
/* Move the boat to the next possible position */
464
457
static void move_boat()
465
458
{
466
 
  gboolean status = TRUE;
467
 
  double y1 = 0;
468
 
  gint min = LEFT_CANAL_HEIGHT;
469
459
 
470
460
  /* If there is already an animation do nothing else set animation to avoid deadlock */
471
461
  if(animation)
499
489
  else
500
490
    {
501
491
      /* No possible move */
502
 
      gcompris_play_ogg ("crash", NULL);
 
492
      gc_sound_play_ogg ("sounds/crash.ogg", NULL);
503
493
      animation = FALSE;
504
494
      return;
505
495
    }
506
496
 
507
 
  gnome_canvas_item_get_bounds(tuxboat_item, &timer_item_x1, &timer_item_y1, 
 
497
  gnome_canvas_item_get_bounds(tuxboat_item, &timer_item_x1, &timer_item_y1,
508
498
                               &timer_item_x2, &timer_item_y2);
509
499
 
510
500
  timer_item = tuxboat_item;
533
523
      lock_water_low = !lock_water_low;
534
524
      y1 = BASE_LINE - RIGHT_CANAL_HEIGHT;
535
525
    }
536
 
  else 
 
526
  else
537
527
    {
538
528
      /* The water level is correct */
539
529
      animation = FALSE;
540
530
      return;
541
531
    }
542
532
 
543
 
  gnome_canvas_item_get_bounds(canal_middle_item, &timer_item_x1, &timer_item_y1, 
 
533
  gnome_canvas_item_get_bounds(canal_middle_item, &timer_item_x1, &timer_item_y1,
544
534
                               &timer_item_x2, &timer_item_y2);
545
535
 
546
536
  timer_item = canal_middle_item;
558
548
{
559
549
  gboolean status = TRUE;
560
550
  double y1 = 0;
561
 
  gint min;
562
 
  guint animate_speed;
 
551
  gint min = 0;
 
552
  guint animate_speed = 0;
563
553
 
564
554
  /* If there is already an animation do nothing else set animation to avoid deadlock */
565
555
  if(animation)
566
556
    return;
567
557
  animation = TRUE;
568
558
 
569
 
  gnome_canvas_item_get_bounds(item, &timer_item_x1, &timer_item_y1, 
 
559
  gnome_canvas_item_get_bounds(item, &timer_item_x1, &timer_item_y1,
570
560
                               &timer_item_x2, &timer_item_y2);
571
561
 
572
562
  if(item == lock_left_item)
614
604
 
615
605
 
616
606
/* ==================================== */
617
 
static gboolean animate_step() 
 
607
static gboolean animate_step()
618
608
{
619
609
 
620
610
  if(!gcomprisBoard)
624
614
  timer_item_y1 += timer_step_y1;
625
615
 
626
616
  if(GNOME_IS_CANVAS_PIXBUF(timer_item))
627
 
    gnome_canvas_item_set(timer_item, 
 
617
    gnome_canvas_item_set(timer_item,
628
618
                          "x", timer_item_x1,
629
619
                          "y", timer_item_y1,
630
620
                          NULL);
631
621
  else if(GNOME_IS_CANVAS_RECT(timer_item))
632
 
    gnome_canvas_item_set(timer_item, 
 
622
    gnome_canvas_item_set(timer_item,
633
623
                          "x1", timer_item_x1,
634
624
                          "y1", timer_item_y1,
635
625
                          NULL);
639
629
    {
640
630
      double item_x1, item_y1, item_x2, item_y2;
641
631
 
642
 
      gnome_canvas_item_get_bounds(tuxboat_item, &item_x1, &item_y1, 
 
632
      gnome_canvas_item_get_bounds(tuxboat_item, &item_x1, &item_y1,
643
633
                                   &item_x2, &item_y2);
644
634
 
645
 
      gnome_canvas_item_set(tuxboat_item, 
 
635
      gnome_canvas_item_set(tuxboat_item,
646
636
                            "y", item_y1 + timer_step_y1,
647
637
                            NULL);
648
638
    }
673
663
/* Highlight the given item */
674
664
static void hightlight(GnomeCanvasItem *item, gboolean status)
675
665
{
676
 
  guint color;
677
 
  
 
666
  guint color = 0;
 
667
 
678
668
  /* This is an image, not a rectangle */
679
669
  if(item == tuxboat_item)
680
670
    return;
709
699
  if(board_paused)
710
700
    return FALSE;
711
701
 
712
 
  switch (event->type) 
 
702
  switch (event->type)
713
703
    {
714
704
    case GDK_ENTER_NOTIFY:
715
705
      hightlight(item, TRUE);
721
711
 
722
712
      /* If there is already an animation do nothing */
723
713
      if(animation)
724
 
        return;
725
 
           
 
714
        return FALSE;
 
715
 
726
716
      if(item == lock_left_item)
727
717
        {
728
718
          if(lock_water_low && canallock_right_up)
729
719
              toggle_lock(item);
730
720
          else
731
 
            gcompris_play_ogg ("crash", NULL);
 
721
            gc_sound_play_ogg ("sounds/crash.ogg", NULL);
732
722
 
733
723
        }
734
724
      else if(item == lock_right_item)
736
726
          if(!lock_water_low && canallock_left_up)
737
727
              toggle_lock(item);
738
728
          else
739
 
            gcompris_play_ogg ("crash", NULL);
 
729
            gc_sound_play_ogg ("sounds/crash.ogg", NULL);
740
730
        }
741
731
      else if(item == canallock_left_item && canallock_right_up)
742
732
        {
743
733
          if(lock_right_up)
744
734
              toggle_lock(item);
745
735
          else
746
 
            gcompris_play_ogg ("crash", NULL);
 
736
            gc_sound_play_ogg ("sounds/crash.ogg", NULL);
747
737
        }
748
738
      else if(item == canallock_right_item && canallock_left_up)
749
739
        {
750
740
          if(lock_left_up)
751
741
              toggle_lock(item);
752
742
          else
753
 
            gcompris_play_ogg ("crash", NULL);
 
743
            gc_sound_play_ogg ("sounds/crash.ogg", NULL);
754
744
        }
755
745
      else if(item == tuxboat_item)
756
746
        {
758
748
        }
759
749
      else
760
750
        {
761
 
          gcompris_play_ogg ("crash", NULL);
 
751
          gc_sound_play_ogg ("sounds/crash.ogg", NULL);
762
752
        }
763
753
      break;
764
754
    default:
770
760
  /*
771
761
    gamewon = TRUE;
772
762
    canal_lock_destroy_all_items();
773
 
    gcompris_display_bonus(gamewon, BONUS_SMILEY);
 
763
    gc_bonus_display(gamewon, BONUS_SMILEY);
774
764
  */
775
765
  return FALSE;
776
766
}