9 #include "soundeffects.h"
11 /* current bubble count */
12 static int nr_bubbles;
14 static Bubble *bubbles = NULL;
15 static SA_Image bubbles_image_data;
18 static int bubble_state_change;
20 static Bubble_settings bubble_settings;
22 Bubble_settings *bubble_get_settings_ptr(void)
24 return &bubble_settings;
27 void bubble_exit(void)
29 if(bubbles_image_data.pixbuf != NULL)
30 g_object_unref(bubbles_image_data.pixbuf);
31 memset(&bubbles_image_data, 0, sizeof(SA_Image));
34 void bubble_init(void)
38 ad = aquarium_get_settings_ptr();
41 bubble_state_change = ad->ymax / (BUBBLES_FRAMES - 1);
47 bubbles = g_malloc0(sizeof(Bubble) * bubble_settings.max_bubbles);
51 load_image("bubbles.png", &bubbles_image_data, BUBBLES_FRAMES);
55 void bubble_update(void)
61 ad = aquarium_get_settings_ptr();
64 for(i = 0; i < nr_bubbles; i++){
65 aquarium_clean_image(bubbles[i].x, bubbles[i].y,
66 bubbles_image_data.width,
67 bubbles_image_data.height);
71 /* make a new bubble, if needed */
72 if(((nr_bubbles < bubble_settings.max_bubbles)) && (g_rand_int_range(ad->rnd, 0, 100) <= 32)) {
73 bubbles[nr_bubbles].x = ad->viewpoint_start_x + (g_rand_int_range(ad->rnd, 0, ad->xmax));
74 bubbles[nr_bubbles].y = ad->viewpoint_start_y + ad->ymax;
76 bubbles[nr_bubbles].speed = g_rand_double_range(ad->rnd, 1.0/13.0, 12.0/13.0);
83 /* Update and draw the bubbles */
84 for (i = 0; i < nr_bubbles; i++) {
86 /* Move the bubble vertically */
87 bubbles[i].y -= bubbles[i].speed;
90 if (bubbles[i].y < ad->viewpoint_start_y) {
92 bubbles[i].x = bubbles[nr_bubbles - 1].x;
93 bubbles[i].y = bubbles[nr_bubbles - 1].y;
94 bubbles[i].speed = bubbles[nr_bubbles - 1].speed;
97 /* We must check the previously last bubble, which is
98 * now the current bubble, also. */
103 /* Draw the bubble */
104 x = bubbles[i].x - ad->viewpoint_start_x;
105 y = ((int) bubbles[i].y) - ad->viewpoint_start_y;
107 /* calculate bubble sequence - 0 to 4 (determine bubble sprite idx) */
108 seq = y / bubble_state_change;
110 /* draw the bubble, using offset-to-center calculated from current
111 * sequence, and make the bubble bigger as we go up. 120 - alpha */
113 if(seq < BUBBLES_FRAMES){
114 aquarium_draw_pic_alpha(&bubbles_image_data, bubbles_image_data.width,
115 bubbles_image_data.height, x, y,
121 /* Sometimes play bubble sound */