2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "object/bullet.hpp"
18 #include "object/camera.hpp"
19 #include "sprite/sprite_manager.hpp"
20 #include "supertux/globals.hpp"
21 #include "supertux/sector.hpp"
24 const float BULLET_XM = 600;
25 const float BULLET_STARTING_YM = 0;
28 Bullet::Bullet(const Vector& pos, float xm, int dir, BonusType type) :
34 float speed = dir == RIGHT ? BULLET_XM : -BULLET_XM;
35 physic.set_velocity_x(speed + xm);
37 if(type == FIRE_BONUS) {
38 sprite = sprite_manager->create("images/objects/bullets/firebullet.sprite");
39 } else if(type == ICE_BONUS) {
41 sprite = sprite_manager->create("images/objects/bullets/icebullet.sprite");
43 log_warning << "Bullet::Bullet called with unknown BonusType" << std::endl;
45 sprite = sprite_manager->create("images/objects/bullets/firebullet.sprite");
49 bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
57 Bullet::update(float elapsed_time)
59 // remove bullet when it's offscreen
61 Sector::current()->camera->get_translation().x;
63 Sector::current()->camera->get_translation().y;
64 if (get_pos().x < scroll_x ||
65 get_pos().x > scroll_x + SCREEN_WIDTH ||
66 // get_pos().y < scroll_y ||
67 get_pos().y > scroll_y + SCREEN_HEIGHT ||
73 movement = physic.get_movement(elapsed_time);
77 Bullet::draw(DrawingContext& context)
79 sprite->draw(context, get_pos(), LAYER_OBJECTS);
83 Bullet::collision_solid(const CollisionHit& hit)
85 if(hit.top || hit.bottom) {
86 physic.set_velocity_y(-physic.get_velocity_y());
88 } else if(hit.left || hit.right) {
89 if(type == ICE_BONUS) {
90 physic.set_velocity_x(-physic.get_velocity_x());
98 Bullet::ricochet(GameObject& , const CollisionHit& hit)
100 collision_solid(hit);
104 Bullet::collision(GameObject& , const CollisionHit& )