-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcustom_classes.h
91 lines (69 loc) · 1.69 KB
/
custom_classes.h
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
#ifndef SCENE_H
#define SCENE_H
/* custom_classes.h:
*
* these are ad-hoc structures used by this specific game:
* - Stats, (of a ship)
* - Ship,
* - Bullet,
* - Scene (all data of a game, also the arena)
*
* (in class, this file was called "scene.h")
*
* Often, they inhert from general "PhysObjects" and add fields and/or
* add / redefine funcionalies. They use methods of their base class.
*
*/
#include <vector>
#include "phys_object.h"
#include "controller.h"
struct Stats{
float accRate;
float turnRate;
float fireRate; // bullets per seconds
float fireRange;
float fireSpeed;
};
struct Bullet : public PhysObject {
float timeToLive;
bool alive;
void renderPlaceHolder() const;
void doPhysStep();
void reset(){ alive = false; }
};
struct Ship: public PhysObject{
Stats stats;
ShipController controller;
void doPhysStep();
void renderPlaceHolder() const;
void render() const;
void setMaxVelAndAcc( float maxVel, float acc );
std::vector< Bullet > bullets;
float timeBeforeFiringAgain;
void spawnNewBullet();
Bullet& findUnusedBullet();
void fillBullet(Bullet& b) const;
void reset();
void die();
void respawn();
void setStatsAsFighter(); //
void setStatsAsTank();
bool alive;
double timeDead;
};
struct Scene{
float arenaRadius;
std::vector< Ship > ships;
vec3 randomPosInArena() const;
void initAsNewGame();
void render();
void doPhysStep();
bool isInside( vec3 p ) const;
vec3 pacmanWarp( vec3 p) const;
private:
void checkAllCollisions();
void renderFloor() const;
void cameraOnTwoObjects( const PhysObject& a, const PhysObject& b );
};
extern Scene scene; // a poor man's singleton (there is one, and everyone can use it)
#endif // SCENE_H