}
-struct key_status {
- int forward, backward, left, right;
-};
-struct key_status player_key_status;
-
void fire(bool burst = false){
if(burst)
ice_balls.add_projectile(player_position, player_heading, player_elevation, 0.4f, 10000.0f, 1.0f, true);
look_at_point.y += 6.0f * sinf(player_elevation);
look_at_point.z += 6.0f * cosf(player_elevation) * cosf(player_heading);
for(gameobject* o : objects) {
- ssize_t collide_index = o->collision_index(look_at_point, 4.0f);
+ ssize_t collide_index = o->collision_index(look_at_point, 20.0f);
if(collide_index != -1)
o->activate(collide_index);
}
while(!shutdown_engine){
// 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.1f * glm::vec3(sinf(player_heading), 0, cosf(player_heading));
- }
- if(player_key_status.backward){
- step_to_point += 0.1f * glm::vec3(-sinf(player_heading), 0, -cosf(player_heading));
- }
- if(player_key_status.left){
- step_to_point += 0.05f * glm::vec3(sinf(player_heading + M_PI/2), 0, cosf(player_heading + M_PI/2));
- }
- if(player_key_status.right){
- 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;
- }
+ if(current_vehicle){
+ current_vehicle->vehicle_move();
+ } else {
+ glm::vec3 step_to_point = player_position;
+ if(player_key_status.forward){
+ step_to_point += 0.1f * glm::vec3(sinf(player_heading), 0, cosf(player_heading));
+ }
+ if(player_key_status.backward){
+ step_to_point += 0.1f * glm::vec3(-sinf(player_heading), 0, -cosf(player_heading));
+ }
+ if(player_key_status.left){
+ step_to_point += 0.05f * glm::vec3(sinf(player_heading + M_PI/2), 0, cosf(player_heading + M_PI/2));
+ }
+ if(player_key_status.right){
+ 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;
+ }
+
+ }
}
- }
- player_position = step_to_point;
+ player_position = step_to_point;
- if(player_platform){
- if(!player_platform->is_on_idx(player_position, player_platform_index, player_height))
- player_platform = 0;
- } else {
- float floor_height = 0;
- for(gameobject* o : objects) {
- ssize_t ppi = o->is_on(player_position, player_height);
- if(ppi != -1) {
- player_platform_index = ppi;
- player_platform = o;
- floor_height = player_platform->locations[player_platform_index].y + (player_platform->size.y / 2);
+ if(player_platform){
+ if(!player_platform->is_on_idx(player_position, player_platform_index, player_height))
+ player_platform = 0;
+ } else {
+ float floor_height = 0;
+ for(gameobject* o : objects) {
+ ssize_t ppi = o->is_on(player_position, player_height);
+ if(ppi != -1) {
+ player_platform_index = ppi;
+ player_platform = o;
+ floor_height = player_platform->locations[player_platform_index].y + (player_platform->size.y / 2);
+ player_fall_speed = 0;
+ player_position.y = floor_height + player_height;
+ }
+ }
+ if(player_position.y - player_height > floor_height) {
+ player_position.y += player_fall_speed;
+ player_fall_speed -= GRAVITY;
+ } else {
player_fall_speed = 0;
player_position.y = floor_height + player_height;
}
}
- if(player_position.y - player_height > floor_height) {
- player_position.y += player_fall_speed;
- player_fall_speed -= GRAVITY;
- } else {
- player_fall_speed = 0;
- player_position.y = floor_height + player_height;
- }
}
main_hud.lprintf(2, "Player Position: (%f, %f, %f)", player_position.x, player_position.y, player_position.z);
// grand_mutex.unlock();
bwb.locations.push_back(glm::vec3(-30, 0, 0));
objects.push_back(&bwb);
- t.locations.push_back(glm::vec3(100, -5, 200));
- t.locations.push_back(glm::vec3(-100, -5, 200));
- t.locations.push_back(glm::vec3(100, -5, 100));
- t.locations.push_back(glm::vec3(50, -5, 100));
+ t.add(glm::vec3(100, -5, 200));
+ t.add(glm::vec3(-100, -5, 200));
+ t.add(glm::vec3(100, -5, 100));
+ t.add(glm::vec3(50, -5, 100));
t.current_target = &targets;
t.current_projectile = &ice_balls;
objects.push_back(&t);
objects.push_back(&spawned_blocks);
+ flying_carpet fc;
+ fc.locations.push_back(glm::vec3(30, -5, 450));
+ objects.push_back(&fc);
+
/* Initialize game objects */
for(gameobject* o : objects){
if(o->init()){
return 1;
}
}
-
+
main_hud.set_text("Hello World\nThis is line two\nAnd line three!");
/* Start Other Threads */
std::thread animation_thread(animation);
std::thread collision_detection_thread(collision_detection);
std::thread display_fps([](){
- while(!shutdown_engine){
+ while(!shutdown_engine){
double loop_time = 1000.0 / loopcount;
main_hud.lprintf(1, "FPS: %4d Move: %lf", framecount, loop_time);
framecount = 0;
loopcount = 0;
std::this_thread::sleep_for(std::chrono::seconds(1));
- }
- });
+ }
+ });
glEnable(GL_DEPTH_TEST);