File: managers.h

package info (click to toggle)
xgalaga%2B%2B 0.9-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 376 kB
  • sloc: cpp: 2,785; makefile: 242
file content (134 lines) | stat: -rw-r--r-- 3,472 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef MANAGERS_H
#define MANAGERS_H

#include "constants.h"
#include "explosion.h"
#include "sprites.h"
#include <limits>
#include <list>
#include <utility>
#include <vector>


// An aliens convoy is defined by the vessel, the number of
// vessels and the formation (that can be X-mirrored)
struct ConvoyData {
	const int wait;
	const char *const *const alien_xpm;
	const int convoy_size_pc;
	const RCoord *const arrival;
	const bool x_mirror;
	const bool split;

	int ConvoySize() const;
};


class BulletsManager {
	typedef std::list<Projectile*> BulletsCtn;
	BulletsCtn bullets_;
public:
	~BulletsManager();
	void Move();
	void Add(const Pix * pix, Coord pos, Coord speed);
	int DoCollisions(const Sprite & other, int max);
	int Nb() const { return bullets_.size(); }
};


class BonusManager {
	typedef std::list<Bonus*> BonusCtn;
	BonusCtn bonuses_;
public:
	~BonusManager();
	void Move();
	void Add(Coord pos, Bonus::bonus_t type);
	Bonus::bonus_t GetBonusCollision(const Sprite & other);
};


class ExplosionsManager {
	typedef std::list<Explosion*> ExplosionsCtn;
	ExplosionsCtn explosions_;
public:
	~ExplosionsManager();
	void Move();
	void Add(Coord pos, Coord speed, XColor color, int duration = 24);
};


// Aliens arrive in convoys. The AlienManager creates aliens according
// to convoys data and then move and destroy them if collision.
class AliensManager {
	static int bonus_wait_;

	BulletsManager *const bombs_manager_;
	BulletsManager *const bullets_manager_;
	BonusManager *const bonus_manager_;
	ExplosionsManager *const explosions_manager_;
	const int level_number_;
	const ConvoyData *const convoys_;
	const int nconvoys_;
	const int max_convoy_size_;
	int convoy_idx_;
	int convoy_alien_idx_;
	const int speed_;
	Coord base_cruise_;
	int base_cruise_speed_;
	enum creation_t { new_convoy, new_alien, new_attack };
	creation_t next_creation_;
	int next_creation_wait_;
	typedef std::list<Alien*> AliensCtn;
	AliensCtn aliens_;
public:
	AliensManager(BulletsManager * bombs_manager,
	              BulletsManager * bullets_manager,
	              BonusManager*, ExplosionsManager*,
	              int level_number, const ConvoyData * convoysdata,
	              int max_level);
	~AliensManager();
	void Move();
	void Fire() const;
	int  DoBulletsCollisions();
	bool Finished() const
		{ return next_creation_ == new_attack && aliens_.empty(); }
private:
	int GetMaxConvoySize() const;
	void Creation();
	void CreateBonusMaybe(Coord);
};


// The player ship is displayed by a pix and moves on the bottom of the window.
// It can fire bullets. It can collide with alien bullets (bombs) and bonuses.
// The shield is decremented by each collision.
class Player : public Sprite {
	Player(const Player &); // no copy
	Player & operator=(const Player &); // no copy

	BulletsManager *const bullets_manager_;
	BulletsManager *const bombs_manager_;
	BonusManager *const bonus_manager_;
	ExplosionsManager *const explosions_manager_;
	const int below_y_;
	int shield_;
	int speed_;
	int fire_wait_, fire_interval_;
	int multi_fire_;
public:
	Player(BulletsManager * bullets_manager, BulletsManager * bombs_manager,
	       BonusManager*, ExplosionsManager*, int below_y);
	void Move(int direction);
	void Fire();
	void DoBombsCollisions();
	void DoBonusCollisions();
	int  Shield() const { return shield_; }
	void ExtraFire();
	void ExtraMulti();
	void ExtraShield() { ++shield_; }
	void ExtraSpeed() { ++speed_; }
private:
	int  PosY() const;
};

#endif