// $Id: starparticlesystem.h,v 1.4 2006/08/05 09:08:59 matthew Exp $ // Fish Supper // Copyright (C) 2006 Matthew Clarke // // 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 useful, // 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., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. #ifndef _STAR_PARTICLE_SYSTEM_H_ #define _STAR_PARTICLE_SYSTEM_H_ #include #include "SDL.h" #include "constants.h" #include "playdisplay.h" #include "enums.h" namespace FS { // FIXME: This class should be made more general so // that different types of particle system can be sub-classed // from it. class StarParticleSystem { private: static const int MAX_STARS = 20; // launch a new star every n ms: static const int LAUNCH_INTERVAL = 30; static const int NUM_FRAMES = 11; static const int DURATION = 80; static const int STAR_WIDTH = 30; static const int STAR_HEIGHT = 30; // A particle is basically a lightweight sprite. // Unlike a usual sprite, we don't need to worry about // collisions. In the case of 'star' particles, no need // to track movement either. struct StarParticle { int x; int y; int start_time; int current_frame; bool active; SDL_Rect isr; // i.e. image section rect! }; // struct StarParticle bool active; bool stopped; int start_time; int num_stars; SDL_Rect dest_rect; SDL_Rect erase_rect; SDL_Rect update_rect; int min_x, max_x, min_y, max_y; StarParticle my_stars[MAX_STARS]; void launch_new_star(int t, SDL_Rect box); void draw_stars(PlayDisplay * pd); // Helper functions // FIXME: Put these somewhere all classes can use them int min(int a, int b) const { return ((a < b) ? a : b); } int max(int a, int b) const { return ((a > b) ? a : b); } public: StarParticleSystem(); ~StarParticleSystem(); void activate(int t, SDL_Rect box); // Calling stop() means the system won't launch any new // particles but it will continue to update existing ones // until they've all died out. void stop(int t); // Is this system in use and therefore in need of updates? bool is_active() const { return active; } bool is_stopped() const { return stopped; } void update(int time_passed, SDL_Rect box, PlayDisplay * pd); }; // class StarParticleSystem } // namespace FS #endif