-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame_object.h
147 lines (122 loc) · 4.59 KB
/
game_object.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
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
#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <vector>
#include "texture.h"
#include "sprite_renderer.h"
#include "model.h"
#include "state_manager.h"
/*------------------------------------INTERFACES-----------------------------------------*/
class GameObject
{
public:
// Render state
Texture2D Tex;
// Draw sprite
GameObject(Texture2D sprite) : Tex(sprite) { }
virtual void Draw(StateManager &manager, SpriteRenderer &renderer, glm::mat4 projection, glm::mat4 view) = 0;
};
// Container object for holding all state relevant for a single
// game object entity. Each object in the game likely needs the
// minimal of state as described within GameObject.
class Game_Object3D
{
public:
// Object state
glm::vec3 Position, Size, Color, Rotation;
GLfloat Alpha;
// Constructor(s)
// Object3D();
Game_Object3D(glm::vec3 pos, glm::vec3 size, glm::vec3 color = glm::vec3(1.0f))
: Position(pos), Size(size), Color(color), Rotation(0), Alpha(1.0f) { }
};
/*------------------------------------MODEL CONTAINER-----------------------------------------*/
// Represents the different sides of a model
enum Side {
UP_SIDE,
DOWN_SIDE,
FRONT_SIDE,
BACK_SIDE,
LEFT_SIDE,
RIGHT_SIDE
};
// class regrouping property of a 3D model
class GameModel : public Game_Object3D
{
public:
// Object state
Model model;
// Constructor(s)
GameModel(std::string file, std::string name);
// Draw sprite
void Draw(StateManager &manager, Shader shader, glm::mat4 projection, glm::mat4 view);
void Update(GLfloat dt, GLfloat spin);
// Set model's position correctly :
// the given side of the model will be localised as to be at pos location if it is facing the orientation side_local
// Putting the model in its correct orientation for it to work will need to be done elsewhere.
void SetSide(GLfloat pos, Side side_local, Side side_model);
void SetSide(GLfloat pos, Side side_local) { SetSide(pos, side_local, side_local); }
};
/*----------------------------------------CUBE---------------------------------------------*/
class Object3D : public GameObject, public Game_Object3D
{
public:
// Constructor(s)
Object3D(glm::vec3 pos, glm::vec3 size, Texture2D sprite, glm::vec3 color = glm::vec3(1.0f));
// Draw sprite
virtual void Draw(StateManager &manager, SpriteRenderer &renderer, glm::mat4 projection = glm::mat4(), glm::mat4 view = glm::mat4());
};
/*----------------------------------TEXTURED-SQUARE-----------------------------------------*/
// Container of a character's sprite
enum State {
IDLE,
WALK,
BITE,
WHIP,
HURT,
JUMP,
DEAD
};
class Object2D : public GameObject
{
public:
// Object state
glm::vec2 Position, Size;
GLboolean Reversed;
glm::vec2 Sprite_size; //width and height of one sprite in the texture, in a 0-1 range
GLfloat Alpha, Animation_timer;
// Constructor(s)
Object2D(Texture2D sprite, glm::vec2 position);
Object2D(Texture2D sprite, glm::vec2 position, glm::vec2 size);
Object2D(Texture2D sprite, std::vector<GLuint> N_max, GLfloat size_factor = 1.0f, glm::vec2 position = glm::vec2(0));
// Draw sprite
virtual void Draw(StateManager &manager, SpriteRenderer &renderer, glm::mat4 projection = glm::mat4(), glm::mat4 view = glm::mat4());
void Update(GLfloat dt);
void SetState(State state);
GLboolean IsState(State state);
glm::vec3 ExchangeSprite(const Object2D &sprite2, const glm::vec3 &cam_pos);
private:
// column and line in the sprite sheet of the current displayed image
State Action; //line
GLdouble N_img; //column
std::vector<GLuint> N_max;// number of the images composing each animation (classed by line number)
GLboolean Sound_played;
void Animate(GLfloat dt);
};
/*----------------------------------COLORED-SQUARE-----------------------------------------*/
class Square
{
public:
// Object state
glm::vec2 Position, Size, Velocity;
GLboolean IsCircle;
glm::vec3 Color1, Color2;
Effect Effet;
// Constructor(s)
Square(glm::vec2 position, glm::vec2 size, glm::vec3 color1, glm::vec3 color2 = glm::vec3(0), Effect effect = NONE, glm::vec2 velocity = glm::vec2(0), GLboolean circle = GL_FALSE);
// Draw sprite
virtual void Draw(StateManager &manager, SpriteRenderer &renderer, glm::mat4 projection = glm::mat4(), glm::mat4 view = glm::mat4(), GLboolean border = GL_FALSE);
void Update(GLfloat dt);
};
#endif