]> isoptera.lcsc.edu Git - example_engine/.git/commitdiff
Updates to make the turrets work right and rotate
author= <=>
Mon, 21 Oct 2024 23:29:27 +0000 (16:29 -0700)
committer= <=>
Mon, 21 Oct 2024 23:29:27 +0000 (16:29 -0700)
Makefile
activation_area.h
baseclass.cpp
game.h
helpers.cpp
main.cpp
projectiles.h
turret.h

index 8b95cc60e7d43c6be233c1cb1755b8f3aa5e185e..a962bbf071e3f22271539f3e0a4675c3662edeb5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ all: ${OBJS}
        ${CXX} ${OBJS}  ${LDFLAGS}
 
 clean:
-       rm a.out ${OBJS}
+       rm -f a.out ${OBJS}
 
 test:  all
        ./a.out
index 1ba4414fe9bfd86171e30076318343eca10c972b..d969abdd3333ee6b5c2b5dc5235a3ab450399d36 100644 (file)
@@ -41,10 +41,9 @@ class activation_area : public gameobject {
                                                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++){
index dd43f6d9c56cb4b4537ea5cc4142140812123f1c..67a3973404c967a3ecad03d513e1e7deed842779 100644 (file)
@@ -30,8 +30,7 @@ int loaded_object::init() {
        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());
@@ -41,6 +40,12 @@ void loaded_object::draw(glm::mat4 vp) {
                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);
diff --git a/game.h b/game.h
index 1deac74770644d64a009f4bcb44f9f5b431ffa40..05c3e36bbdd232b698f02669aed4f6b20babef02 100644 (file)
--- a/game.h
+++ b/game.h
@@ -67,6 +67,7 @@ public:
                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;
 };
 
index 3a0595c2b6fdb79138618831074cf8b800009213..36c5882d64fbaab72b22c77ae8310bd4574f730e 100644 (file)
@@ -27,7 +27,7 @@ void free_helpers() {
 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) {
index 3a37ea088fc80a03a03a3f3f0429040a797ade24..e95fa3da51e417ab5c71d357e2be92d0b661014e 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -76,7 +76,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
        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;
@@ -331,13 +331,15 @@ int main(int argc, char** argv) {
        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));
@@ -346,7 +348,8 @@ int main(int argc, char** argv) {
        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);
index 045c51cefceb1d80531e60e8f08e0e56ac31c591..f838cb6524b2d42c602eba5561c916e6c369bdf1 100644 (file)
@@ -60,6 +60,7 @@ public:
        }
        void hit_index(size_t index) override {
                directions[index] = glm::vec3(0, 0, 0);
+               lifetimes[index] = 0.0f; // Delegate removal to move()
        } 
 };
 
index 772d45b58f54ba63c0c99628c9b195eea00db05c..53e7c423ce58c6ac736d22b792c2813522cfdfdc 100644 (file)
--- a/turret.h
+++ b/turret.h
@@ -7,28 +7,55 @@ public:
        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;
        }
 };
+
+