4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "resources.hpp"
27 #include "sprite/sprite_manager.hpp"
28 #include "badguy/badguy.hpp"
32 const float BULLET_XM = 600;
33 const float BULLET_STARTING_YM = 0;
36 Bullet::Bullet(const Vector& pos, float xm, int dir, BonusType type)
37 : life_count(3), type(type)
39 float speed = dir == RIGHT ? BULLET_XM : -BULLET_XM;
40 physic.set_velocity_x(speed + xm);
42 if(type == FIRE_BONUS) {
43 sprite.reset(sprite_manager->create("images/objects/bullets/firebullet.sprite"));
44 } else if(type == ICE_BONUS) {
46 sprite.reset(sprite_manager->create("images/objects/bullets/icebullet.sprite"));
50 bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
58 Bullet::update(float elapsed_time)
60 // remove bullet when it's offscreen
62 Sector::current()->camera->get_translation().x;
64 Sector::current()->camera->get_translation().y;
65 if (get_pos().x < scroll_x ||
66 get_pos().x > scroll_x + SCREEN_WIDTH ||
67 // get_pos().y < scroll_y ||
68 get_pos().y > scroll_y + SCREEN_HEIGHT ||
74 movement = physic.get_movement(elapsed_time);
78 Bullet::draw(DrawingContext& context)
80 sprite->draw(context, get_pos(), LAYER_OBJECTS);
84 Bullet::collision_solid(const CollisionHit& hit)
86 if(hit.top || hit.bottom) {
87 physic.set_velocity_y(-physic.get_velocity_y());
89 } else if(hit.left || hit.right) {
90 if(type == ICE_BONUS) {
91 physic.set_velocity_x(-physic.get_velocity_x());
99 Bullet::ricochet(GameObject& , const CollisionHit& hit)
101 collision_solid(hit);
105 Bullet::collision(GameObject& , const CollisionHit& )