}
}
- /* 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
{
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;
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;
}
}
+
/* 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
{
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;
}
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);
}
//
// 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;
}