forked from ixchow/15-466-f18-base0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.hpp
117 lines (91 loc) · 3.26 KB
/
Game.hpp
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
#pragma once
#include "GL.hpp"
#include <SDL.h>
#include <SDL_audio.h>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <vector>
// The 'Game' struct holds all of the game-relevant state,
// and is called by the main loop.
struct Game {
//Game creates OpenGL resources (i.e. vertex buffer objects) in its
//constructor and frees them in its destructor.
Game();
~Game();
//handle_event is called when new mouse or keyboard events are received:
// (note that this might be many times per frame or never)
//The function should return 'true' if it handled the event.
bool handle_event(SDL_Event const &evt, glm::uvec2 window_size);
//update is called at the start of a new frame, after events are handled:
void update(float elapsed, uint32_t num_frames);
//draw is called after update:
void draw(glm::uvec2 drawable_size);
//------- opengl resources -------
//shader program that draws lit objects with vertex colors:
struct {
GLuint program = -1U; //program object
//uniform locations:
GLuint object_to_clip_mat4 = -1U;
GLuint object_to_light_mat4x3 = -1U;
GLuint normal_to_light_mat3 = -1U;
GLuint sun_direction_vec3 = -1U;
GLuint sun_color_vec3 = -1U;
GLuint sky_direction_vec3 = -1U;
GLuint sky_color_vec3 = -1U;
//attribute locations:
GLuint Position_vec4 = -1U;
GLuint Normal_vec3 = -1U;
GLuint Color_vec4 = -1U;
} simple_shading;
//mesh data, stored in a vertex buffer:
GLuint meshes_vbo = -1U; //vertex buffer holding mesh data
//The location of each mesh in the meshes vertex buffer:
struct Mesh {
GLint first = 0;
GLsizei count = 0;
};
Mesh background_mesh;
Mesh sat_mesh;
Mesh asteroid_mesh;
Mesh junk_mesh;
Mesh health_bar_win_mesh;
Mesh health_bar_foreground_mesh;
GLuint meshes_for_simple_shading_vao = -1U; //vertex array object that describes how to connect the meshes_vbo to the simple_shading_program
//------- game state -------
struct Transform {
glm::quat rotation;
glm::quat ang_vel;
glm::vec3 position;
glm::vec3 lin_vel;
};
float fuel = 0.6f;
float fuel_burn_increment = 0.0005f;
float fuel_asteroid_increment = 0.03f;
uint32_t asteroid_spawn_interval = 800;
uint32_t junk_spawn_interval = 400;
float asteroid_capture_distance = 0.07f;
float collision_min_distance = 0.1f;
glm::vec2 frame_max = glm::vec2(0.85f, 0.5f);
glm::vec2 frame_min = glm::vec2(-0.85f, -0.5f);
struct {
bool yaw_left = false;
bool yaw_right = false;
bool trans_left = false;
bool trans_right = false;
bool trans_fwd = false;
bool trans_back = false;
bool grab = false;
} controls;
struct FlyingObject {
Transform transform;
bool active;
};
FlyingObject sat {
{ glm::angleAxis(0.0f, glm::vec3(1.0f, 0.0f, 0.0f)), // start pointing upwards
glm::quat(1.0f, 0.0f, 0.0f, 0.0f), // not rotating
glm::vec3(0.0f), // at the origin
glm::vec3(0.0f)}, // stationary
true};
std::vector<FlyingObject> asteroids;
std::vector<FlyingObject> junks;
};