9 #include "app/globals.h"
10 #include "special/sprite_manager.h"
11 #include "badguy/badguy.h"
13 static const float BULLET_XM = 300;
14 static const float BULLET_STARTING_YM = 0;
16 Bullet::Bullet(const Vector& pos, float xm, int dir, int kind_)
17 : kind(kind_), life_count(3), sprite(0)
22 float speed = dir == RIGHT ? BULLET_XM : -BULLET_XM;
23 physic.set_velocity_x(speed + xm);
24 physic.set_velocity_y(-BULLET_STARTING_YM);
26 if (kind == ICE_BULLET) {
27 life_count = 6; //ice-bullets get "extra lives" for bumping off walls
28 sprite = sprite_manager->create("icebullet");
29 } else if(kind == FIRE_BULLET) {
30 sprite = sprite_manager->create("firebullet");
40 Bullet::action(float elapsed_time)
42 if(kind == FIRE_BULLET) {
43 // @not completely framerate independant :-/
44 physic.set_velocity_y(physic.get_velocity_y() - 50 * elapsed_time);
46 if(physic.get_velocity_y() > 900)
47 physic.set_velocity_y(900);
48 else if(physic.get_velocity_y() < -900)
49 physic.set_velocity_y(-900);
52 Sector::current()->camera->get_translation().x;
54 Sector::current()->camera->get_translation().y;
55 if (get_pos().x < scroll_x ||
56 get_pos().x > scroll_x + screen->w ||
57 // get_pos().y < scroll_y ||
58 get_pos().y > scroll_y + screen->h ||
64 movement = physic.get_movement(elapsed_time);
68 Bullet::draw(DrawingContext& context)
70 sprite->draw(context, get_pos(), LAYER_OBJECTS);
74 Bullet::collision(GameObject& other, const CollisionHit& hit)
76 if(other.get_flags() & FLAG_SOLID) {
77 if(fabsf(hit.normal.y) > .5) { // roof or floor bump
78 physic.set_velocity_y(-physic.get_velocity_y());
80 } else { // bumped left or right
81 if(kind == FIRE_BULLET)
84 physic.set_velocity_x(-physic.get_velocity_x());
90 BadGuy* badguy = dynamic_cast<BadGuy*> (&other);