From 08d8a98d7528180152de3a1bec3b7626ef2637bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Thu, 19 Feb 2004 22:02:41 +0000 Subject: [PATCH] more bad guy physics improvements SVN-Revision: 131 --- src/badguy.c | 53 +++++++++++++++++++++++++++++++++++++++++------------ src/physic.c | 34 ++++++++++++++++++++++------------ src/physic.h | 1 + 3 files changed, 64 insertions(+), 24 deletions(-) diff --git a/src/badguy.c b/src/badguy.c index fa20790d6..7f6f28ec0 100644 --- a/src/badguy.c +++ b/src/badguy.c @@ -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); } diff --git a/src/physic.c b/src/physic.c index f6440a473..2988bd0e2 100644 --- a/src/physic.c +++ b/src/physic.c @@ -1,7 +1,7 @@ // // C Implementation: physic // -// Description: +// Description: // // // Author: Tobias Glaesser , (C) 2004 @@ -11,49 +11,59 @@ // #include +#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; } diff --git a/src/physic.h b/src/physic.h index 915034524..fd7f88695 100644 --- a/src/physic.h +++ b/src/physic.h @@ -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); -- 2.11.0