/* movers.h - some sprites, including the player ship Copyright (C) 2006 Mark boyd This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be fun to play, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef MOVERS_H #define MOVERS_H #include #include "arena.h" /*for arena_t*/ #include "etc.h" struct SDL_Surface; /* Mover = Sprite. Anything which is not scenery. This includes turrets, which don't move! move: Duh. do_stuff: Override if you need to do something "interesting" (e.g. shooting at the player) does_arena_colliions, does_collisions: Override these if you want to handle collisions Please be selective here and only return true for potential collisions which you actually want to handle- if you can return false then a slow pixel-by-pixel test is avoided notify_collision: here is where you should do something in response to a collision is_stuck: a vile hack. "stuck" movers ignore forces roughly_untractor: called when a tractor beam from this mover is destroyed (usually because whatever was on the other end has just died) */ class mover { public: float m_mass; float m_x,m_y; float m_dx,m_dy; //These are in pixels/second virtual ~mover(){}; virtual void move(float t){m_x+=t*m_dx;m_y+=t*m_dy;}; virtual void do_stuff(float /*time_interval*/){} virtual SDL_Surface* pic() const=0; virtual bool does_arena_collisions() const {return false;} virtual bool does_collisions(mover *) const {return false;} virtual void notify_collision(arena_t hit){} virtual void notify_collision(mover *other){} virtual bool is_stuck() const {return false;} virtual void roughly_untractor(){} mover(){m_x=0;m_y=0;m_dx=0;m_dy=0;m_is_dead = false;m_mass=0;} //convenience fns? void teleport(float x, float y){m_x=x;m_y=y;} void teleport_centre(float x, float y); float x_centre() const; float y_centre() const; void die() {m_is_dead = true;} bool is_dead() {return m_is_dead;} private: bool m_is_dead; }; //The player's "avatar". class ship : public mover { public: ship(); void do_stuff(float time_interval); SDL_Surface* pic() const; bool does_collisions(mover *m) const; bool does_arena_collisions() const {return true;} void notify_collision(arena_t); void notify_collision(mover *); void take_hit(int damage); private: void roughly_untractor(){m_tractor_on=false;} void move(float t); void fire_weapons(); float m_angle; SDL_Surface *m_pics[32]; int m_pic_index; bool m_tractor_on; int m_shop_timeout; float m_last_interval; //ugly hack for colisions }; //The vital macguffin which needs to be picked up, carried around, and dropped on things class ball:public mover { public: ball(); ~ball(); SDL_Surface* pic() const{return m_pic;} bool is_stuck() const {return m_stuck;} void stick() {m_stuck=true;m_dx=0;m_dy=0;} void unstick() {m_stuck=false;} bool does_arena_collisions() const {return true;} private: SDL_Surface* m_pic; bool m_stuck; }; typedef void detonation_fn_t(mover *, mover *); typedef void expiration_fn_t(mover *); //Projectile fired by the player class shot:public mover { public: shot(const std::string &pic_name, float li_ex, detonation_fn_t *det_fn=0, expiration_fn_t *exp_fn=0); ~shot(); SDL_Surface* pic() const{return m_pic;} void do_stuff(float time_interval); bool does_collisions(mover *m) const; bool does_arena_collisions() const {return true;} void notify_collision(arena_t); void notify_collision(mover *m); std::string pic_name() const; private: std::string m_pic_name; detonation_fn_t *m_det_fn; expiration_fn_t *m_exp_fn; SDL_Surface* m_pic; float m_life_expectancy; }; //Usually dropped by slain enemies class coin:public mover { public: coin(); SDL_Surface* pic() const{return m_pic;} void do_stuff(float time_interval); bool does_collisions(mover *m) const; void notify_collision(mover *m); private: SDL_Surface* m_pic; int m_bounces; }; class recking_ball:public mover { public: recking_ball(); SDL_Surface* pic() const{return m_pic;} bool does_collisions(mover *m) const; bool does_arena_collisions() const {return true;} void notify_collision(arena_t); void notify_collision(mover *m); private: SDL_Surface* m_pic; }; #endif