/** * add_aieee_bubble * @x: x position * @y: y position * * Description: * adds and "Aieee" bubble at @x,@y **/ void add_aieee_bubble (gint x, gint y) { remove_bubble (); add_bubble (x, y); bubble_type = BUBBLE_AIEEE; }
/** * add_yahoo_bubble * @x: x position * @y: y position * * Description: * adds and "Yahoo" bubble at @x,@y **/ void add_yahoo_bubble (gint x, gint y) { remove_bubble (); add_bubble (x, y); bubble_type = BUBBLE_YAHOO; }
/** * add_splat_bubble * @x: x position * @y: y position * * Description: * adds a "Splat" speech bubble at @x,@y **/ void add_splat_bubble (gint x, gint y) { remove_bubble (); add_bubble (x, y); bubble_ypos += BUBBLE_YOFFSET; bubble_type = BUBBLE_SPLAT; }
static void game_tick(int paint) { int i, j, k; int yoff, xoff; int bx, by; SDL_Rect rect; SDL_Rect rect2; xoff = 30, yoff = 40; p.angle += p.right * 90 * time_step; if(p.angle < -85) p.angle = -85; else if(p.angle > 85) p.angle = 85; if(level == 255) { k = 0; for(i = 0; i < field_height; ++i) { for(j = 0; j < WIDTH(i); ++j) { if(p.field[i][j]) ++k; } } for(i = 0; i < sizeof(p.mbubbles) / sizeof(p.mbubbles[0]); ++i) { if(p.mbubbles[i].color && !p.mbubbles[i].falling) ++k; } k += p.evil_bubble_count; if(k < 20) { for(i = 0; i < 5; ++i) p.evil_bubbles[p.evil_bubble_count++] = (rand() % 8) + 1; } } for(k = 0; k < sizeof(p.mbubbles) / sizeof(p.mbubbles[0]); ++k) { struct moving_bubble* b = &p.mbubbles[k]; if(!b->color) continue; if(b->y > 480) b->color = 0; if(!b->falling) { b->x += b->velx * time_step; b->y += b->vely * time_step; if(level < sizeof(levels) / sizeof(levels[0])) { if(levels[level].mode == GM_GRAVITY) b->vely += 1; else if(levels[level].mode == GM_INV_GRAVITY) b->vely -= 3; } if(b->x < 0) { b->x = -b->x; b->velx = -b->velx; if(sound_enable) sounds[2].pos = 0; } else if(b->x > max_x) { b->x = 2 * max_x - b->x; b->velx = -b->velx; if(sound_enable) sounds[2].pos = 0; } for(i = -1; i < field_height; ++i) { for(j = 0; j < WIDTH(i); ++j) { float posx, posy; float dirx, diry; if(i != -1 && !p.field[i][j]) continue; posx = j * 32.0f + ((i & 1) ? 32.0f : 16.0f); posy = i * 28.0f + 16.0f; dirx = posx - (b->x + 16.0f); diry = posy - (b->y + 16.0f); float minrage = 784.0f; if(level < sizeof(levels) / sizeof(levels[0]) && levels[level].mode == GM_GRAVITY) minrage = 32 * 32; if(dirx * dirx + diry * diry < minrage) { if(fabs(dirx) > fabs(diry)) { by = i; if(dirx > 0) bx = j - 1; else bx = j + 1; } else // fabs(dirx) <= fabs(diry) { if(diry > 0) by = i - 1; else by = i + 1; if(by & 1) { if(dirx > 0) bx = j - 1; else bx = j; } else { if(dirx > 0) bx = j; else bx = j + 1; } } if(by > 11) { int a, b; for(a = 0; a < field_height; ++a) for(b = 0; b < WIDTH(a); ++b) remove_bubble(&p, b, a, 0); state = GS_PINK; for(a = 0; a < sizeof(p.mbubbles) / sizeof(p.mbubbles[0]); ++a) p.mbubbles[a].falling = 1; } else { if(stick(&p, bx, by, b->color)) { int a; if(level != 255) state = GS_SHINE_GET; for(a = 0; a < sizeof(p.mbubbles) / sizeof(p.mbubbles[0]); ++a) p.mbubbles[a].falling = 1; } b->color = 0; } goto collide; } } } collide:; } else { b->vely += 1500.0f * time_step; b->x += b->velx * time_step; b->y += b->vely * time_step; } } if(paint) { int draw_anyway = 0; if(p.bubble > 7 || p.next_bubble > 7) draw_anyway = 1; if(p.dirty_minx < p.dirty_maxx) { SET_RECT(rect, xoff + p.dirty_minx, yoff + p.dirty_miny, p.dirty_maxx - p.dirty_minx, p.dirty_maxy - p.dirty_miny); SDL_BlitSurface(spbg, &rect, screen, &rect); } for(i = 0; i < sizeof(p.mbubbles) / sizeof(p.mbubbles[0]); ++i) { if(p.mbubbles[i].lastpaintx == INT_MIN) continue; SET_RECT(rect, p.mbubbles[i].lastpaintx + xoff, p.mbubbles[i].lastpainty + yoff, 32, 32); SDL_BlitSurface(spbg, &rect, screen, &rect); mark_dirty(&p, p.mbubbles[i].lastpaintx, p.mbubbles[i].lastpainty, 32, 32); p.mbubbles[i].lastpaintx = INT_MIN; } if(p.dirty_minx < p.dirty_maxx || (level < sizeof(levels) / sizeof(levels[0]) && levels[level].has_joker)) { for(i = 0; i < 10; ++i) { for(j = 0; j < WIDTH(i); ++j) { if(!p.field[i][j]) continue; rect.x = xoff + j * 32 + ((i & 1) ? 16 : 0); rect.y = yoff + i * 28; rect.w = 32; rect.h = 32; int color = p.field[i][j] - 1; if(color < 8) cond_blit(&p, bubbles[color], 0, screen, &rect); else { mark_dirty(&p, rect.x - xoff, rect.y - yoff, rect.w, rect.h); cond_blit(&p, bubbles[(now / 100) % 8], 0, screen, &rect); } } } } if(p.last_angle != p.angle || ( 78 <= p.dirty_maxx && 178 >= p.dirty_minx && 316 <= p.dirty_maxy && 432 >= p.dirty_miny)) { mark_dirty(&p, 78, 316, 100, 100); p.last_angle = p.angle; } if(p.dirty_minx < p.dirty_maxx || draw_anyway) { rect.x = xoff + 78; rect.y = yoff + 316; rect.w = 100; rect.h = 100; if(draw_anyway) mark_dirty(&p, rect.x - xoff, rect.y - yoff, 100, 100); cond_blit(&p, spbg, &rect, screen, &rect); for(i = 10; i < field_height; ++i) { for(j = 0; j < WIDTH(i); ++j) { if(!p.field[i][j]) continue; rect2.x = xoff + j * 32 + ((i & 1) ? 16 : 0); rect2.y = yoff + i * 28; rect2.w = 32; rect2.h = 32; int color = p.field[i][j] - 1; if(color < 8) cond_blit(&p, bubbles[color], 0, screen, &rect2); else cond_blit(&p, bubbles[(now / 100) % 8], 0, screen, &rect2); } } if((78 <= p.dirty_maxx && 178 >= p.dirty_minx && 316 <= p.dirty_maxy && 432 >= p.dirty_miny) || draw_anyway) { rect2.x = xoff + 112; rect2.y = yoff + 350; rect2.w = 32; rect2.h = 32; if(p.bubble < 8) SDL_BlitSurface(bubbles[p.bubble], 0, screen, &rect2); else SDL_BlitSurface(bubbles[(now / 100) % 8], 0, screen, &rect2); SDL_BlitSurface(base[(int) ((p.angle + 90.0f) * 128 / 180.0f)], 0, screen, &rect); rect2.x = xoff + 112; rect2.y = yoff + 400; if(p.next_bubble < 8) SDL_BlitSurface(bubbles[p.next_bubble], 0, screen, &rect2); else SDL_BlitSurface(bubbles[(now / 100) % 8], 0, screen, &rect2); } } p.dirty_minx = max_field_width * 32; p.dirty_miny = 440; p.dirty_maxx = 0; p.dirty_maxy = 0; for(i = 0; i < sizeof(p.mbubbles) / sizeof(p.mbubbles[0]); ++i) { if(!p.mbubbles[i].color) continue; SET_RECT(rect, (int) p.mbubbles[i].x + xoff, (int) p.mbubbles[i].y + yoff, 32, 32); int color = p.mbubbles[i].color - 1; if(color < 8) SDL_BlitSurface(bubbles[color], 0, screen, &rect); else { mark_dirty(&p, rect.x - xoff, rect.y - yoff, rect.w, rect.h); SDL_BlitSurface(bubbles[(now / 100) % 8], 0, screen, &rect); } p.mbubbles[i].lastpaintx = rect.x - xoff; p.mbubbles[i].lastpainty = rect.y - yoff; } if(level < sizeof(levels) / sizeof(levels[0]) && levels[level].mode == GM_TIME_ATTACK) { wchar_t buf[256]; int remaining = levels[level].time - (now - first_tick) / 1000 + bonus; if(remaining <= 0) { if(levels[level].shoot_bonus) { bonus += levels[level].shoot_bonus; shoot(&p, random_bubble(&p), -1); remaining = bonus; } else { state = GS_PINK; remaining = 0; } } #ifndef WIN32 swprintf(buf, sizeof(buf), L"%u", remaining); #else swprintf(buf, L"%u", remaining); #endif SET_RECT(rect, 355, 104, 256, 128); SDL_BlitSurface(spbg, &rect, screen, &rect); print_string(0, 483, 144, L"Time remaining", 1); print_string(0, 483, 184, buf, 1); } else if(level < sizeof(levels) / sizeof(levels[0]) && levels[level].mode == GM_AVALANCHE) { if(now - last_avalanche > levels[level].time * 1000) { p.evil_bubbles[p.evil_bubble_count++] = random_bubble(&p) + 1; last_avalanche = now; } } { wchar_t buf[256]; SET_RECT(rect, 355, 232, 256, 80); SDL_BlitSurface(spbg, &rect, screen, &rect); if(level != 255) { #ifndef WIN32 swprintf(buf, sizeof(buf), L"Level %u", level + 1); #else swprintf(buf, L"Level %u", level + 1); #endif print_string(0, 483, 264, buf, 1); } else { print_string(0, 483, 264, L"Infinity", 1); } } } }