#include "game.h" /* This is where implementations of misc. game objects goes */ /* At the moment, these have to be axis-aligned, like Minecraft */ ssize_t FloorPanel::is_inside(vec3 pos, float margin) { size_t highest_instance; float highest_height = -1000000; for(size_t i = 0; i < models.size(); i++){ mat4 m = models[i]; /* How close is the floor panel represented by m? */ vec3 size = vec3(m[0][0], m[1][1], m[2][2]); vec3 cmpos = vec3(m[3][0], m[3][1], m[3][2]); /* Is it inside? */ if(fabs(cmpos.x - pos.x) < size.x/2 + margin && fabs(cmpos.y - pos.y) < size.y/2 + margin && fabs(cmpos.z - pos.z) < size.z/2 + margin){ if(highest_height < (cmpos.y + size.y/2)){ highest_height = cmpos.y + size.y/2; highest_instance = i; } } } if(highest_height == -1000000) return -1; else return highest_instance; } float SolidObject::get_topbottom(size_t instance, bool bottom){ mat4 m = models[instance]; vec3 size = vec3(m[0][0], m[1][1], m[2][2]); vec3 cmpos = vec3(m[3][0], m[3][1], m[3][2]); if(bottom) return cmpos.y - size.y / 2.0f; else return cmpos.y + size.y / 2.0f; } void FloorPanel::trigger_action(size_t instance, int action){ switch(action){ case PLAYER_ON_OBJECT: g.on_count++; /* if(instance == 0) { printf("Triggered launch\n"); g.vertical_speed = 3.0f; } */ break; } } void VanishBlock::movement(float time){ for(size_t i = 0; i < models.size(); i++){ if(instance_countdowns[i] == 0){ models.erase(models.begin() + i); instance_countdowns.erase(instance_countdowns.begin() + i); } else if(instance_countdowns[i] > 0){ instance_countdowns[i]--; } } } void VanishBlock::trigger_action(size_t instance, int action){ switch(action){ case PLAYER_ON_OBJECT: if(instance_countdowns[instance] == -1) instance_countdowns[instance] = 100; break; } } void SlipperyBlock::trigger_action(size_t instance, int action){ switch(action){ case PLAYER_ON_OBJECT: g.player_position.x += 0.2; break; } } float SolidObject::get_top(size_t instance){ return get_topbottom(instance, false); } float SolidObject::get_bottom(size_t instance){ return get_topbottom(instance, true); }