more bad guy physics improvements
authorTobias Gläßer <tobi.web@gmx.de>
Thu, 19 Feb 2004 22:02:41 +0000 (22:02 +0000)
committerTobias Gläßer <tobi.web@gmx.de>
Thu, 19 Feb 2004 22:02:41 +0000 (22:02 +0000)
SVN-Revision: 131

src/badguy.c
src/physic.c
src/physic.h

index fa20790..7f6f28e 100644 (file)
@@ -90,14 +90,19 @@ void badguy_action(bad_guy_type* pbad)
                     }
                 }
 
             /* Fall if we get off the ground: */
+ /* Fall if we get off the ground: */
 
               if (pbad->dying != FALLING)
                 {
-                  if (!issolid(pbad->base.x, pbad->base.y + 32) &&
-                      pbad->base.ym < MAX_YM)
+                  if (!issolid(pbad->base.x+16, pbad->base.y + 32))
                     {
-                      pbad->base.ym = pbad->base.ym + GRAVITY;
+                      if(!physic_is_set(&pbad->physic))
+                        {
+                          physic_set_state(&pbad->physic,PH_VT);
+                          physic_set_start_vy(&pbad->physic,2.);
+                        }
+
+                          pbad->base.ym = physic_get_velocity(&pbad->physic);
                     }
                   else
                     {
@@ -108,10 +113,18 @@ void badguy_action(bad_guy_type* pbad)
                           pbad->base.y = (int)(pbad->base.y / 32) * 32;
                           pbad->base.ym = 0;
                         }
+                      physic_init(&pbad->physic);
                     }
                 }
               else
-                pbad->base.ym = pbad->base.ym + GRAVITY;
+                {
+                  if(!physic_is_set(&pbad->physic))
+                    {
+                      physic_set_state(&pbad->physic,PH_VT);
+                      physic_set_start_vy(&pbad->physic,2.);
+                    }
+                  pbad->base.ym = physic_get_velocity(&pbad->physic);
+                }
 
               if (pbad->base.y > screen->h)
                 pbad->base.alive = NO;
@@ -177,11 +190,11 @@ void badguy_action(bad_guy_type* pbad)
               if (!pbad->dying)
                 {
                   int changed = pbad->dir;
-                  if (issolid( pbad->base.x - 1, (int) pbad->base.y))
+                  if (issolid( pbad->base.x - 1, (int) pbad->base.y + 16))
                     {
                       pbad->dir = RIGHT;
                     }
-                  else if (issolid( pbad->base.x + pbad->base.width-1, (int) pbad->base.y))
+                  else if (issolid( pbad->base.x + pbad->base.width-1, (int) pbad->base.y + 16))
                     {
                       pbad->dir = LEFT;
                     }
@@ -199,15 +212,23 @@ void badguy_action(bad_guy_type* pbad)
 
                 }
 
+
               /* Fall if we get off the ground: */
 
               if (pbad->dying != FALLING)
                 {
-                  if (!issolid(pbad->base.x, pbad->base.y + 32) &&
-                      pbad->base.ym < MAX_YM)
+                  if (!issolid(pbad->base.x+16, pbad->base.y + 32))
                     {
+                      if(!physic_is_set(&pbad->physic))
+                        {
+                          physic_set_state(&pbad->physic,PH_VT);
+                          physic_set_start_vy(&pbad->physic,0.);
+                        }
+
                       if(pbad->mode != HELD)
-                        pbad->base.ym = pbad->base.ym + GRAVITY;
+                        {
+                          pbad->base.ym = physic_get_velocity(&pbad->physic);
+                        }
                     }
                   else
                     {
@@ -218,10 +239,18 @@ void badguy_action(bad_guy_type* pbad)
                           pbad->base.y = (int)(pbad->base.y / 32) * 32;
                           pbad->base.ym = 0;
                         }
+                      physic_init(&pbad->physic);
                     }
                 }
               else
-                pbad->base.ym = pbad->base.ym + GRAVITY;
+                {
+                  if(!physic_is_set(&pbad->physic))
+                    {
+                      physic_set_state(&pbad->physic,PH_VT);
+                      physic_set_start_vy(&pbad->physic,0.);
+                    }
+                  pbad->base.ym = physic_get_velocity(&pbad->physic);
+                }
 
               if (pbad->base.y > screen->h)
                 pbad->base.alive = NO;
@@ -249,7 +278,7 @@ void badguy_action(bad_guy_type* pbad)
                 }
               else if(issolid(pbad->base.x, pbad->base.y - 1))
                 { /* This works, but isn't the best solution imagineable */
-                 physic_set_state(&pbad->physic,PH_VT);
+                  physic_set_state(&pbad->physic,PH_VT);
                   physic_set_start_vy(&pbad->physic,0.);
                   pbad->base.ym = physic_get_velocity(&pbad->physic);
                 }
index f6440a4..2988bd0 100644 (file)
@@ -1,7 +1,7 @@
 //
 // C Implementation: physic
 //
-// Description: 
+// Description:
 //
 //
 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
 //
 
 #include <stdio.h>
+#include "defines.h"
 #include "physic.h"
 
 void physic_init(physic_type* pphysic)
 {
-pphysic->state = -1;
-pphysic->start_time = 0;
+  pphysic->state = -1;
+  pphysic->start_time = 0;
+  pphysic->start_vy = 0;
 }
 
 int physic_get_state(physic_type* pphysic)
 {
-return pphysic->state;
+  return pphysic->state;
 }
 
 void physic_set_state(physic_type* pphysic, int nstate)
 {
-pphysic->state = nstate;
-pphysic->start_time = st_get_ticks();
+  pphysic->state = nstate;
+  pphysic->start_time = st_get_ticks();
 }
 
 void physic_set_start_vy(physic_type* pphysic, float start_vy)
 {
-pphysic->start_vy = start_vy;
+  pphysic->start_vy = start_vy;
+}
+
+int physic_is_set(physic_type* pphysic)
+{
+  if(pphysic->state != -1)
+    return YES;
+  else
+    return NO;
 }
 
 float physic_get_velocity(physic_type* pphysic)
 {
-if(pphysic->state == PH_VT)
-return - (pphysic->start_vy - 10.* ((float)(st_get_ticks() - pphysic->start_time))/1000.);
+  if(pphysic->state == PH_VT)
+    return - (pphysic->start_vy - 10.* ((float)(st_get_ticks() - pphysic->start_time))/1000.);
 }
 
 float physic_get_max_distance(physic_type* pphysic)
 {
-return (pphysic->start_vy * pphysic->start_vy / 2.*10.);
+  return (pphysic->start_vy * pphysic->start_vy / 2.*10.);
 }
 
 unsigned int physic_get_max_time(physic_type* pphysic)
 {
-return (unsigned int)((pphysic->start_vy / 10.) * 1000);
+  return (unsigned int)((pphysic->start_vy / 10.) * 1000);
 }
 
 unsigned int physic_get_time_gone(physic_type* pphysic)
 {
-return st_get_ticks() - pphysic->start_time;
+  return st_get_ticks() - pphysic->start_time;
 }
 
 
index 9150345..fd7f886 100644 (file)
@@ -33,6 +33,7 @@ void physic_init(physic_type* pphysic);
 int physic_get_state(physic_type* pphysic);
 void physic_set_state(physic_type* pphysic, int nstate);
 void physic_set_start_vy(physic_type* pphysic, float start_vy);
+int physic_is_set(physic_type* pphysic);
 float physic_get_velocity(physic_type* pphysic);
 float physic_get_max_distance(physic_type* pphysic);
 unsigned int physic_get_max_time(physic_type* pphysic);