pplayer->frame_main = 0;
pplayer->frame = 0;
pplayer->lives = 3;
+ pplayer->score = 0;
+ pplayer->distros = 0;
pplayer->input.down = UP;
pplayer->input.fire = UP;
pplayer->keymap.right = SDLK_RIGHT;
pplayer->keymap.fire = SDLK_LCTRL;
- timer_init(&pplayer->invincible_timer);
- timer_init(&pplayer->skidding_timer);
- timer_init(&pplayer->safe_timer);
+ timer_init(&pplayer->invincible_timer,YES);
+ timer_init(&pplayer->skidding_timer,YES);
+ timer_init(&pplayer->safe_timer,YES);
+ timer_init(&pplayer->frame_timer,YES);
+ physic_init(&pplayer->hphysic);
+ physic_init(&pplayer->vphysic);
}
-int player_keydown_event(player_type* pplayer, SDLKey key)
+int player_key_event(player_type* pplayer, SDLKey key, int state)
{
if(key == pplayer->keymap.right)
{
- pplayer->input.right = DOWN;
+ pplayer->input.right = state;
return YES;
}
else if( key == pplayer->keymap.left)
{
- pplayer->input.left = DOWN;
+ pplayer->input.left = state;
return YES;
}
else if(key == pplayer->keymap.jump)
{
- pplayer->input.up = DOWN;
+ pplayer->input.up = state;
return YES;
}
else if(key == pplayer->keymap.duck)
{
- pplayer->input.down = DOWN;
+ pplayer->input.down = state;
return YES;
}
else if(key == pplayer->keymap.fire)
{
- pplayer->input.fire = DOWN;
- return YES;
- }
- else
- return NO;
-}
-
-int player_keyup_event(player_type* pplayer, SDLKey key)
-{
- if(key == pplayer->keymap.right)
- {
- pplayer->input.right = UP;
- return YES;
- }
- else if( key == pplayer->keymap.left)
- {
- pplayer->input.left = UP;
- return YES;
- }
- else if(key == pplayer->keymap.jump)
- {
- pplayer->input.up = UP;
- return YES;
- }
- else if(key == pplayer->keymap.duck)
- {
- pplayer->input.down = UP;
- return YES;
- }
- else if(key == pplayer->keymap.fire)
- {
- pplayer->input.fire = UP;
+ pplayer->input.fire = state;
return YES;
}
else
pplayer->input.old_fire = UP;
pplayer->input.right = UP;
pplayer->input.up = UP;
-
- timer_init(&pplayer->invincible_timer);
- timer_init(&pplayer->skidding_timer);
- timer_init(&pplayer->safe_timer);
+
+ timer_init(&pplayer->invincible_timer,YES);
+ timer_init(&pplayer->skidding_timer,YES);
+ timer_init(&pplayer->safe_timer,YES);
+ timer_init(&pplayer->frame_timer,YES);
+ physic_init(&pplayer->hphysic);
+ physic_init(&pplayer->vphysic);
}
void player_action(player_type* pplayer)
/* Move tux: */
- pplayer->base.x= pplayer->base.x+ pplayer->base.xm * frame_ratio;
- pplayer->base.y = pplayer->base.y + pplayer->base.ym * frame_ratio;
+ pplayer->base.x += pplayer->base.xm * frame_ratio;
+ pplayer->base.y += pplayer->base.ym * frame_ratio;
player_keep_in_bounds(pplayer);
if (!pplayer->dying)
{
- /* FIXME: this code is COMPLETLY broken!!! */
- /* if (issolid(pplayer->base.x, pplayer->base.y + 31) &&
- !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y + 31))
- {
- while (issolid(pplayer->base.x, pplayer->base.y + 31))
- {
- if (pplayer->base.xm < 0)
- pplayer->base.x++;
- else if (pplayer->base.xm > 0)
- pplayer->base.x--;
- }
- pplayer->base.xm = 0;
- }*/
+ /*if(physic_is_set(&pplayer->vphysic))
+ {
+ pplayer->base.ym = physic_get_velocity(&pplayer->vphysic);
+ }
+ else
+ {*/
+ if( /*!issolid( pplayer->base.x + 16, pplayer->base.y + pplayer->base.height )*/ !player_on_ground(pplayer))
+ {
+ if(!physic_is_set(&pplayer->vphysic))
+ {
+ physic_set_state(&pplayer->vphysic,PH_VT);
+ physic_set_start_vy(&pplayer->vphysic,0.);
+ }
+ pplayer->base.ym = physic_get_velocity(&pplayer->vphysic);
+ }
+ else
+ {
+ /* Land: */
- /*if (issolid(pplayer->base.x, pplayer->base.y) &&
- !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y))
- {
- while (issolid(pplayer->base.x, (pplayer->base.y)))
- {
- if (pplayer->base.xm < 0)
- pplayer->base.x++;
- else if (pplayer->base.xm > 0)
- pplayer->base.x--;
- }
+ if (pplayer->base.ym > 0)
+ {
+ pplayer->base.y = (int)(((int)(pplayer->base.y +1) / 32) * 32);
+ pplayer->base.ym = 0;
+ }
+ physic_init(&pplayer->vphysic);
+ }
- pplayer->base.xm = 0;
- }*/
+ while(issolid( pplayer->base.x + 16, pplayer->base.y + pplayer->base.height) && !issolid( pplayer->base.x + 16, pplayer->base.y + 1))
+ {
+ --pplayer->base.y;
+ }
+ while(issolid( pplayer->base.x + 16, pplayer->base.y + 1) && !issolid( pplayer->base.x + 16, pplayer->base.y + pplayer->base.height))
+ {
+ ++pplayer->base.y;
+ }
+ while(issolid( pplayer->base.x - 1, pplayer->base.y + 1) || issolid( pplayer->base.x - 1, pplayer->base.y+pplayer->base.height))
+ {
+ ++pplayer->base.x;
+ }
+ while(issolid( pplayer->base.x + 32, pplayer->base.y + 1) || issolid( pplayer->base.x + 32, pplayer->base.y+pplayer->base.height))
+ {
+ --pplayer->base.x;
+ }
- if (issolid(pplayer->base.x, pplayer->base.y + 31))
- {
- /* Set down properly: */
+ if(pplayer->base.ym < 0)
+ {
- int debug_int = 0;
- while (issolid(pplayer->base.x, pplayer->base.y + 31))
- {
- ++debug_int;
- if(debug_int > 32)
- {
- DEBUG_MSG("FIXME - UNDER certain circumstances I'm hanging in a loop here!");
- /*the circumstances are:
- issolid() is true and base.ym == 0
- use of floating point varibles for base stuff*/
- break;
- }
- if (pplayer->base.ym < 0)
- pplayer->base.y++;
- else if (pplayer->base.ym > 0)
- pplayer->base.y--;
- }
+ if (isbrick(pplayer->base.x, pplayer->base.y) ||
+ isfullbox(pplayer->base.x, pplayer->base.y))
+ {
+ trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE);
+ trybumpbadguy(pplayer->base.x, pplayer->base.y - 64);
+ if(pplayer->size == BIG)
+ trybreakbrick(pplayer->base.x, pplayer->base.y);
- /* Reset score multiplier (for multi-hits): */
+ bumpbrick(pplayer->base.x, pplayer->base.y);
+ tryemptybox(pplayer->base.x, pplayer->base.y);
+ }
+
+ if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
+ isfullbox(pplayer->base.x+ 31, pplayer->base.y))
+ {
+ trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE);
+ trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64);
+
+ if(pplayer->size == BIG)
+ trybreakbrick(pplayer->base.x+ 31, pplayer->base.y);
+
+ bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
+ tryemptybox(pplayer->base.x+ 31, pplayer->base.y);
+ }
- if (pplayer->base.ym > 0)
- score_multiplier = 1;
+ if(pplayer->size == SMALL)
+ {
+ /* Get a distro from a brick? */
+
+ if (shape(pplayer->base.x, pplayer->base.y) == 'x' ||
+ shape(pplayer->base.x, pplayer->base.y) == 'y')
+ {
+ add_bouncy_distro((((int)pplayer->base.x)
+ / 32) * 32,
+ ((int)pplayer->base.y / 32) * 32);
+ if (counting_distros == NO)
+ {
+ counting_distros = YES;
+ distro_counter = 100;
+ }
- /* Stop jumping! */
+ if (distro_counter <= 0)
+ level_change(¤t_level,pplayer->base.x,pplayer->base.y - 1, 'a');
+
+ play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
+ score = score + SCORE_DISTRO;
+ distros++;
+ }
+ else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' ||
+ shape(pplayer->base.x+ 31, pplayer->base.y) == 'y')
+ {
+ add_bouncy_distro((((int)pplayer->base.x + 31)
+ / 32) * 32,
+ ((int)pplayer->base.y / 32) * 32);
+ if (counting_distros == NO)
+ {
+ counting_distros = YES;
+ distro_counter = 100;
+ }
+
+ if (distro_counter <= 0)
+ level_change(¤t_level,pplayer->base.x+ 31, pplayer->base.y, 'a');
+
+ play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
+ score = score + SCORE_DISTRO;
+ distros++;
+ }
+ }
+ }
+
+ player_grabdistros(pplayer);
+
+ /* FIXME: this code is COMPLETLY broken!!! */
+ /* if (issolid(pplayer->base.x, pplayer->base.y + 31) &&
+ !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y + 31))
+ {
+ while (issolid(pplayer->base.x, pplayer->base.y + 31))
+ {
+ if (pplayer->base.xm < 0)
+ pplayer->base.x++;
+ else if (pplayer->base.xm > 0)
+ pplayer->base.x--;
+ }
+
+ pplayer->base.xm = 0;
+ }*/
+
+ /*if (issolid(pplayer->base.x, pplayer->base.y) &&
+ !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y))
+ {
+ while (issolid(pplayer->base.x, (pplayer->base.y)))
+ {
+ if (pplayer->base.xm < 0)
+ pplayer->base.x++;
+ else if (pplayer->base.xm > 0)
+ pplayer->base.x--;
+ }
+
+ pplayer->base.xm = 0;
+ }*/
+
+ /*if (issolid(pplayer->base.x, pplayer->base.y + 31))
+ {
+ /* Set down properly: * /
+
+ int debug_int = 0;
+ while (issolid(pplayer->base.x, pplayer->base.y + 31))
+ {
+ ++debug_int;
+ if(debug_int > 32)
+ {
+ DEBUG_MSG("FIXME - UNDER certain circumstances I'm hanging in a loop here!");
+ /*the circumstances are:
+ issolid() is true and base.ym == 0
+ use of floating point varibles for base stuff* /
+ break;
+ }
+ if (pplayer->base.ym < 0)
+ pplayer->base.y++;
+ else if (pplayer->base.ym > 0)
+ pplayer->base.y--;
+ }
+
+
+ /* Reset score multiplier (for multi-hits): */
+
+ if (pplayer->base.ym > 2)
+ score_multiplier = 1;
+
+
+ /* Stop jumping! * /
pplayer->base.ym = 0;
pplayer->jumping = NO;
pplayer->input.up = UP;
}
- /* FIXME: this code is COMPLETLY broken!!! */
+ /* FIXME: this code is COMPLETLY broken!!! */
/*if (issolid(pplayer->base.x, pplayer->base.y) ||
(pplayer->size == BIG && !pplayer->duck &&
(issolid(pplayer->base.x, pplayer->base.y - 32))))
{*/
/*if (!issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y) &&
(pplayer->size == SMALL || pplayer->duck ||
- !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32)))*/
+ !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32)))* /
if (((!issolid(pplayer->base.x, pplayer->base.y- pplayer->base.ym * frame_ratio) && (issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x, pplayer->base.y+31))))
||((!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y) && (issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x+32, pplayer->base.y)))))
/*(pplayer->size == SMALL || pplayer->duck ||
- !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))*/
+ !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))* /
{
pplayer->base.y = pplayer->base.y- pplayer->base.ym * frame_ratio;
pplayer->base.ym = 0;
}
-
+
if (((issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x+32, pplayer->base.y)) && (!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y))
/*(pplayer->size == SMALL || pplayer->duck ||
- !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))*/) ||
- (!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y+pplayer->base.height) && (issolid(pplayer->base.x, pplayer->base.y+pplayer->base.height) || issolid(pplayer->base.x +32, pplayer->base.y+pplayer->base.height))))
+ !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))* /) ||
+ (!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y+pplayer->base.height) && (issolid(pplayer->base.x, pplayer->base.y+pplayer->base.height) || issolid(pplayer->base.x +32, pplayer->base.y+pplayer->base.height))))
{
- pplayer->base.x = pplayer->base.x- pplayer->base.xm * frame_ratio;
+ pplayer->base.x = pplayer->base.x- pplayer->base.xm * frame_ratio;
pplayer->base.xm = 0;
}
-
+
if (pplayer->base.ym <= 0)
{
if (isbrick(pplayer->base.x, pplayer->base.y) ||
bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
tryemptybox(pplayer->base.x+ 31, pplayer->base.y);
}
- /* Get a distro from a brick? */
+ /* Get a distro from a brick? * /
if (shape(pplayer->base.x, pplayer->base.y) == 'x' ||
shape(pplayer->base.x, pplayer->base.y) == 'y')
score = score + SCORE_DISTRO;
distros++;
}
-
- }
- else
-{
- pplayer->base.ym = 0;
- pplayer->jumping = NO;
- timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
-}
- /*}*/
- /* Bump into things: * /
-
- if (issolid(pplayer->base.x, pplayer->base.y) ||
- (pplayer->size == BIG && !pplayer->duck &&
- (issolid(pplayer->base.x, pplayer->base.y - 32))))
- {
-
- if (!issolid(pplayer->base.x, pplayer->base.y - pplayer->base.ym) &&
- (pplayer->size == SMALL || pplayer->duck ||
- !issolid(pplayer->base.x, pplayer->base.y - 32 - pplayer->base.ym)))
+
+ }
+ else
+ {
+ pplayer->base.ym = 0;
+ pplayer->jumping = NO;
+ timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
+ }
+ /*}*/
+ /* Bump into things: * /
+
+ if (issolid(pplayer->base.x, pplayer->base.y) ||
+ (pplayer->size == BIG && !pplayer->duck &&
+ (issolid(pplayer->base.x, pplayer->base.y - 32))))
{
- if (pplayer->base.ym <= 0)
+
+ if (!issolid(pplayer->base.x, pplayer->base.y - pplayer->base.ym) &&
+ (pplayer->size == SMALL || pplayer->duck ||
+ !issolid(pplayer->base.x, pplayer->base.y - 32 - pplayer->base.ym)))
{
- /* Jumping up? */
+ if (pplayer->base.ym <= 0)
+ {
+ /* Jumping up? */
/* FIXME: this code is COMPLETLY broken!!! */
- if (pplayer->size == BIG)
- {
- /* Break bricks and empty boxes: * /
-
- if (!pplayer->duck)
+ if (pplayer->size == BIG)
{
- if (isbrick(pplayer->base.x, pplayer->base.y - 32) ||
- isfullbox(pplayer->base.x, pplayer->base.y - 32))
- {
- trygrabdistro(pplayer->base.x, pplayer->base.y - 64, BOUNCE);
- trybumpbadguy(pplayer->base.x, pplayer->base.y - 96);
+ /* Break bricks and empty boxes: * /
- if (isfullbox(pplayer->base.x, pplayer->base.y - 32))
+ if (!pplayer->duck)
+ {
+ if (isbrick(pplayer->base.x, pplayer->base.y - 32) ||
+ isfullbox(pplayer->base.x, pplayer->base.y - 32))
{
- bumpbrick(pplayer->base.x, pplayer->base.y - 32);
+ trygrabdistro(pplayer->base.x, pplayer->base.y - 64, BOUNCE);
+ trybumpbadguy(pplayer->base.x, pplayer->base.y - 96);
+
+ if (isfullbox(pplayer->base.x, pplayer->base.y - 32))
+ {
+ bumpbrick(pplayer->base.x, pplayer->base.y - 32);
+ }
+
+ trybreakbrick(pplayer->base.x, pplayer->base.y - 32);
+ tryemptybox(pplayer->base.x, pplayer->base.y - 32);
}
- trybreakbrick(pplayer->base.x, pplayer->base.y - 32);
- tryemptybox(pplayer->base.x, pplayer->base.y - 32);
- }
+ if (isbrick(pplayer->base.x+ 31, pplayer->base.y - 32) ||
+ isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32))
+ {
+ trygrabdistro(pplayer->base.x+ 31,
+ pplayer->base.y - 64,
+ BOUNCE);
+ trybumpbadguy(pplayer->base.x+ 31,
+ pplayer->base.y - 96);
- if (isbrick(pplayer->base.x+ 31, pplayer->base.y - 32) ||
- isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32))
- {
- trygrabdistro(pplayer->base.x+ 31,
- pplayer->base.y - 64,
- BOUNCE);
- trybumpbadguy(pplayer->base.x+ 31,
- pplayer->base.y - 96);
+ if (isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32))
+ {
+ bumpbrick(pplayer->base.x+ 31, pplayer->base.y - 32);
+ }
- if (isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32))
+ trybreakbrick(pplayer->base.x+ 31,
+ pplayer->base.y - 32);
+ tryemptybox(pplayer->base.x+ 31,
+ pplayer->base.y - 32);
+ }
+ }
+ else /* ducking * /
+ {
+ if (isbrick(pplayer->base.x, pplayer->base.y) ||
+ isfullbox(pplayer->base.x, pplayer->base.y))
{
- bumpbrick(pplayer->base.x+ 31, pplayer->base.y - 32);
+ trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE);
+ trybumpbadguy(pplayer->base.x, pplayer->base.y - 64);
+ if (isfullbox(pplayer->base.x, pplayer->base.y))
+ bumpbrick(pplayer->base.x, pplayer->base.y);
+ trybreakbrick(pplayer->base.x, pplayer->base.y);
+ tryemptybox(pplayer->base.x, pplayer->base.y);
}
- trybreakbrick(pplayer->base.x+ 31,
- pplayer->base.y - 32);
- tryemptybox(pplayer->base.x+ 31,
- pplayer->base.y - 32);
+ if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
+ isfullbox(pplayer->base.x+ 31, pplayer->base.y))
+ {
+ trygrabdistro(pplayer->base.x+ 31,
+ pplayer->base.y - 32,
+ BOUNCE);
+ trybumpbadguy(pplayer->base.x+ 31,
+ pplayer->base.y - 64);
+ if (isfullbox(pplayer->base.x+ 31, pplayer->base.y))
+ bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
+ trybreakbrick(pplayer->base.x+ 31, pplayer->base.y);
+ tryemptybox(pplayer->base.x+ 31, pplayer->base.y);
+ }
}
- }
- else /* ducking * /
- {
+ }
+ else
+ {
+ /* It's a brick and we're small, make the brick
+ bounce, and grab any distros above it: * /
+
if (isbrick(pplayer->base.x, pplayer->base.y) ||
isfullbox(pplayer->base.x, pplayer->base.y))
{
trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE);
trybumpbadguy(pplayer->base.x, pplayer->base.y - 64);
- if (isfullbox(pplayer->base.x, pplayer->base.y))
- bumpbrick(pplayer->base.x, pplayer->base.y);
- trybreakbrick(pplayer->base.x, pplayer->base.y);
+ bumpbrick(pplayer->base.x, pplayer->base.y);
tryemptybox(pplayer->base.x, pplayer->base.y);
}
if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
isfullbox(pplayer->base.x+ 31, pplayer->base.y))
{
- trygrabdistro(pplayer->base.x+ 31,
- pplayer->base.y - 32,
- BOUNCE);
- trybumpbadguy(pplayer->base.x+ 31,
- pplayer->base.y - 64);
- if (isfullbox(pplayer->base.x+ 31, pplayer->base.y))
- bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
- trybreakbrick(pplayer->base.x+ 31, pplayer->base.y);
+ trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE);
+ trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64);
+ bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
tryemptybox(pplayer->base.x+ 31, pplayer->base.y);
}
- }
- }
- else
- {
- /* It's a brick and we're small, make the brick
- bounce, and grab any distros above it: * /
- if (isbrick(pplayer->base.x, pplayer->base.y) ||
- isfullbox(pplayer->base.x, pplayer->base.y))
- {
- trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE);
- trybumpbadguy(pplayer->base.x, pplayer->base.y - 64);
- bumpbrick(pplayer->base.x, pplayer->base.y);
- tryemptybox(pplayer->base.x, pplayer->base.y);
- }
- if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
- isfullbox(pplayer->base.x+ 31, pplayer->base.y))
- {
- trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE);
- trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64);
- bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
- tryemptybox(pplayer->base.x+ 31, pplayer->base.y);
- }
+ /* Get a distro from a brick? * /
+ if (shape(pplayer->base.x, pplayer->base.y) == 'x' ||
+ shape(pplayer->base.x, pplayer->base.y) == 'y')
+ {
+ add_bouncy_distro(((pplayer->base.x+ 1)
+ / 32) * 32,
+ (int)(pplayer->base.y / 32) * 32);
- /* Get a distro from a brick? * /
+ if (counting_distros == NO)
+ {
+ counting_distros = YES;
+ distro_counter = 100;
+ }
- if (shape(pplayer->base.x, pplayer->base.y) == 'x' ||
- shape(pplayer->base.x, pplayer->base.y) == 'y')
- {
- add_bouncy_distro(((pplayer->base.x+ 1)
- / 32) * 32,
- (int)(pplayer->base.y / 32) * 32);
+ if (distro_counter <= 0)
+ level_change(¤t_level,pplayer->base.x,pplayer->base.y, 'a');
- if (counting_distros == NO)
- {
- counting_distros = YES;
- distro_counter = 100;
+ play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
+ score = score + SCORE_DISTRO;
+ distros++;
}
+ else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' ||
+ shape(pplayer->base.x+ 31, pplayer->base.y) == 'y')
+ {
+ add_bouncy_distro(((pplayer->base.x+ 1 + 31)
+ / 32) * 32,
+ (int)(pplayer->base.y / 32) * 32);
- if (distro_counter <= 0)
- level_change(¤t_level,pplayer->base.x,pplayer->base.y, 'a');
+ if (counting_distros == NO)
+ {
+ counting_distros = YES;
+ distro_counter = 100;
+ }
- play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
- score = score + SCORE_DISTRO;
- distros++;
- }
- else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' ||
- shape(pplayer->base.x+ 31, pplayer->base.y) == 'y')
- {
- add_bouncy_distro(((pplayer->base.x+ 1 + 31)
- / 32) * 32,
- (int)(pplayer->base.y / 32) * 32);
+ if (distro_counter <= 0)
+ level_change(¤t_level,pplayer->base.x+ 31, pplayer->base.y, 'a');
- if (counting_distros == NO)
- {
- counting_distros = YES;
- distro_counter = 100;
+ play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
+ score = score + SCORE_DISTRO;
+ distros++;
}
-
- if (distro_counter <= 0)
- level_change(¤t_level,pplayer->base.x+ 31, pplayer->base.y, 'a');
-
- play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
- score = score + SCORE_DISTRO;
- distros++;
- }
- }
+ }
- /* Bump head: * /
+ /* Bump head: * /
- pplayer->base.y = (int)(pplayer->base.y / 32) * 32 + 30;
- }
- else
- {
- /* Land on feet: * /
+ pplayer->base.y = (int)(pplayer->base.y / 32) * 32 + 30;
+ }
+ else
+ {
+ /* Land on feet: * /
- pplayer->base.y = (int)(pplayer->base.y / 32) * 32 - 32;
- }
+ pplayer->base.y = (int)(pplayer->base.y / 32) * 32 - 32;
+ }
- pplayer->base.ym = 0;
- pplayer->jumping = NO;
- timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
- }*/
+ pplayer->base.ym = 0;
+ pplayer->jumping = NO;
+ timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
+ }*/
+ }
}
-}
-
-
-player_grabdistros(pplayer);
+ /*
+ player_grabdistros(pplayer);
+ */
-/* Slow down horizontally: */
+ /* Slow down horizontally: * /
+
+ if (!pplayer->dying)
+ {
+ if (pplayer->input.right == UP && pplayer->input.left == UP)
+ {
+ if (isice(pplayer->base.x, pplayer->base.y + 32) ||
+ !issolid(pplayer->base.x, pplayer->base.y + 32))
+ {
+ /* Slowly on ice or in air: * /
-if (!pplayer->dying)
+ if (pplayer->base.xm > 0)
+ pplayer->base.xm--;
+ else if (pplayer->base.xm < 0)
+ pplayer->base.xm++;
+ }
+ else
{
- if (pplayer->input.right == UP && pplayer->input.left == UP)
- {
- if (isice(pplayer->base.x, pplayer->base.y + 32) ||
- !issolid(pplayer->base.x, pplayer->base.y + 32))
- {
- /* Slowly on ice or in air: */
+ /* Quickly, otherwise: * /
- if (pplayer->base.xm > 0)
- pplayer->base.xm--;
- else if (pplayer->base.xm < 0)
- pplayer->base.xm++;
- }
- else
- {
- /* Quickly, otherwise: */
-
- pplayer->base.xm = pplayer->base.xm / 2;
- }
- }
+ pplayer->base.xm = pplayer->base.xm / 2;
+ }
+ }
- /* Drop vertically: */
+ /* Drop vertically: * /
- if (!issolid(pplayer->base.x, pplayer->base.y + 32))
- {
- pplayer->base.ym = pplayer->base.ym + GRAVITY;
+ if (!issolid(pplayer->base.x, pplayer->base.y + 32))
+ {
+ pplayer->base.ym = pplayer->base.ym + GRAVITY;
- if (pplayer->base.ym > MAX_YM)
- pplayer->base.ym = MAX_YM;
- }
+ if (pplayer->base.ym > MAX_YM)
+ pplayer->base.ym = MAX_YM;
+ }
}
+ */
+ timer_check(&pplayer->safe_timer);
-timer_check(&pplayer->safe_timer);
+ /* ---- DONE HANDLING TUX! --- */
-/* ---- DONE HANDLING TUX! --- */
+ /* Handle invincibility timer: */
-/* Handle invincibility timer: */
+ if (current_music == HERRING_MUSIC && !timer_check(&pplayer->invincible_timer))
+ {
+ /*
+ no, we are no more invincible
+ or we were not in invincible mode
+ but are we in hurry ?
+ */
-if (current_music == HERRING_MUSIC && !timer_check(&pplayer->invincible_timer))
- {
- /*
- no, we are no more invincible
- or we were not in invincible mode
- but are we in hurry ?
- */
+ if (timer_get_left(&time_left) < TIME_WARNING)
+ {
+ /* yes, we are in hurry
+ stop the herring_song, prepare to play the correct
+ fast level_song !
+ */
+ current_music = HURRYUP_MUSIC;
+ }
+ else
+ {
+ current_music = LEVEL_MUSIC;
+ }
- if (timer_get_left(&time_left) < TIME_WARNING)
- {
- /* yes, we are in hurry
- stop the herring_song, prepare to play the correct
- fast level_song !
- */
- current_music = HURRYUP_MUSIC;
- }
- else
- {
- current_music = LEVEL_MUSIC;
- }
+ /* stop the old music if it's being played */
+ if (playing_music())
+ halt_music();
+ }
- /* stop the old music if it's being played */
- if (playing_music())
- halt_music();
- }
+ /* Handle skidding: */
-/* Handle skidding: */
+ timer_check(&pplayer->skidding_timer);
-timer_check(&pplayer->skidding_timer);
+ /* End of level? */
-/* End of level? */
+ if (pplayer->base.x - scroll_x >= endpos && endpos != 0)
+ {
+ next_level = 1;
+ }
-if (pplayer->base.x - scroll_x >= endpos && endpos != 0)
- {
- next_level = 1;
- }
+}
+int player_on_ground(player_type *pplayer)
+{
+ if( issolid(pplayer->base.x + pplayer->base.width / 2, pplayer->base.y + pplayer->base.height + 1) ||
+ issolid(pplayer->base.x + 1, pplayer->base.y + pplayer->base.height + 1) ||
+ issolid(pplayer->base.x + pplayer->base.width - 1, pplayer->base.y + pplayer->base.height + 1) )
+ {
+ return YES;
+ }
+ else
+ {
+ return NO;
+ }
}
void player_handle_horizontal_input(player_type *pplayer, int dir)
void player_handle_vertical_input(player_type *pplayer)
{
- if(!timer_started(&pplayer->jump_timer))
+ if(pplayer->input.up == DOWN)
{
- timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
-
-
- /* Taking off? */
-
- if (!issolid(pplayer->base.x, pplayer->base.y + 32) ||
- pplayer->base.ym != 0)
+ if (player_on_ground(pplayer))
{
- /* If they're not on the ground, or are currently moving
- vertically, don't jump! */
-
- pplayer->jumping = NO;
- timer_stop(&pplayer->jump_timer);
- }
- else
- {
- /* Make sure we're not standing back up into a solid! */
-
- if (pplayer->size == SMALL || pplayer->duck == NO ||
- !issolid(pplayer->base.x, pplayer->base.y))
+ if(!physic_is_set(&pplayer->vphysic))
{
+ physic_set_state(&pplayer->vphysic,PH_VT);
+ physic_set_start_vy(&pplayer->vphysic,5.5);
+ --pplayer->base.y;
pplayer->jumping = YES;
-
if (pplayer->size == SMALL)
play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER);
else
}
}
}
+ else if(pplayer->input.up == UP && pplayer->jumping == YES)
+ {
+ if (issolid(pplayer->base.x + 16, pplayer->base.y + pplayer->base.height + 1))
+ {
+ physic_init(&pplayer->vphysic);
+ pplayer->jumping == NO;
+ }
+ else
+ {
+ pplayer->jumping = NO;
+ if(physic_is_set(&pplayer->vphysic))
+ {
+ if(physic_get_velocity(&pplayer->vphysic) < 0.)
+ {
+ physic_set_state(&pplayer->vphysic,PH_VT);
+ physic_set_start_vy(&pplayer->vphysic,0);
+ }
+ }
+ else
+ {
+ if(!physic_is_set(&pplayer->vphysic))
+ {
+ physic_set_state(&pplayer->vphysic,PH_VT);
+ }
+ }
+ }
+ }
+
+ /* Taking off? * /
+
+ if (!issolid(pplayer->base.x, pplayer->base.y + 32) ||
+ pplayer->base.ym != 0)
+ {
+ /* If they're not on the ground, or are currently moving
+ vertically, don't jump! * /
+
+ pplayer->jumping = NO;
+ timer_stop(&pplayer->jump_timer);
+ }
+ else
+ {
+ /* Make sure we're not standing back up into a solid! * /
- /* Keep jumping for a while: */
+ if (pplayer->size == SMALL || pplayer->duck == NO ||
+ !issolid(pplayer->base.x, pplayer->base.y))
+ {
+ pplayer->jumping = YES;
+
+ if (pplayer->size == SMALL)
+ play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER);
+ else
+ play_sound(sounds[SND_BIGJUMP], SOUND_CENTER_SPEAKER);
+ }
+ }*/
+
+ /* Keep jumping for a while: * /
if (timer_check(&pplayer->jump_timer))
{
pplayer->base.ym = pplayer->base.ym - JUMP_SPEED * frame_ratio;
if (pplayer->base.ym < -YM_FOR_JUMP)
- pplayer->base.ym = -YM_FOR_JUMP;
- }
+ pplayer->base.ym = pplayer->base.ym/*-YM_FOR_JUMP* /;
+ }*/
}
void player_input(player_type *pplayer)
{
player_handle_horizontal_input(pplayer,LEFT);
}
+ else
+ {
+ if(pplayer->base.xm > 0)
+ {
+ pplayer->base.xm = (int)(pplayer->base.xm - frame_ratio);
+ if(pplayer->base.xm < 0)
+ pplayer->base.xm = 0;
+ }
+ else if(pplayer->base.xm < 0)
+ {
+ pplayer->base.xm = (int)(pplayer->base.xm + frame_ratio);
+ if(pplayer->base.xm > 0)
+ pplayer->base.xm = 0;
+ }
+ }
/* Jump/jumping? */
- if ( pplayer->input.up == DOWN)
+ if ( pplayer->input.up == DOWN || (pplayer->input.up == UP && pplayer->jumping == YES))
{
player_handle_vertical_input(pplayer);
}
- else
- timer_stop(&pplayer->jump_timer);
/* Shoot! */
{
/* Make sure we're not standing back up into a solid! */
- if (!issolid(pplayer->base.x, pplayer->base.y - 32))
+ if (!issolid(pplayer->base.x + 16, pplayer->base.y - 16))
pplayer->duck = NO;
}
else
/* (Tux): */
- if (pplayer->input.right == UP && pplayer->input.left == UP)
+ if(!timer_check(&pplayer->frame_timer))
{
- pplayer->frame_main = 1;
- pplayer->frame = 1;
- }
- else
- {
- if ((pplayer->input.fire == DOWN && (frame % 2) == 0) ||
- (frame % 4) == 0)
- pplayer->frame_main = (pplayer->frame_main + 1) % 4;
+ timer_start(&pplayer->frame_timer,25);
+ if (pplayer->input.right == UP && pplayer->input.left == UP)
+ {
+ pplayer->frame_main = 1;
+ pplayer->frame = 1;
+ }
+ else
+ {
+ if ((pplayer->input.fire == DOWN && (frame % 2) == 0) ||
+ (frame % 4) == 0)
+ pplayer->frame_main = (pplayer->frame_main + 1) % 4;
- pplayer->frame = pplayer->frame_main;
+ pplayer->frame = pplayer->frame_main;
- if (pplayer->frame == 3)
- pplayer->frame = 1;
+ if (pplayer->frame == 3)
+ pplayer->frame = 1;
+ }
}
}
trygrabdistro(pplayer->base.x, pplayer->base.y, NO_BOUNCE);
trygrabdistro(pplayer->base.x+ 31, pplayer->base.y, NO_BOUNCE);
- if (pplayer->size == BIG && !pplayer->duck)
+ trygrabdistro(pplayer->base.x, pplayer->base.y + pplayer->base.height, NO_BOUNCE);
+ trygrabdistro(pplayer->base.x+ 31, pplayer->base.y + pplayer->base.height, NO_BOUNCE);
+
+ if(pplayer->size == BIG)
{
- trygrabdistro(pplayer->base.x, pplayer->base.y - 32, NO_BOUNCE);
- trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32, NO_BOUNCE);
+ trygrabdistro(pplayer->base.x, pplayer->base.y + pplayer->base.height / 2, NO_BOUNCE);
+ trygrabdistro(pplayer->base.x+ 31, pplayer->base.y + pplayer->base.height / 2, NO_BOUNCE);
}
+
}
if (pplayer->dir == RIGHT)
{
texture_draw(&bigcape_right[frame % 2],
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
else
{
texture_draw(&bigcape_left[frame % 2],
- pplayer->base.x-scroll_x, pplayer->base.y,
+ pplayer->base.x-scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&bigtux_right[pplayer->frame],
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
else
{
texture_draw(&bigtux_left[pplayer->frame],
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&bigtux_right_jump,
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
else
{
texture_draw(&bigtux_left_jump,
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&skidtux_right,
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
else
{
texture_draw(&skidtux_left,
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
}
{
if (pplayer->dir == RIGHT)
{
- texture_draw(&ducktux_right, pplayer->base.x- scroll_x, pplayer->base.y,
+ texture_draw(&ducktux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
else
{
- texture_draw(&ducktux_left, pplayer->base.x- scroll_x, pplayer->base.y,
+ texture_draw(&ducktux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&bigfiretux_right[pplayer->frame],
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
else
{
texture_draw(&bigfiretux_left[pplayer->frame],
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&bigfiretux_right_jump,
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
else
{
texture_draw(&bigfiretux_left_jump,
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&skidfiretux_right,
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
else
{
texture_draw(&skidfiretux_left,
- pplayer->base.x- scroll_x, pplayer->base.y,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
}
{
if (pplayer->dir == RIGHT)
{
- texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x, pplayer->base.y,
+ texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
else
{
- texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x, pplayer->base.y,
+ texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y,
NO_UPDATE);
}
}
else
{
pbad_c->dying = FALLING;
- pbad_c->base.ym = -8;
+ physic_set_state(&pplayer->vphysic,PH_VT);
+ physic_set_start_vy(&pplayer->vphysic,-2.);
play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
}
}
else
{
pbad_c->dying = FALLING;
- pbad_c->base.ym = -8;
+ physic_set_state(&pplayer->vphysic,PH_VT);
+ physic_set_start_vy(&pplayer->vphysic,-2.);
play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
}
}
void player_dying(player_type *pplayer)
{
- pplayer->base.ym = pplayer->base.ym + GRAVITY;
+ pplayer->base.ym = pplayer->base.ym + gravity;
/* He died :^( */