void bullet_action(bullet_type* pbullet)
{
- pbullet->base.x = pbullet->base.x + pbullet->base.xm * frame_ratio;
- pbullet->base.y = pbullet->base.y + pbullet->base.ym * frame_ratio;
+ pbullet->base.x = pbullet->base.x + pbullet->base.xm * frame_ratio;
+ pbullet->base.y = pbullet->base.y + pbullet->base.ym * frame_ratio;
- collision_swept_object_map(&pbullet->old_base,&pbullet->base);
+ collision_swept_object_map(&pbullet->old_base,&pbullet->base);
- if (issolid(pbullet->base.x, pbullet->base.y + 4) || issolid(pbullet->base.x, pbullet->base.y))
- {
- pbullet->base.ym = -pbullet->base.ym;
- pbullet->base.y = (int)(pbullet->base.y / 32) * 32;
- }
+ if (issolid(pbullet->base.x, pbullet->base.y + 4) || issolid(pbullet->base.x, pbullet->base.y))
+ {
+ pbullet->base.ym = -pbullet->base.ym;
+ pbullet->base.y = (int)(pbullet->base.y / 32) * 32;
+ }
- pbullet->base.ym = pbullet->base.ym + GRAVITY;
+ pbullet->base.ym = pbullet->base.ym + GRAVITY;
- if (pbullet->base.x < scroll_x ||
- pbullet->base.x > scroll_x + screen->w ||
- pbullet->base.y < 0 ||
- pbullet->base.y > screen->h ||
- issolid(pbullet->base.x + 4, pbullet->base.y + 2) ||
- issolid(pbullet->base.x, pbullet->base.y + 2))
- {
- bullets.erase(static_cast<std::vector<bullet_type>::iterator>(pbullet));
- }
+ if (pbullet->base.x < scroll_x ||
+ pbullet->base.x > scroll_x + screen->w ||
+ pbullet->base.y < 0 ||
+ pbullet->base.y > screen->h ||
+ issolid(pbullet->base.x + 4, pbullet->base.y + 2) ||
+ issolid(pbullet->base.x, pbullet->base.y + 2))
+ {
+ bullets.erase(static_cast<std::vector<bullet_type>::iterator>(pbullet));
+ }
}
if (pbullet->base.x >= scroll_x - pbullet->base.width &&
pbullet->base.x <= scroll_x + screen->w)
{
- texture_draw(&img_bullet, pbullet->base.x - scroll_x, pbullet->base.y,
+ texture_draw(&img_bullet, pbullet->base.x - scroll_x, pbullet->base.y, 255,
NO_UPDATE);
}
}
void bullet_collision(bullet_type* pbullet, int c_object)
{
-
- if(c_object == CO_BADGUY)
- bullets.erase(static_cast<std::vector<bullet_type>::iterator>(pbullet));
-
+ if(c_object == CO_BADGUY) {
+ std::vector<bullet_type>::iterator i;
+ for(i = bullets.begin(); i != bullets.end(); ++i) {
+ if(& (*i) == pbullet) {
+ bullets.erase(i);
+ return;
+ }
+ }
+ }
}
void upgrade_init(upgrade_type *pupgrade, float x, float y, int dir, int kind)
{
- if (pupgrade->base.height < 32)
- {
- /* Rise up! */
+ if (pupgrade->base.height < 32)
+ {
+ /* Rise up! */
- pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio;
- if(pupgrade->base.height > 32)
- pupgrade->base.height = 32;
- }
- else
- {
- /* Move around? */
+ pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio;
+ if(pupgrade->base.height > 32)
+ pupgrade->base.height = 32;
+ }
+ else
+ {
+ /* Move around? */
- if (pupgrade->kind == UPGRADE_MINTS ||
- pupgrade->kind == UPGRADE_HERRING)
- {
- pupgrade->base.x = pupgrade->base.x + pupgrade->base.xm * frame_ratio;
- pupgrade->base.y = pupgrade->base.y + pupgrade->base.ym * frame_ratio;
+ if (pupgrade->kind == UPGRADE_MINTS ||
+ pupgrade->kind == UPGRADE_HERRING)
+ {
+ pupgrade->base.x = pupgrade->base.x + pupgrade->base.xm * frame_ratio;
+ pupgrade->base.y = pupgrade->base.y + pupgrade->base.ym * frame_ratio;
- collision_swept_object_map(&pupgrade->old_base,&pupgrade->base);
+ collision_swept_object_map(&pupgrade->old_base,&pupgrade->base);
- /* Off the screen? Kill it! */
+ /* Off the screen? Kill it! */
- if (pupgrade->base.x < scroll_x - pupgrade->base.width)
- upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
- if (pupgrade->base.y > screen->h)
- upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
+ if (pupgrade->base.x < scroll_x - pupgrade->base.width)
+ upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
+ if (pupgrade->base.y > screen->h)
+ upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
- if (issolid(pupgrade->base.x + 1, pupgrade->base.y + 32.) ||
- issolid(pupgrade->base.x + 31., pupgrade->base.y + 32.))
+ if (issolid(pupgrade->base.x + 1, pupgrade->base.y + 32.) ||
+ issolid(pupgrade->base.x + 31., pupgrade->base.y + 32.))
+ {
+ if (pupgrade->base.ym > 0)
{
- if (pupgrade->base.ym > 0)
+ if (pupgrade->kind == UPGRADE_MINTS)
{
- if (pupgrade->kind == UPGRADE_MINTS)
- {
- pupgrade->base.ym = 0;
- }
- else if (pupgrade->kind == UPGRADE_HERRING)
- {
- pupgrade->base.ym = -8;
- }
-
- pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
+ pupgrade->base.ym = 0;
+ }
+ else if (pupgrade->kind == UPGRADE_HERRING)
+ {
+ pupgrade->base.ym = -8;
}
- }
- else
- pupgrade->base.ym = pupgrade->base.ym + GRAVITY * frame_ratio;
- if (issolid(pupgrade->base.x - 1, (int) pupgrade->base.y))
- {
- if(pupgrade->base.xm < 0)
- pupgrade->base.xm = -pupgrade->base.xm;
- }
- else if (issolid(pupgrade->base.x + pupgrade->base.width, (int) pupgrade->base.y))
- {
- if(pupgrade->base.xm > 0)
- pupgrade->base.xm = -pupgrade->base.xm;
+ pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
}
}
+ else
+ pupgrade->base.ym = pupgrade->base.ym + GRAVITY * frame_ratio;
+ if (issolid(pupgrade->base.x - 1, (int) pupgrade->base.y))
+ {
+ if(pupgrade->base.xm < 0)
+ pupgrade->base.xm = -pupgrade->base.xm;
+ }
+ else if (issolid(pupgrade->base.x + pupgrade->base.width, (int) pupgrade->base.y))
+ {
+ if(pupgrade->base.xm > 0)
+ pupgrade->base.xm = -pupgrade->base.xm;
+ }
}
+
+ }
}
void upgrade_draw(upgrade_type* pupgrade)
{
SDL_Rect dest;
- if (pupgrade->base.height < 32)
+ if (pupgrade->base.height < 32)
+ {
+ /* Rising up... */
+
+ dest.x = (int)(pupgrade->base.x - scroll_x);
+ dest.y = (int)(pupgrade->base.y + 32 - pupgrade->base.height);
+ dest.w = 32;
+ dest.h = (int)pupgrade->base.height;
+
+ if (pupgrade->kind == UPGRADE_MINTS)
+ texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h);
+ else if (pupgrade->kind == UPGRADE_COFFEE)
+ texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h);
+ else if (pupgrade->kind == UPGRADE_HERRING)
+ texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h);
+ }
+ else
+ {
+ if (pupgrade->kind == UPGRADE_MINTS)
{
- /* Rising up... */
-
- dest.x = (int)(pupgrade->base.x - scroll_x);
- dest.y = (int)(pupgrade->base.y + 32 - pupgrade->base.height);
- dest.w = 32;
- dest.h = (int)pupgrade->base.height;
-
- if (pupgrade->kind == UPGRADE_MINTS)
- texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
- else if (pupgrade->kind == UPGRADE_COFFEE)
- texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
- else if (pupgrade->kind == UPGRADE_HERRING)
- texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
+ texture_draw(&img_mints,
+ pupgrade->base.x - scroll_x, pupgrade->base.y);
}
- else
+ else if (pupgrade->kind == UPGRADE_COFFEE)
{
- if (pupgrade->kind == UPGRADE_MINTS)
- {
- texture_draw(&img_mints,
- pupgrade->base.x - scroll_x, pupgrade->base.y,
- NO_UPDATE);
- }
- else if (pupgrade->kind == UPGRADE_COFFEE)
- {
- texture_draw(&img_coffee,
- pupgrade->base.x - scroll_x, pupgrade->base.y,
- NO_UPDATE);
- }
- else if (pupgrade->kind == UPGRADE_HERRING)
- {
- texture_draw(&img_golden_herring,
- pupgrade->base.x - scroll_x, pupgrade->base.y,
- NO_UPDATE);
- }
+ texture_draw(&img_coffee,
+ pupgrade->base.x - scroll_x, pupgrade->base.y);
+ }
+ else if (pupgrade->kind == UPGRADE_HERRING)
+ {
+ texture_draw(&img_golden_herring,
+ pupgrade->base.x - scroll_x, pupgrade->base.y);
}
+ }
}
void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
{
- player_type* pplayer = NULL;
+ Player* pplayer = NULL;
switch (c_object)
{
/* Remove the upgrade: */
/* p_c_object is CO_PLAYER, so assign it to pplayer */
- pplayer = (player_type*) p_c_object;
+ pplayer = (Player*) p_c_object;
upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
pplayer->base.height = 64;
pplayer->base.y -= 32;
if(collision_object_map(&pplayer->base))
- {
- pplayer->base.height = 32;
- pplayer->base.y += 32;
- pplayer->duck = YES;
- }
+ {
+ pplayer->base.height = 32;
+ pplayer->base.y += 32;
+ pplayer->duck = true;
+ }
timer_start(&super_bkgd_timer, 350);
}
else if (pupgrade->kind == UPGRADE_COFFEE)
{
play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
- pplayer->got_coffee = YES;
+ pplayer->got_coffee = true;
timer_start(&super_bkgd_timer, 250);
}
else if (pupgrade->kind == UPGRADE_HERRING)