| 1 |
#ifndef _CPARTICLE_ |
| 2 |
#define _CPARTICLE_ |
| 3 |
|
| 4 |
#include <list> |
| 5 |
#include "CRect.h" |
| 6 |
#include "CVector.h" |
| 7 |
#include "CSurface.h" |
| 8 |
#include "CSequencedEvent.h" |
| 9 |
#include "CTimer.h" |
| 10 |
|
| 11 |
//! Base class for things that have a position and velocity |
| 12 |
class CParticle |
| 13 |
{ |
| 14 |
public: |
| 15 |
enum BoundaryInfo { |
| 16 |
OUTSIDE_LOW = -1, |
| 17 |
INSIDE = 0, |
| 18 |
OUTSIDE_HIGH = 1 |
| 19 |
}; |
| 20 |
|
| 21 |
CParticle(CVector v, CVector pos); |
| 22 |
CParticle(CVector v, CVector pos, const CRect &r); |
| 23 |
CParticle(const CParticle &p); |
| 24 |
|
| 25 |
virtual ~CParticle(); |
| 26 |
|
| 27 |
virtual void update(); |
| 28 |
virtual void draw(CSurface &surface) = 0; |
| 29 |
virtual void clear(); |
| 30 |
|
| 31 |
BoundaryInfo inBoundaryHoriz(); |
| 32 |
virtual BoundaryInfo inBoundaryHoriz(double x); |
| 33 |
BoundaryInfo inBoundaryVert(); |
| 34 |
virtual BoundaryInfo inBoundaryVert(double y); |
| 35 |
void stayInBoundary(); |
| 36 |
|
| 37 |
void setVelocity(CVector vel) { velocity = vel; } |
| 38 |
void changeVelocity(double x, double y) { velocity = CVector(velocity.getX() + x, velocity.getY() + y); } |
| 39 |
void setPos(CVector pos); |
| 40 |
void setPos(double x, double y); |
| 41 |
void setPosRel(double x, double y); |
| 42 |
void setRect(CRect box) { CParticle::box = box; } |
| 43 |
CRect getRect() { return box; } |
| 44 |
void appendEvent(CSequencedEvent* e); |
| 45 |
void appendBehavior(CSequencedEvent* e); |
| 46 |
void prependEvent(CSequencedEvent* e); |
| 47 |
bool hasEvent() { return events.size() > 0; } |
| 48 |
void removeEvent(CSequencedEvent *e) { events.remove(e); } |
| 49 |
void move(double x, double y) { pos.addX(x); pos.addY(y); } |
| 50 |
bool isAlive() { return !dead; } //! Is this particle alive? |
| 51 |
|
| 52 |
double getX() { return pos.getX(); } |
| 53 |
double getY() { return pos.getY(); } |
| 54 |
CVector getVel() { return velocity; } |
| 55 |
CVector getPos() { return pos; } |
| 56 |
|
| 57 |
protected: |
| 58 |
CVector velocity; //! Vector that describes the particle's motion (in pixels per second) |
| 59 |
CVector pos; //! Vector that describes the particle's location (origin at top-left of screen) |
| 60 |
bool moving; //! If true, the particle is moving (ie its velocity is applied every frame. |
| 61 |
CTimer timer; //! timer object to make framerate-independent movement possible |
| 62 |
CRect box; //! Particle will stay within this box |
| 63 |
CSequencedEvent::Container events; //! List holding events to execute on this particle |
| 64 |
CSequencedEvent::Container behaviors; //! List holding behaviors to execute on this particle provided that no events are non-concurrent |
| 65 |
|
| 66 |
private: |
| 67 |
bool dead; //! particle is dead, should be deleted |
| 68 |
}; |
| 69 |
|
| 70 |
#endif |