{
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))
+ {
pbad->dir = LEFT;
- }
+ }
}
/* Fall if we get off the ground: */
/* Bump into things horizontally: */
+ /* Bump into things horizontally: */
+
if (!pbad->dying)
{
- if (issolid(pbad->base.x, pbad->base.y))
+ int changed = pbad->dir;
+ if (issolid( pbad->base.x - 1, (int) pbad->base.y))
{
- pbad->dir = !pbad->dir;
-
- if (pbad->mode == KICK)
- {
- /* handle stereo sound */
- /* FIXME: In theory a badguy object doesn't know anything about player objects */
- if (tux.base.x > pbad->base.x)
- play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
- else if (tux.base.x < pbad->base.x)
- play_sound(sounds[SND_RICOCHET], SOUND_RIGHT_SPEAKER);
- else
- play_sound(sounds[SND_RICOCHET], SOUND_CENTER_SPEAKER);
- }
+ pbad->dir = RIGHT;
+ }
+ else if (issolid( pbad->base.x + pbad->base.width-1, (int) pbad->base.y))
+ {
+ pbad->dir = LEFT;
+ }
+ if(pbad->mode == KICK && changed != pbad->dir)
+ {
+ /* handle stereo sound */
+ /* FIXME: In theory a badguy object doesn't know anything about player objects */
+ if (tux.base.x > pbad->base.x)
+ play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
+ else if (tux.base.x < pbad->base.x)
+ play_sound(sounds[SND_RICOCHET], SOUND_RIGHT_SPEAKER);
+ else
+ play_sound(sounds[SND_RICOCHET], SOUND_CENTER_SPEAKER);
}
- }
+ }
/* Fall if we get off the ground: */
pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
- if(physic_get_state(&pbad->physic) == -1)
- physic_set_state(&pbad->physic,PH_VTU);
-
- if(issolid(pbad->base.x, pbad->base.y + 32))
- {
- physic_set_state(&pbad->physic,PH_VTU);
- pbad->base.ym = -0.6;
- }
- else if(issolid(pbad->base.x, pbad->base.y - 1))
- { /* This works, but isn't the best solution imagineable */
- pbad->base.ym = physic_get_velocity(&pbad->physic,-6.);
- }
- else
- {
- pbad->base.ym = physic_get_velocity(&pbad->physic,6.);
- }
+ if(physic_get_state(&pbad->physic) == -1)
+ {
+ physic_set_state(&pbad->physic,PH_VT);
+ physic_set_start_vy(&pbad->physic,0.);
+ }
+
+ if(issolid(pbad->base.x, pbad->base.y + 32))
+ {
+ physic_set_state(&pbad->physic,PH_VT);
+ physic_set_start_vy(&pbad->physic,6.);
+ pbad->base.ym = physic_get_velocity(&pbad->physic);
+ }
+ 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_start_vy(&pbad->physic,0.);
+ pbad->base.ym = physic_get_velocity(&pbad->physic);
+ }
+ else
+ {
+ pbad->base.ym = physic_get_velocity(&pbad->physic);
+ }
if (pbad->base.y > screen->h)
pbad->base.alive = NO;
pphysic->start_time = st_get_ticks();
}
-float physic_get_velocity(physic_type* pphysic, float start_velocity)
+void physic_set_start_vy(physic_type* pphysic, float start_vy)
{
-return - (start_velocity - 10.* ((float)(st_get_ticks() - pphysic->start_time))/1000.);
+pphysic->start_vy = start_vy;
}
-float physic_get_max_distance(physic_type* pphysic, float start_velocity)
+float physic_get_velocity(physic_type* pphysic)
{
-return (start_velocity * start_velocity / 2.*10.);
+if(pphysic->state == PH_VT)
+return - (pphysic->start_vy - 10.* ((float)(st_get_ticks() - pphysic->start_time))/1000.);
}
-unsigned int physic_get_max_time(physic_type* pphysic, float start_velocity)
+float physic_get_max_distance(physic_type* pphysic)
{
-return (unsigned int)((start_velocity / 10.) * 1000);
+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);
}
unsigned int physic_get_time_gone(physic_type* pphysic)
#include "timer.h"
enum {
- PH_VTU /* Vertical throw up. */
+ PH_VT, /* Vertical throw.*/
};
/* Physic type: */
typedef struct physic_type
{
int state;
+ float start_vy;
unsigned int start_time;
}
physic_type;
void physic_init(physic_type* pphysic);
int physic_get_state(physic_type* pphysic);
void physic_set_state(physic_type* pphysic, int nstate);
-float physic_get_velocity(physic_type* pphysic, float start_velocity);
-float physic_get_max_distance(physic_type* pphysic, float start_velocity);
-unsigned int physic_get_max_time(physic_type* pphysic, float start_velocity);
+void physic_set_start_vy(physic_type* pphysic, float start_vy);
+float physic_get_velocity(physic_type* pphysic);
+float physic_get_max_distance(physic_type* pphysic);
+unsigned int physic_get_max_time(physic_type* pphysic);
unsigned int physic_get_time_gone(physic_type* pphysic);
#endif /*SUPERTUX_PHYSIC_H*/