summaryrefslogtreecommitdiff
path: root/enginecore.h
blob: 5ea49ae34f218f97401b11b369ecc989f43513cf (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#ifndef ENGINECORE_H
#define ENGINECORE_H

#include "util.h"
#include <SDL/SDL_rotozoom.h>
#include <SDL/SDL_mixer.h>
#include <fstream>
#include <list>
#include <algorithm>

using namespace std;

//a drawable object featering an image and a position
class DObject
{
protected:
	SDL_Surface* image;
public:
	double x;
	double y;	
	
	DObject();
	DObject(string filename, double newx, double newy);
	DObject(SDL_Surface* newImage, double newx, double newy);
	DObject(const DObject &o);
	virtual ~DObject();
	virtual void draw(SDL_Surface* screen);	
};

bool ooB(const DObject* o, SDL_Surface* screen);

double armorF(double damage, double armor);

class Levelable
{
protected:
	double exp;
	int level;
public:
	double next;
	double lin;
	double quad;
	double cube;
	
	Levelable();
	
	int addExp(double moreExp);
	int getLevel();
	double getExp();
	double* getExpPointer();
};

class Projectile: public DObject
{
public:
	Projectile(SDL_Surface* newimage, double newx, double newy, double newdamage, double newcollisionsize, double newxSpeed, double newySpeed);
	Projectile(const Projectile& P);
	Projectile(string filename,vector<Mix_Chunk*>& sounds);
	virtual ~Projectile(){};
	double damage;
	double armorPiercing;
	double collisionSize;
	double xSpeed;
	double ySpeed;
	
	void frame(double time);
	void rotateAccordingly();
};

class Item: public DObject
{
public:
	double cost;
	bool sellable;
	Item(const Item& item);
	Item(const DObject& dObject);
	Item(){};
	SDL_Surface* getImage();
};

class Weapon: public Item
{
protected:
	vector<double> startTimer;
	vector<Projectile*> prototypes;
public:
	bool playSound;
	vector<vector<Mix_Chunk*> > sounds;
	bool active;
	string name;
	double energyUsage;
	vector<double> cooldown;
	vector<double> currentTimer;
	Weapon(const Weapon& w);
	Weapon(string filename);
	~Weapon();
	vector<Projectile*> frame(double time);
	void mirror();
	double getDPS() const;
	double getDPE() const;
};


class Upgradeable
{
protected:
	double value;
public:
	string name;
	double cost;
	int level;
	int maxLevel;
	void setValue(double nvalue);
	double getValue() const;
	Upgradeable();
	Upgradeable(double d);
	operator double() const;
	Upgradeable& operator=(const double& d);
	void upgrade();
	void save(ofstream& o);
	void load(ifstream& i);
};

ifstream& operator>>(ifstream& ins, Upgradeable& u);

class Ship: public DObject
{
public:
	Ship(string filename,int x, int y);
	Ship(){};
	Ship(const Ship& s);
	virtual ~Ship();
	string name;
	double hp;
	Upgradeable maxhp;
	Upgradeable armor;
	Upgradeable moveSpeed;
	double collisionSize;
	vector<Weapon*> weapons;
	vector<pair<int, int> > slotPositions;
	int hit(const Projectile& P);
//	void draw(SDL_Surface* screen);
	virtual vector<Projectile*> frame(double time);
};

class EnemyShip: public Ship
{
public:
	vector<pair<double, double> > path;
	double gold;
	double exp;
	double score;
	unsigned int current;
	EnemyShip(const EnemyShip& s);
	EnemyShip(string filename);
	vector<Projectile*> frame(double time);
	void assignValue();
};

class UserShip: public Ship
{
public:
	SDL_Surface* getImage();
	double cost;
	double energy;
	Upgradeable maxEnergy;
	Upgradeable energyProduction;
	Upgradeable handling;
	double xSpeed;
	double ySpeed;
	int weaponSlots;
	vector<double> maxSize;
	int right;
	int down;
	int shooting;
	
	UserShip(string filename);
	
	void draw(SDL_Surface* screen);
	vector<Upgradeable*> getUpgradeables();
	void reset();
	
	vector<Projectile*> frame(double time, SDL_Surface* screen);
};

double estimateValue(const Weapon& w);
double estimateValue(const UserShip& s);


#endif