8 #include "app/globals.h"
9 #include "special/sprite_manager.h"
10 #include "badguy/badguy.h"
12 static const float BULLET_XM = 300;
13 static const float BULLET_STARTING_YM = 0;
15 Bullet::Bullet(const Vector& pos, float xm, int dir, int kind_)
16 : kind(kind_), life_count(3), sprite(0)
21 float speed = dir == RIGHT ? BULLET_XM : -BULLET_XM;
22 physic.set_velocity_x(speed + xm);
23 physic.set_velocity_y(-BULLET_STARTING_YM);
25 if (kind == ICE_BULLET) {
26 life_count = 6; //ice-bullets get "extra lives" for bumping off walls
27 sprite = sprite_manager->create("icebullet");
28 } else if(kind == FIRE_BULLET) {
29 sprite = sprite_manager->create("firebullet");
39 Bullet::action(float elapsed_time)
41 if(kind == FIRE_BULLET) {
42 // @not completely framerate independant :-/
43 physic.set_velocity_y(physic.get_velocity_y() - 50 * elapsed_time);
45 if(physic.get_velocity_y() > 900)
46 physic.set_velocity_y(900);
47 else if(physic.get_velocity_y() < -900)
48 physic.set_velocity_y(-900);
51 Sector::current()->camera->get_translation().x;
53 Sector::current()->camera->get_translation().y;
54 if (get_pos().x < scroll_x ||
55 get_pos().x > scroll_x + screen->w ||
56 // get_pos().y < scroll_y ||
57 get_pos().y > scroll_y + screen->h ||
63 movement = physic.get_movement(elapsed_time);
67 Bullet::draw(DrawingContext& context)
69 sprite->draw(context, get_pos(), LAYER_OBJECTS);
73 Bullet::collision(GameObject& other, const CollisionHit& hit)
75 if(other.get_flags() & FLAG_SOLID) {
76 if(fabsf(hit.normal.y) > .5) { // roof or floor bump
77 physic.set_velocity_y(-physic.get_velocity_y());
79 } else { // bumped left or right
80 if(kind == FIRE_BULLET)
83 physic.set_velocity_x(-physic.get_velocity_x());
89 BadGuy* badguy = dynamic_cast<BadGuy*> (&other);