]> isoptera.lcsc.edu Git - engine26/.git/commitdiff
Adjusted get_random in exploding target to support variable RAND_MAX, reordered proje...
authorSeth Long <sslong@lcsc.edu>
Thu, 5 Nov 2026 19:25:08 +0000 (11:25 -0800)
committerSeth Long <sslong@lcsc.edu>
Thu, 5 Nov 2026 19:25:08 +0000 (11:25 -0800)
explodingtarget.h
main.cpp
projectile.h

index ad8a566d2e50a1ad84f483c6720f51f078edb9b1..b36601ddf8e8993f8ad4ef3e6a0d58180c0ea2c6 100644 (file)
@@ -4,7 +4,7 @@
 class ExplodingTarget : public FloorPanel {
 public:
        float get_random(){
-               return ((rand() % 2000000) - 1000000.0f) / 500000.0f;
+               return 3.0 * (1.0f - 2.0f * (float)rand() / (float)RAND_MAX);
        }
 
        void report_collision(GameObject *other, size_t other_instance, size_t our_instance) override {
index bd5c12c49bb5f5cabdb6ea120749ae1df40ce9e3..05d515f0b23dd3d7dbcd272283535a4873b31d7d 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -234,7 +234,8 @@ void movement_function() {
                double sleep_seconds = 0.001 - (end_time - start_time);
                unsigned long sleep_microseconds = sleep_seconds * 1000000.0;
 
-               this_thread::sleep_for(chrono::microseconds(sleep_microseconds));       
+// Windows can sleep for a minimum of about 15ms by this method, it seems
+//             this_thread::sleep_for(chrono::microseconds(sleep_microseconds));       
 
        }
 }
index 907c6620bcf465d8588c36c75ffa082fd5853bb7..341740023ae20216f27fb59d99e5099aa2fa2105 100644 (file)
@@ -12,11 +12,11 @@ public:
                moving = true;
        };
        void add_location_size(vec3 start, vec3 vel){
-               models.push_back(translate(mat4(1.0), start));
-               models[models.size() - 1] = scale(models[models.size() - 1], vec3(proj_size, proj_size, proj_size));
                velocities.push_back(vel * 0.1f);
                times_to_live.push_back(2000);
                specials.push_back(0);
+               models.push_back(translate(mat4(1.0), start));
+               models[models.size() - 1] = scale(models[models.size() - 1], vec3(proj_size, proj_size, proj_size));
        }
        void add_location_size(){
                /* Defaults to "launched by player" */
@@ -28,13 +28,14 @@ public:
        }
        void movement(float time) {
                for(size_t i = 0; i < models.size(); i++) {
-                       models[i] = translate(models[i], velocities[i]);
+                       models[i] = translate(models[i], velocities[i] * time);
                        times_to_live[i] -= time;
                        if(times_to_live[i] < 0){
                                models.erase(models.begin() + i);
                                velocities.erase(velocities.begin() + i);
                                times_to_live.erase(times_to_live.begin() + i);
                                specials.erase(specials.begin() + i);
+                               i--;
                        }
                }
        }