pbad->base.y = y;
pbad->base.xm = 1.3;
pbad->base.ym = 4.8;
+ pbad->old_base = pbad->base;
pbad->dir = LEFT;
pbad->seen = NO;
timer_init(&pbad->timer,YES);
pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
+ if (pbad->dying != FALLING)
+ collision_swept_object_map(&pbad->old_base,&pbad->base);
+ if (pbad->base.y > screen->h)
+ pbad->base.alive = NO;
/* Bump into things horizontally: */
if (!pbad->dying)
{
- if (issolid( pbad->base.x - 1, (int) pbad->base.y + 16))
+ if (issolid( pbad->base.x, (int) pbad->base.y + 16))
{
pbad->dir = RIGHT;
}
- else if (issolid( pbad->base.x + pbad->base.width-1, (int) pbad->base.y + 16))
+ else if (issolid( pbad->base.x + pbad->base.width, (int) pbad->base.y + 16))
{
pbad->dir = LEFT;
}
/* Move left/right: */
- if (pbad->mode != KICK && pbad->mode != HELD)
+ if (pbad->mode != HELD)
{
if (pbad->dying == NO ||
pbad->dying == FALLING)
pbad->base.x = pbad->base.x - pbad->base.xm * frame_ratio;
}
}
- else if (pbad->mode == KICK)
- {
- /* Obsolete
- if (pbad->dir == RIGHT)
- pbad->base.x = pbad->base.x + 16;
- else if (pbad->dir == LEFT)
- pbad->base.x = pbad->base.x - 16;*/
- }
else if (pbad->mode == HELD)
{ /* FIXME: The pbad object shouldn't know about pplayer objects. */
/* If we're holding the laptop */
- if(tux.dir==RIGHT)
+ pbad->dir=tux.dir;
+ if(pbad->dir==RIGHT)
{
- pbad->base.x = tux.base.x - 16;
- pbad->base.y = tux.base.y - 8 - (tux.size*16);
+ pbad->base.x = tux.base.x + 16;
+ pbad->base.y = tux.base.y + tux.base.height/1.5 - pbad->base.height;
}
else /* facing left */
{
pbad->base.x = tux.base.x - 16;
- pbad->base.y = tux.base.y - 8 - (tux.size*16);
+ pbad->base.y = tux.base.y + tux.base.height/1.5 - pbad->base.height;
}
+ if(collision_object_map(&pbad->base))
+ {
+ pbad->base.x = tux.base.x;
+ pbad->base.y = tux.base.y + tux.base.height/1.5 - pbad->base.height;
+ }
if(tux.input.fire != DOWN) /* SHOOT! */
{
- pbad->dir=tux.dir;
+ if(pbad->dir = LEFT)
+ pbad->base.x -= 24;
+ else
+ pbad->base.x += 24;
+
pbad->mode=KICK;
pbad->base.ym-=8;
play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER);
if(pbad->mode != HELD)
pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
-
+
+ if (pbad->dying != FALLING)
+ collision_swept_object_map(&pbad->old_base,&pbad->base);
+ if (pbad->base.y > screen->h)
+ pbad->base.alive = NO;
/* Bump into things horizontally: */
/* Bump into things horizontally: */
if (!pbad->dying)
{
int changed = pbad->dir;
- if (issolid( pbad->base.x - 1, (int) pbad->base.y + 16))
+ if (issolid( pbad->base.x, (int) pbad->base.y + 16))
{
pbad->dir = RIGHT;
}
- else if (issolid( pbad->base.x + pbad->base.width-1, (int) pbad->base.y + 16))
+ else if (issolid( pbad->base.x + pbad->base.width, (int) pbad->base.y + 16))
{
pbad->dir = LEFT;
}
pbad->base.ym = physic_get_velocity(&pbad->physic);
}
- if (pbad->base.y > screen->h)
- pbad->base.alive = NO;
+
}
else if (pbad->kind == BAD_MONEY)
{
/* Move vertically: */
pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
+
+ if (pbad->dying != FALLING)
+ collision_swept_object_map(&pbad->old_base,&pbad->base);
+
+ if (pbad->base.y > screen->h)
+ pbad->base.alive = NO;
if(physic_get_state(&pbad->physic) == -1)
{
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))
+ else if(issolid(pbad->base.x, pbad->base.y))
{ /* 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);
+ ++pbad->base.y;
}
else
{
}
pbad->base.ym = physic_get_velocity(&pbad->physic);
}
-
- if (pbad->base.y > screen->h)
- pbad->base.alive = NO;
}
else if (pbad->kind == -1)
{}
}
else if (pbad->kind == BAD_LAPTOP)
{
+
if (pbad->mode != KICK)
{
/* Flatten! */
{
/* Kick! */
- pbad->mode = KICK;
play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
if (pplayer_c->base.x <= pbad->base.x)
25 * score_multiplier);
/* play_sound(sounds[SND_SQUISH]); */
- }
+ }
break;
}
cape_right[2], cape_left[2],
bigcape_right[2], bigcape_left[2];
+void player_input_init(player_input_type* pplayer_input)
+{
+ pplayer_input->down = UP;
+ pplayer_input->fire = UP;
+ pplayer_input->left = UP;
+ pplayer_input->old_fire = UP;
+ pplayer_input->right = UP;
+ pplayer_input->up = UP;
+}
+
void player_init(player_type* pplayer)
{
pplayer->base.width = 32;
pplayer->base.y = 240;
pplayer->base.xm = 0;
pplayer->base.ym = 0;
+ pplayer->old_base = pplayer->base;
pplayer->dir = RIGHT;
pplayer->duck = NO;
pplayer->score = 0;
pplayer->distros = 0;
- pplayer->input.down = UP;
- pplayer->input.fire = UP;
- pplayer->input.left = UP;
- pplayer->input.old_fire = UP;
- pplayer->input.right = UP;
- pplayer->input.up = UP;
+ player_input_init(&pplayer->input);
pplayer->keymap.jump = SDLK_UP;
pplayer->keymap.duck = SDLK_DOWN;
pplayer->base.y = 240;
pplayer->base.xm = 0;
pplayer->base.ym = 0;
+ pplayer->old_base = pplayer->base;
- pplayer->input.down = UP;
- pplayer->input.fire = UP;
- pplayer->input.left = UP;
- pplayer->input.old_fire = UP;
- pplayer->input.right = UP;
- pplayer->input.up = UP;
+ player_input_init(&pplayer->input);
timer_init(&pplayer->invincible_timer,YES);
timer_init(&pplayer->skidding_timer,YES);
void player_action(player_type* pplayer)
{
+ int i, jumped_in_solid;
+ jumped_in_solid = NO;
+
/* --- HANDLE TUX! --- */
player_input(pplayer);
pplayer->base.x += pplayer->base.xm * frame_ratio;
pplayer->base.y += pplayer->base.ym * frame_ratio;
+ collision_swept_object_map(&pplayer->old_base,&pplayer->base);
+
player_keep_in_bounds(pplayer);
/* Land: */
if (!pplayer->dying)
{
- 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(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( !player_on_ground(pplayer))
{
- if(!physic_is_set(&pplayer->vphysic))
+ if(player_under_solid(pplayer))
{
physic_set_state(&pplayer->vphysic,PH_VT);
- physic_set_start_vy(&pplayer->vphysic,0.);
+ physic_set_start_vy(&pplayer->vphysic,0);
+ jumped_in_solid = YES;
+ }
+ else
+ {
+ 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 (pplayer->base.ym > 0)
{
- pplayer->base.y = (int)(((int)(pplayer->base.y +1) / 32) * 32);
+ pplayer->base.y = (int)(((int)pplayer->base.y / 32) * 32);
pplayer->base.ym = 0;
}
+
physic_init(&pplayer->vphysic);
}
- if(pplayer->base.ym < 0)
+
+ if(jumped_in_solid == YES)
{
if (isbrick(pplayer->base.x, pplayer->base.y) ||
}
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))
+ if(jumped_in_solid == YES)
{
- /* Set down properly: * /
-
- int debug_int = 0;
- while (issolid(pplayer->base.x, pplayer->base.y + 31))
+ ++pplayer->base.y;
+ ++pplayer->old_base.y;
+ if(player_on_ground(pplayer))
{
- ++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--;
+ /* Make sure jumping is off. */
+ pplayer->jumping = NO;
}
+ }
-
- /* Reset score multiplier (for multi-hits): */
+ /* 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!!! */
- /*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)))* /
-
- 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))* /
- {
- 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))))
- {
- 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) ||
- 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);
-
- if (counting_distros == NO)
- {
- counting_distros = YES;
- distro_counter = 100;
- }
-
- if (distro_counter <= 0)
- level_change(¤t_level,pplayer->base.x,pplayer->base.y, '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(((pplayer->base.x+ 1 + 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++;
- }
-
- }
- 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)))
- {
- 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 (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);
-
- 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);
- }
-
- 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);
- }
-
- 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))
- {
- 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);
- }
-
- 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
- {
- /* 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);
-
- if (counting_distros == NO)
- {
- counting_distros = YES;
- distro_counter = 100;
- }
-
- if (distro_counter <= 0)
- level_change(¤t_level,pplayer->base.x,pplayer->base.y, '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(((pplayer->base.x+ 1 + 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++;
- }
- }
-
-
- /* 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 - 32;
- }
-
- pplayer->base.ym = 0;
- pplayer->jumping = NO;
- timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
- }*/
- }
}
-
- /*
- player_grabdistros(pplayer);
- */
-
- /* 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->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;
- }
- }
-
-
- /* Drop vertically: * /
-
- 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;
- }
- }
-
-
- */
timer_check(&pplayer->safe_timer);
/* Handle invincibility timer: */
- if (current_music == HERRING_MUSIC && !timer_check(&pplayer->invincible_timer))
+ if (get_current_music() == HERRING_MUSIC && !timer_check(&pplayer->invincible_timer))
{
/*
no, we are no more invincible
stop the herring_song, prepare to play the correct
fast level_song !
*/
- current_music = HURRYUP_MUSIC;
+ set_current_music(HURRYUP_MUSIC);
}
else
{
- current_music = LEVEL_MUSIC;
+ set_current_music(LEVEL_MUSIC);
}
- /* stop the old music if it's being played */
- if (playing_music())
- halt_music();
+ /* start playing it */
+ play_current_music();
}
/* Handle skidding: */
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) )
+ if( issolid(pplayer->base.x + pplayer->base.width / 2, pplayer->base.y + pplayer->base.height) ||
+ issolid(pplayer->base.x + 1, pplayer->base.y + pplayer->base.height) ||
+ issolid(pplayer->base.x + pplayer->base.width - 1, pplayer->base.y + pplayer->base.height) )
+ {
+ return YES;
+ }
+ else
+ {
+ return NO;
+ }
+}
+
+int player_under_solid(player_type *pplayer)
+{
+ if( issolid(pplayer->base.x + pplayer->base.width / 2, pplayer->base.y) ||
+ issolid(pplayer->base.x + 1, pplayer->base.y) ||
+ issolid(pplayer->base.x + pplayer->base.width - 1, pplayer->base.y) )
{
return YES;
}
pplayer->dir = dir;
}
- if ((dir ? (pplayer->base.xm < 0) : (pplayer->base.xm > 0)) && !isice(pplayer->base.x, pplayer->base.y + 32) &&
+ if ((dir ? (pplayer->base.xm < 0) : (pplayer->base.xm > 0)) && !isice(pplayer->base.x, pplayer->base.y + pplayer->base.height) &&
!timer_started(&pplayer->skidding_timer))
{
pplayer->base.xm = 0;
}
else if(pplayer->input.up == UP && pplayer->jumping == YES)
{
- if (issolid(pplayer->base.x + 16, pplayer->base.y + pplayer->base.height + 1))
+ if (player_on_ground(pplayer))
{
physic_init(&pplayer->vphysic);
pplayer->jumping == NO;
}
}
}
-
- /* 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! * /
-
- 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 = pplayer->base.ym/*-YM_FOR_JUMP* /;
- }*/
}
void player_input(player_type *pplayer)
if (pplayer->input.down == DOWN)
{
- if (pplayer->size == BIG)
- {
- pplayer->duck = YES;
- pplayer->base.height = 32;
- }
+ if (pplayer->size == BIG && pplayer->duck != YES)
+ {
+ pplayer->duck = YES;
+ pplayer->base.height = 32;
+ pplayer->base.y += 32;
+ }
}
else
{
if (pplayer->size == BIG && pplayer->duck == YES)
{
/* Make sure we're not standing back up into a solid! */
+ pplayer->base.height = 64;
+ pplayer->base.y -= 32;
- if (!issolid(pplayer->base.x + 16, pplayer->base.y - 16))
- {
- pplayer->duck = NO;
- pplayer->base.height = 64;
- }
+ if (!collision_object_map(&pplayer->base) /*issolid(pplayer->base.x + 16, pplayer->base.y - 16)*/)
+ {
+ pplayer->duck = NO;
+ pplayer->base.height = 64;
+ pplayer->old_base.y -= 32;
+ pplayer->old_base.height = 64;
+ }
+ else
+ {
+ pplayer->base.height = 32;
+ pplayer->base.y += 32;
+ }
}
else
- {
- pplayer->duck = NO;
- }
+ {
+ pplayer->duck = NO;
+ }
}
/* (Tux): */
else
{
pbad_c->dir = LEFT;
- pbad_c->base.x = pbad_c->base.x - 16;
+ pbad_c->base.x = pbad_c->base.x - 32;
}
-
- timer_start(&pbad_c->timer,5000);
+
+ timer_start(&pbad_c->timer,5000);
}
else if (pbad_c->mode == FLAT && pplayer->input.fire == DOWN)
{
pupgrade->base.xm = 2;
pupgrade->base.ym = -2;
pupgrade->base.height = 0;
+ pupgrade->old_base = pupgrade->base;
}
void upgrade_action(upgrade_type *pupgrade)
/* Rise up! */
pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio;
- if(pupgrade->base.height > 32)
- pupgrade->base.height = 32;
+ if(pupgrade->base.height > 32)
+ pupgrade->base.height = 32;
}
else
{
pupgrade->base.x = pupgrade->base.x + pupgrade->base.xm * frame_ratio;
pupgrade->base.y = pupgrade->base.y + pupgrade->base.ym * frame_ratio;
- if (issolid(pupgrade->base.x, pupgrade->base.y + 31.) ||
- issolid(pupgrade->base.x + 31., pupgrade->base.y + 31.))
+ collision_swept_object_map(&pupgrade->old_base,&pupgrade->base);
+
+ /* Off the screen? Kill it! */
+
+ if (pupgrade->base.x < scroll_x - pupgrade->base.width)
+ pupgrade->base.alive = NO;
+ if (pupgrade->base.y > screen->h)
+ pupgrade->base.alive = NO;
+
+ if (issolid(pupgrade->base.x + 1, pupgrade->base.y + 32.) ||
+ issolid(pupgrade->base.x + 31., pupgrade->base.y + 32.))
{
if (pupgrade->base.ym > 0)
{
}
}
else
- pupgrade->base.ym = pupgrade->base.ym + GRAVITY;
+ pupgrade->base.ym = pupgrade->base.ym + GRAVITY * frame_ratio;
- if (issolid(pupgrade->base.x - 1, (int) pupgrade->base.y))
- {
- if(pupgrade->base.xm < 0)
- pupgrade->base.xm = -pupgrade->base.xm;
- }
- else if (issolid(pupgrade->base.x + pupgrade->base.width-1, (int) pupgrade->base.y))
- {
- if(pupgrade->base.xm > 0)
- pupgrade->base.xm = -pupgrade->base.xm;
- }
+ if (issolid(pupgrade->base.x - 1, (int) pupgrade->base.y))
+ {
+ if(pupgrade->base.xm < 0)
+ pupgrade->base.xm = -pupgrade->base.xm;
+ }
+ else if (issolid(pupgrade->base.x + pupgrade->base.width, (int) pupgrade->base.y))
+ {
+ if(pupgrade->base.xm > 0)
+ pupgrade->base.xm = -pupgrade->base.xm;
+ }
}
-
- /* Off the screen? Kill it! */
-
- if (pupgrade->base.x < scroll_x - pupgrade->base.width)
- pupgrade->base.alive = NO;
-
}
}
}
void upgrade_draw(upgrade_type* pupgrade)
{
-SDL_Rect dest;
+ SDL_Rect dest;
if (pupgrade->base.alive)
{
if (pupgrade->base.height < 32)
dest.h = (int)pupgrade->base.height;
if (pupgrade->kind == UPGRADE_MINTS)
- texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
+ texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
else if (pupgrade->kind == UPGRADE_COFFEE)
- texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
+ texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
else if (pupgrade->kind == UPGRADE_HERRING)
- texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
+ texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
}
else
{
{
play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
pplayer->size = BIG;
- pplayer->base.height = 64;
+ pplayer->base.height = 64;
+ pplayer->base.y -= 32;
+ if(collision_object_map(&pplayer->base))
+ {
+ pplayer->base.height = 32;
+ pplayer->base.y += 32;
+ pplayer->duck = YES;
+ }
timer_start(&super_bkgd_timer, 350);
}
else if (pupgrade->kind == UPGRADE_COFFEE)
timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
timer_start(&super_bkgd_timer, 250);
/* play the herring song ^^ */
- if (current_music != HURRYUP_MUSIC)
+ if (get_current_music() != HURRYUP_MUSIC)
{
- current_music = HERRING_MUSIC;
- if (playing_music())
- halt_music();
+ set_current_music(HERRING_MUSIC);
+ play_current_music();
}
}
break;