4 // Copyright (C) 2005 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
24 #include "resources.hpp"
27 #include "sprite/sprite_manager.hpp"
28 #include "badguy/badguy.hpp"
31 static const float BULLET_XM = 300;
32 static const float BULLET_STARTING_YM = 0;
34 Bullet::Bullet(const Vector& pos, float xm, int dir, int kind_)
35 : kind(kind_), life_count(3), sprite(0)
40 float speed = dir == RIGHT ? BULLET_XM : -BULLET_XM;
41 physic.set_velocity_x(speed + xm);
42 physic.set_velocity_y(-BULLET_STARTING_YM);
44 if (kind == ICE_BULLET) {
45 life_count = 6; //ice-bullets get "extra lives" for bumping off walls
46 sprite = sprite_manager->create("icebullet");
47 } else if(kind == FIRE_BULLET) {
48 sprite = sprite_manager->create("firebullet");
58 Bullet::update(float elapsed_time)
60 if(kind == FIRE_BULLET) {
61 // @not completely framerate independant :-/
62 physic.set_velocity_y(physic.get_velocity_y() - 50 * elapsed_time);
64 if(physic.get_velocity_y() > 900)
65 physic.set_velocity_y(900);
66 else if(physic.get_velocity_y() < -900)
67 physic.set_velocity_y(-900);
70 Sector::current()->camera->get_translation().x;
72 Sector::current()->camera->get_translation().y;
73 if (get_pos().x < scroll_x ||
74 get_pos().x > scroll_x + SCREEN_WIDTH ||
75 // get_pos().y < scroll_y ||
76 get_pos().y > scroll_y + SCREEN_HEIGHT ||
82 movement = physic.get_movement(elapsed_time);
86 Bullet::draw(DrawingContext& context)
88 sprite->draw(context, get_pos(), LAYER_OBJECTS);
92 Bullet::collision(GameObject& other, const CollisionHit& hit)
94 if(other.get_flags() & FLAG_SOLID) {
95 if(fabsf(hit.normal.y) > .5) { // roof or floor bump
96 physic.set_velocity_y(-physic.get_velocity_y());
98 } else { // bumped left or right
99 if(kind == FIRE_BULLET)
102 physic.set_velocity_x(-physic.get_velocity_x());
108 BadGuy* badguy = dynamic_cast<BadGuy*> (&other);