#include "moving_platform.h"
#include "turret.h"
#include "geometric_objects.h"
+#include "aimpoint.h"
std::mutex grand_mutex;
std::vector<gameobject*> objects;
projectile ice_balls;
-
+wall_block spawned_blocks("cube.obj", "projectile.jpg", glm::vec3(2, 2, 2));
fragment brick_fragments;
+
class target : public loaded_object, public block_object {
-public:
- target() : loaded_object("monkey.obj", "brick.jpg", glm::vec3(15.0f, 10.0f, 15.0f)) {
- collision_check = true;
- }
- void hit_index(size_t index){
- brick_fragments.create_burst(100, locations[index], 0.01f);
- locations.erase(locations.begin() + index);
- }
-
+ public:
+ target() : loaded_object("monkey.obj", "brick.jpg", glm::vec3(15.0f, 10.0f, 15.0f)) {
+ collision_check = true;
+ }
+ void hit_index(size_t index){
+ brick_fragments.create_burst(100, locations[index], 0.01f);
+ locations.erase(locations.begin() + index);
+ }
+
};
+ssize_t is_empty(glm::vec3 position, float distance = 0.2f){
+ for(gameobject* o : objects) {
+ ssize_t collide_index = o->collision_index(position, distance);
+ if(collide_index != -1)
+ return false;
+ }
+ return true;
+
+}
+
struct key_status {
int forward, backward, left, right;
};
fire();
if(button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS)
fire(true);
+ if(button == 2 && action == GLFW_PRESS){
+ // Spawn a block
+ glm::vec3 look_at_point = 2.0f * glm::vec3(roundf(player_position.x/2.0f), roundf(player_position.y/2.0f), roundf(player_position.z/2.0f)) ;
+ look_at_point.x += 2.0f * roundf(4.0f * cosf(player_elevation) * sinf(player_heading));
+ look_at_point.y += 2.0f * roundf(4.0f * sinf(player_elevation));
+ look_at_point.z += 2.0f * roundf(4.0f * cosf(player_elevation) * cosf(player_heading));
+ if(!is_empty(look_at_point, 0.0f)){
+ look_at_point = 2.0f * glm::vec3(roundf(player_position.x/2.0f), roundf(player_position.y/2.0f), roundf(player_position.z/2.0f)) ;
+ look_at_point.x += 2.0f * roundf(2.0f * cosf(player_elevation) * sinf(player_heading));
+ look_at_point.y += 2.0f * roundf(2.0f * sinf(player_elevation));
+ look_at_point.z += 2.0f * roundf(2.0f * cosf(player_elevation) * cosf(player_heading));
+ }
+ if(is_empty(look_at_point, 0.0f))
+ spawned_blocks.locations.push_back(look_at_point);
+ }
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods){
}
}
-ssize_t is_empty(glm::vec3 position, float distance){
- for(gameobject* o : objects) {
- ssize_t collide_index = o->collision_index(position, 0.2f);
- if(collide_index != -1)
- return false;
- }
- return true;
-
-}
-
int shutdown_engine = 0;
/* Must be called at a consistent rate */
void player_movement(){
while(!shutdown_engine){
-// grand_mutex.lock();
+ // grand_mutex.lock();
auto start = std::chrono::system_clock::now();
glm::vec3 step_to_point = player_position;
if(player_key_status.forward){
step_to_point += 0.05f * glm::vec3(-sinf(player_heading + M_PI/2), 0, -cosf(player_heading + M_PI/2));
}
for(gameobject* o : objects) {
- ssize_t collide_index = o->collision_index(step_to_point, 0.2f);
- if(collide_index != -1) {
- if(is_empty(glm::vec3(player_position.x, step_to_point.y, step_to_point.z), 0.2f)) {
- step_to_point.x = player_position.x;
- break;
- }
- else if(is_empty(glm::vec3(step_to_point.x, step_to_point.y, player_position.z), 0.2f)) {
- step_to_point.z = player_position.z;
- break;
- }
- else {
- step_to_point = player_position;
- break;
- }
-
-
- }
+ ssize_t collide_index = o->collision_index(step_to_point, 0.2f);
+ if(collide_index != -1) {
+ if(is_empty(glm::vec3(player_position.x, step_to_point.y, step_to_point.z), 0.2f)) {
+ step_to_point.x = player_position.x;
+ break;
+ }
+ else if(is_empty(glm::vec3(step_to_point.x, step_to_point.y, player_position.z), 0.2f)) {
+ step_to_point.z = player_position.z;
+ break;
+ }
+ else {
+ step_to_point = player_position;
+ break;
+ }
+
+
+ }
}
player_position = step_to_point;
player_position.y = floor_height + player_height;
}
}
-// grand_mutex.unlock();
+ // grand_mutex.unlock();
auto end = std::chrono::system_clock::now();
// double difference = std::chrono::duration_cast<std::chrono::milliseconds>(start - end).count();
// printf("Time difference: %lf\n", difference);
while(!shutdown_engine){
auto start_time = std::chrono::system_clock::now();
loop_time = std::chrono::duration_cast<std::chrono::microseconds>(start_time - last_call).count();
-
-// grand_mutex.lock();
+
+ // grand_mutex.lock();
if(player_platform){
glm::vec3 pltloc = player_platform->locations[player_platform_index];
float floor_height = pltloc.y + (player_platform->size.y / 2);
player_position.y = floor_height + player_height;
}
-// grand_mutex.unlock();
+ // grand_mutex.unlock();
for(gameobject* o : objects)
- o->move(); // move needs a parameter which indicates how long since we last called move (loop_time)
+ o->move(loop_time); // move needs a parameter which indicates how long since we last called move (loop_time)
auto end_time = std::chrono::system_clock::now();
int cpu_time = std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count();
last_call = start_time;
int sleep_time = 1000 - cpu_time;
-// printf("Loop time: %d Sleep time: %d CPU time: %d\n", loop_time, sleep_time, cpu_time);
+ // printf("Loop time: %d Sleep time: %d CPU time: %d\n", loop_time, sleep_time, cpu_time);
if(sleep_time > 100 )
std::this_thread::sleep_for(std::chrono::microseconds(sleep_time));
}
puts(RED(message).c_str());
else if(severity == GL_DEBUG_SEVERITY_MEDIUM)
puts(YELLOW(message).c_str());
-/* Only uncomment if you want a lot of messages */
-/*
- else
+ /* Only uncomment if you want a lot of messages */
+ /*
+ else
puts(message);
-*/
+ */
}
int main(int argc, char** argv) {
/* Level Loading (hardcoded at the moment) */
-
+
tile_floor fl;
objects.push_back(&ice_balls);
objects.push_back(&fl);
/*
- wall_block monster_box("cube.obj", "monster1.png", glm::vec3(10, 10, 10));
- monster_box.scale = 5.0;
- monster_box.locations.push_back(glm::vec3(53, -10, 50));
- objects.push_back(&monster_box);
- */
+ wall_block monster_box("cube.obj", "monster1.png", glm::vec3(10, 10, 10));
+ monster_box.scale = 5.0;
+ monster_box.locations.push_back(glm::vec3(53, -10, 50));
+ objects.push_back(&monster_box);
+ */
// What if it wasn't a cube?
wall_block bwb("cube.obj", "brick.jpg", glm::vec3(20, 20, 20));
p.addpanel(glm::vec3(10, -9.99, 450), glm::vec2(5, 5), glm::vec2(1, 1));
objects.push_back(&p);
+ aimpoint main_aimpoint;
+ objects.push_back(&main_aimpoint);
+
+ objects.push_back(&spawned_blocks);
+
/* Initialize game objects */
for(gameobject* o : objects){
if(o->init()){
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
-// grand_mutex.lock();
+ // grand_mutex.lock();
/* Where are we? A: player_position
* What are we looking at?
for(gameobject* o : objects)
o->draw(vp);
-// grand_mutex.unlock();
+ // grand_mutex.unlock();
glfwSwapBuffers(window);
}