- SDL_Rect dest;
- if (pupgrade->base.alive)
- {
- 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,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);
- }
- else
- {
- 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);
- }
- }
- }
+ Sprite* sprite;
+ switch(kind) {
+ case UPGRADE_GROWUP: sprite = img_growup; break;
+ case UPGRADE_ICEFLOWER: sprite = img_iceflower; break;
+ case UPGRADE_FIREFLOWER: sprite = img_fireflower; break;
+ case UPGRADE_HERRING: sprite = img_star; break;
+ case UPGRADE_1UP: sprite = img_1up; break;
+ default:
+ assert(!"wrong type in Powerup::draw()");
+ }
+
+ if(base.height < 32) // still raising up?
+ sprite->draw(context, Vector(base.x, base.y + (32 - base.height)),
+ LAYER_TILES - 10);
+ else
+ sprite->draw(context, Vector(base.x, base.y), LAYER_OBJECTS);
+}
+
+void
+Upgrade::bump(Player* player)
+{
+ // these can't be bumped
+ if(kind != UPGRADE_GROWUP)
+ return;
+
+ sound_manager->play_sound(sounds[SND_BUMP_UPGRADE], Vector(base.x, base.y));
+
+ // determine new direction
+ Direction old_dir = dir;
+ if (player->base.x + player->base.width/2 > base.x + base.width/2)
+ dir = LEFT;
+ else
+ dir = RIGHT;
+
+ // do a little jump and change direction (if necessary)
+ if (dir != old_dir)
+ physic.set_velocity(-physic.get_velocity_x(), 3);
+ else
+ physic.set_velocity_y(3);
+
+ physic.enable_gravity(true);
+}
+
+void
+Upgrade::collision(const MovingObject& , int)
+{
+ // later