${CXX} ${OBJS} ${LDFLAGS}
clean:
- rm a.out ${OBJS}
+ rm -f a.out ${OBJS}
test: all
./a.out
callbacks[i]();
types[i] = 101;
}
- return i;
}
}
- return -1;
+ return -1; // Don't block movement
}
void move(){
for(size_t i = 0; i < types.size(); i++){
return 0;
}
-void loaded_object::draw(glm::mat4 vp) {
- glUseProgram(program);
+std::vector<glm::mat4> loaded_object::create_models(glm::mat4 vp){
std::vector<glm::mat4> models;
data_mutex.lock();
models.reserve(locations.size());
models.push_back(new_model);
}
data_mutex.unlock();
+ return models;
+}
+
+void loaded_object::draw(glm::mat4 vp) {
+ glUseProgram(program);
+ std::vector<glm::mat4> models = create_models(vp);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, models_buffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, models.size() * sizeof(glm::mat4), models.data(), GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, models_buffer);
loaded_object(const char* of, const char* tf, glm::vec3 s) : objectfile(of), texturefile(tf) { size = s; }
int init() override ;
+ virtual std::vector<glm::mat4> create_models(glm::mat4 vp);
void draw(glm::mat4 vp) override;
};
float randvel(float speed){
long min = -100;
long max = 100;
- return speed * (min + random() % (max + 1 - min));
+ return speed * (min + rand() % (max + 1 - min));
}
GLuint make_shader(const char* filename, GLenum shaderType) {
if(GLFW_KEY_D == key)
player_key_status.right = action;
if(GLFW_KEY_SPACE == key && 1 == action){
- if(player_platform){
+ if(player_platform || player_position.y < 0.1f + player_height){
player_fall_speed = 0.04f;
player_position.y += 1.0f;
player_platform = 0;
activation_area target_spawning;
target_spawning.size = glm::vec3(10, 10, 10);
target_spawning.add_area(glm::vec3(10, 0, 10), bob, 1);
- target_spawning.add_area(glm::vec3(90, 5, 300), activate_turret, 2);
+ target_spawning.add_area(glm::vec3(100, 5, 300), activate_turret, 2);
objects.push_back(&target_spawning);
+ /*
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(90, -5, 300 ));
objects.push_back(&monster_box);
+ */
// What if it wasn't a cube?
wall_block bwb("cube.obj", "brick.jpg", glm::vec3(20, 20, 20));
bwb.locations.push_back(glm::vec3(-30, 0, 0));
objects.push_back(&bwb);
- t.locations.push_back(glm::vec3(100, 0, 300));
+ t.locations.push_back(glm::vec3(100, -5, 300));
+ t.locations.push_back(glm::vec3(-100, -5, 300));
t.current_target = &targets;
t.current_projectile = &ice_balls;
objects.push_back(&t);
}
void hit_index(size_t index) override {
directions[index] = glm::vec3(0, 0, 0);
+ lifetimes[index] = 0.0f; // Delegate removal to move()
}
};
gameobject *current_target; // Might be nice if this was a list
projectile *current_projectile;
int countdown = 0;
+ float rotation = 0;
bool active = false;
-
- turret() : loaded_object("turret.obj", "turret.png", glm::vec3(1, 1, 1)) {}
+
+ turret() : loaded_object("cube.obj", "monster1.png", glm::vec3(5, 5, 5)) {
+ scale = 5;
+ }
void move() {
-/* At some rate (every so many calls to this function)
- * Pick a target (How do we know what targets we have?)
- * Launch a projectile at it (How do we launch a projectile from here?)
- */
+ /* At some rate (every so many calls to this function)
+ * Pick a target (How do we know what targets we have?)
+ * Launch a projectile at it (How do we launch a projectile from here?)
+ */
if(!active)
return;
if(countdown > 0){
countdown--;
return;
}
- countdown = 300;
+ countdown = 314;
if(!current_target->locations.size())
return;
glm::vec3 target_location = current_target->locations[target_idx];
- current_projectile->add_projectile(locations[0], glm::normalize(target_location - locations[0]), 10000);
- target_idx++;
- if(target_idx >= current_target->locations.size())
- target_idx = 0;
+ for(auto l : locations){
+ current_projectile->add_projectile(l, 0.2f * glm::normalize(target_location - l), 100000);
+ target_idx++;
+ if(target_idx >= current_target->locations.size())
+ target_idx = 0;
+ }
+ }
+
+ void animate(){
+ if(active)
+ rotation += 0.01;
+ }
+
+ std::vector<glm::mat4> create_models(glm::mat4 vp) override {
+ std::vector<glm::mat4> models;
+ data_mutex.lock();
+ models.reserve(locations.size());
+ for(glm::vec3 l : locations){
+ printf("create_models loop in turret\n");
+ glm::mat4 new_model = glm::mat4(1.0f);
+ new_model = translate(new_model, l);
+ new_model = rotate(new_model, rotation, glm::vec3(0, 1, 0));
+ models.push_back(new_model);
+ }
+ data_mutex.unlock();
+ return models;
}
};
+
+