void badguy_init(bad_guy_type* pbad)
{
- pbad->it.alive = &pbad->alive;
- pbad->it.x = &pbad->x;
- pbad->it.y = &pbad->y;
- pbad->it.width = &pbad->width;
- pbad->it.height = &pbad->height;
- pbad->it.updated = &pbad->updated;
-
- pbad->updated = SDL_GetTicks();
- pbad->alive = NO;
-
-
- pbad->width = 32;
- pbad->height = 32;
+ pbad->base.updated = SDL_GetTicks();
+ pbad->base.alive = NO;
+ pbad->base.width = 32;
+ pbad->base.height = 32;
}
void badguy_action(bad_guy_type* pbad)
{
- double frame_ratio = get_frame_ratio(&pbad->it);
+ double frame_ratio = get_frame_ratio(&pbad->base);
- if (pbad->alive)
+ if (pbad->base.alive)
{
if (pbad->seen)
{
pbad->dying == FALLING)
{
if (pbad->dir == RIGHT)
- pbad->x = pbad->x + pbad->xm * frame_ratio;
+ pbad->base.x = pbad->base.x + pbad->base.xm * frame_ratio;
else if (pbad->dir == LEFT)
- pbad->x = pbad->x - pbad->xm * frame_ratio;
+ pbad->base.x = pbad->base.x - pbad->base.xm * frame_ratio;
}
/* Move vertically: */
- pbad->y = pbad->y + pbad->ym * frame_ratio;
+ pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
/* Bump into things horizontally: */
if (!pbad->dying)
{
- if (issolid(pbad->x, pbad->y))
+ if (issolid(pbad->base.x, pbad->base.y))
pbad->dir = !pbad->dir;
}
if (pbad->dying != FALLING)
{
- if (!issolid(pbad->x, pbad->y + 32) &&
- pbad->ym < MAX_YM)
+ if (!issolid(pbad->base.x, pbad->base.y + 32) &&
+ pbad->base.ym < MAX_YM)
{
- pbad->ym = pbad->ym + GRAVITY;
+ pbad->base.ym = pbad->base.ym + GRAVITY;
}
else
{
/* Land: */
- if (pbad->ym > 0)
+ if (pbad->base.ym > 0)
{
- pbad->y = (int)(pbad->y / 32) * 32;
- pbad->ym = 0;
+ pbad->base.y = (int)(pbad->base.y / 32) * 32;
+ pbad->base.ym = 0;
}
}
}
else
- pbad->ym = pbad->ym + GRAVITY;
+ pbad->base.ym = pbad->base.ym + GRAVITY;
- if (pbad->y > screen->h)
- pbad->alive = NO;
+ if (pbad->base.y > screen->h)
+ pbad->base.alive = NO;
}
else if (pbad->kind == BAD_LAPTOP)
{
pbad->dying == FALLING)
{
if (pbad->dir == RIGHT)
- pbad->x = pbad->x + pbad->xm * frame_ratio;
+ pbad->base.x = pbad->base.x + pbad->base.xm * frame_ratio;
else if (pbad->dir == LEFT)
- pbad->x = pbad->x - pbad->xm * frame_ratio;
+ pbad->base.x = pbad->base.x - pbad->base.xm * frame_ratio;
}
}
else if (pbad->mode == KICK)
{
/* Obsolete
if (pbad->dir == RIGHT)
- pbad->x = pbad->x + 16;
+ pbad->base.x = pbad->base.x + 16;
else if (pbad->dir == LEFT)
- pbad->x = pbad->x - 16;*/
+ 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->x = tux.x - 16;
- pbad->y = tux.y - 8 - (tux.size*16);
+ pbad->base.x = tux.base.x - 16;
+ pbad->base.y = tux.base.y - 8 - (tux.size*16);
}
else /* facing left */
{
- pbad->x = tux.x - 16;
- pbad->y = tux.y - 8 - (tux.size*16);
+ pbad->base.x = tux.base.x - 16;
+ pbad->base.y = tux.base.y - 8 - (tux.size*16);
}
if(tux.input.fire != DOWN) /* SHOOT! */
{
pbad->dir=tux.dir;
pbad->mode=KICK;
- pbad->ym-=8;
+ pbad->base.ym-=8;
play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER);
}
}
/* Move vertically: */
if(pbad->mode != HELD)
- pbad->y = pbad->y + pbad->ym * frame_ratio;
+ pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
/* Bump into things horizontally: */
if (!pbad->dying)
{
- if (issolid(pbad->x, pbad->y))
+ if (issolid(pbad->base.x, pbad->base.y))
{
pbad->dir = !pbad->dir;
{
/* handle stereo sound */
/* FIXME: In theory a badguy object doesn't know anything about player objects */
- if (tux.x > pbad->x)
+ if (tux.base.x > pbad->base.x)
play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
- else if (tux.x < pbad->x)
+ 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);
if (pbad->dying != FALLING)
{
- if (!issolid(pbad->x, pbad->y + 32) &&
- pbad->ym < MAX_YM)
+ if (!issolid(pbad->base.x, pbad->base.y + 32) &&
+ pbad->base.ym < MAX_YM)
{
if(pbad->mode != HELD)
- pbad->ym = pbad->ym + GRAVITY;
+ pbad->base.ym = pbad->base.ym + GRAVITY;
}
else
{
/* Land: */
- if (pbad->ym > 0)
+ if (pbad->base.ym > 0)
{
- pbad->y = (int)(pbad->y / 32) * 32;
- pbad->ym = 0;
+ pbad->base.y = (int)(pbad->base.y / 32) * 32;
+ pbad->base.ym = 0;
}
}
}
else
- pbad->ym = pbad->ym + GRAVITY;
+ pbad->base.ym = pbad->base.ym + GRAVITY;
- if (pbad->y > screen->h)
- pbad->alive = NO;
+ if (pbad->base.y > screen->h)
+ pbad->base.alive = NO;
}
else if (pbad->kind == BAD_MONEY)
{
/* Move vertically: */
- pbad->y = pbad->y + pbad->ym *frame_ratio;
+ pbad->base.y = pbad->base.y + pbad->base.ym *frame_ratio;
/* Fall if we get off the ground: */
if (pbad->dying != FALLING)
{
- if (!issolid(pbad->x, pbad->y + 32))
+ if (!issolid(pbad->base.x, pbad->base.y + 32))
{
- if (pbad->ym < MAX_YM)
+ if (pbad->base.ym < MAX_YM)
{
- pbad->ym = pbad->ym + GRAVITY;
+ pbad->base.ym = pbad->base.ym + GRAVITY;
}
}
else
{
/* Land: */
- if (pbad->ym > 0)
+ if (pbad->base.ym > 0)
{
- pbad->y = (int)(pbad->y / 32) * 32;
- pbad->ym = -MAX_YM;
+ pbad->base.y = (int)(pbad->base.y / 32) * 32;
+ pbad->base.ym = -MAX_YM;
}
}
}
else
- pbad->ym = pbad->ym + GRAVITY;
+ pbad->base.ym = pbad->base.ym + GRAVITY;
- if (pbad->y > screen->h)
- pbad->alive = NO;
+ if (pbad->base.y > screen->h)
+ pbad->base.alive = NO;
}
else if (pbad->kind == -1)
{}
{
/* Remove it if time's up: */
if(!timer_check(&pbad->timer))
- pbad->alive = NO;
+ pbad->base.alive = NO;
}
/* Remove if it's far off the screen: */
- if (pbad->x < scroll_x - OFFSCREEN_DISTANCE)
- pbad->alive = NO;
+ if (pbad->base.x < scroll_x - OFFSCREEN_DISTANCE)
+ pbad->base.alive = NO;
else /* !seen */
{
/* Once it's on screen, it's activated! */
- if (pbad->x <= scroll_x + screen->w + OFFSCREEN_DISTANCE)
+ if (pbad->base.x <= scroll_x + screen->w + OFFSCREEN_DISTANCE)
pbad->seen = YES;
}
/*}*/
void badguy_draw(bad_guy_type* pbad)
{
- if (pbad->alive &&
- pbad->x > scroll_x - 32 &&
- pbad->x < scroll_x + screen->w)
+ if (pbad->base.alive &&
+ pbad->base.x > scroll_x - 32 &&
+ pbad->base.x < scroll_x + screen->w)
{
if (pbad->kind == BAD_BSOD)
{
if (pbad->dir == LEFT)
{
texture_draw(&img_bsod_left[(frame / 5) % 4],
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
else
{
texture_draw(&img_bsod_right[(frame / 5) % 4],
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
}
if (pbad->dir == LEFT)
{
texture_draw(&img_bsod_falling_left,
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
else
{
texture_draw(&img_bsod_falling_right,
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
}
if (pbad->dir == LEFT)
{
texture_draw(&img_bsod_squished_left,
- pbad->x - scroll_x,
- pbad->y + 24,
+ pbad->base.x - scroll_x,
+ pbad->base.y + 24,
NO_UPDATE);
}
else
{
texture_draw(&img_bsod_squished_right,
- pbad->x - scroll_x,
- pbad->y + 24,
+ pbad->base.x - scroll_x,
+ pbad->base.y + 24,
NO_UPDATE);
}
}
if (pbad->dir == LEFT)
{
texture_draw(&img_laptop_left[(frame / 5) % 3],
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
else
{
texture_draw(&img_laptop_right[(frame / 5) % 3],
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
}
if (pbad->dir == LEFT)
{
texture_draw(&img_laptop_flat_left,
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
else
{
texture_draw(&img_laptop_flat_right,
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
}
if (pbad->dir == LEFT)
{
texture_draw(&img_laptop_falling_left,
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
else
{
texture_draw(&img_laptop_falling_right,
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
}
}
else if (pbad->kind == BAD_MONEY)
{
- if (pbad->ym > -16)
+ if (pbad->base.ym > -16)
{
if (pbad->dir == LEFT)
{
texture_draw(&img_money_left[0],
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
else
{
texture_draw(&img_money_right[0],
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
}
if (pbad->dir == LEFT)
{
texture_draw(&img_money_left[1],
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
else
{
texture_draw(&img_money_right[1],
- pbad->x - scroll_x,
- pbad->y,
+ pbad->base.x - scroll_x,
+ pbad->base.y,
NO_UPDATE);
}
}
{
case CO_BULLET:
pbad->dying = FALLING;
- pbad->ym = -8;
+ pbad->base.ym = -8;
/* Gain some points: */
if (pbad->kind == BAD_BSOD)
- add_score(pbad->x - scroll_x, pbad->y,
+ add_score(pbad->base.x - scroll_x, pbad->base.y,
50 * score_multiplier);
else if (pbad->kind == BAD_LAPTOP)
- add_score(pbad->x - scroll_x, pbad->y,
+ add_score(pbad->base.x - scroll_x, pbad->base.y,
25 * score_multiplier);
/* Play death sound: */
/* We're in kick mode, kill the other guy: */
pbad_c->dying = FALLING;
- pbad_c->ym = -8;
+ pbad_c->base.ym = -8;
play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
- add_score(pbad->x - scroll_x,
- pbad->y, 100);
+ add_score(pbad->base.x - scroll_x,
+ pbad->base.y, 100);
}
pbad->dir = !pbad->dir;
break;
{
pbad->dying = SQUISHED;
timer_start(&pbad->timer,4000);
- pplayer_c->ym = -KILL_BOUNCE_YM;
+ pplayer_c->base.ym = -KILL_BOUNCE_YM;
- add_score(pbad->x - scroll_x, pbad->y,
+ add_score(pbad->base.x - scroll_x, pbad->base.y,
50 * score_multiplier);
play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
pbad->mode = FLAT;
- pbad->xm = 4;
+ pbad->base.xm = 4;
timer_start(&pbad->timer,10000);
- pplayer_c->y = pplayer_c->y - 32;
+ pplayer_c->base.y = pplayer_c->base.y - 32;
}
else
{
pbad->mode = KICK;
play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
- if (pplayer_c->x <= pbad->x)
+ if (pplayer_c->base.x <= pbad->base.x)
pbad->dir = RIGHT;
else
pbad->dir = LEFT;
timer_start(&pbad->timer,5000);
}
- pplayer_c->ym = -KILL_BOUNCE_YM;
+ pplayer_c->base.ym = -KILL_BOUNCE_YM;
- add_score(pbad->x - scroll_x,
- pbad->y,
+ add_score(pbad->base.x - scroll_x,
+ pbad->base.y,
25 * score_multiplier);
/* play_sound(sounds[SND_SQUISH]); */
#include "SDL.h"
#include "bitmask.h"
#include "type.h"
+#include "timer.h"
+#include "texture.h"
#include "collision.h"
-#define NUM_BAD_GUYS 128
-
/* Enemy modes: */
#define NORMAL 0
typedef struct bad_guy_type
{
- int alive;
int mode;
int dying;
int kind;
int seen;
int dir;
int frame;
- float x;
- float y;
- float xm;
- float ym;
- float width;
- float height;
- unsigned int updated;
- itop_type it;
+ base_type base;
timer_type timer;
}
bad_guy_type;
#include "bitmask.h"
#include "scene.h"
-int rectcollision(itop_type* one, itop_type* two)
+int rectcollision(base_type* one, base_type* two)
{
- if (*one->x >= *two->x - *one->width &&
- *one->x <= *two->x + *two->width &&
- *one->y >= *two->y - *one->height &&
- *one->y <= *two->y + *two->height )
+ if (one->x >= two->x - one->width &&
+ one->x <= two->x + two->width &&
+ one->y >= two->y - one->height &&
+ one->y <= two->y + two->height )
{
return YES;
}
}
}
-int rectcollision_offset(itop_type* one, itop_type* two, float off_x, float off_y)
+int rectcollision_offset(base_type* one, base_type* two, float off_x, float off_y)
{
- if (*one->x >= *two->x - *one->width +off_x &&
- *one->x <= *two->x + *two->width + off_x &&
- *one->y >= *two->y - *one->height + off_y &&
- *one->y <= *two->y + *two->height + off_y )
+ if (one->x >= two->x - one->width +off_x &&
+ one->x <= two->x + two->width + off_x &&
+ one->y >= two->y - one->height + off_y &&
+ one->y <= two->y + two->height + off_y )
{
return YES;
}
}
}
-void collision_rect_detect(int co_one, int co_two)
-{
- int i,j;
-
- /* CO_BULLET & CO_BADGUY check */
- for(i = 0; i < NUM_BULLETS; ++i)
- {
- if(bullets[i].alive)
- {
- for(j = 0; j < NUM_BAD_GUYS; ++j)
- {
- if(bad_guys[j].alive)
- {
- if(rectcollision(&bullets[i].it,&bad_guys[j].it) == YES)
- {
- /* We have detected a collision and now call the collision functions of the collided objects. */
- bullet_collision(&bullets[i], CO_BADGUY);
- badguy_collision(&bad_guys[j], &bullets[i], CO_BULLET);
- }
- }
- }
- }
- }
-}
-
void collision_handler()
{
int i,j;
/* CO_BULLET & CO_BADGUY check */
- for(i = 0; i < NUM_BULLETS; ++i)
+ for(i = 0; i < num_bullets; ++i)
{
- if(bullets[i].alive)
+ if(bullets[i].base.alive)
{
- for(j = 0; j < NUM_BAD_GUYS; ++j)
+ for(j = 0; j < num_bad_guys; ++j)
{
- if(bad_guys[j].alive)
+ if(bad_guys[j].dying == NO && bad_guys[j].base.alive)
{
- if(rectcollision(&bullets[i].it,&bad_guys[j].it) == YES)
+ if(rectcollision(&bullets[i].base,&bad_guys[j].base) == YES)
{
/* We have detected a collision and now call the collision functions of the collided objects. */
bullet_collision(&bullets[i], CO_BADGUY);
}
/* CO_BADGUY & CO_BADGUY check */
- for(i = 0; i < NUM_BAD_GUYS; ++i)
+ for(i = 0; i < num_bad_guys; ++i)
{
- if(bad_guys[i].alive)
+ if(bad_guys[i].base.alive)
{
- for(j = i+1; j < NUM_BAD_GUYS; ++j)
+ for(j = i+1; j < num_bad_guys; ++j)
{
- if(j != i && bad_guys[j].alive)
+ if(j != i && bad_guys[j].base.alive)
{
- if(rectcollision(&bad_guys[i].it,&bad_guys[j].it) == YES)
+ if(rectcollision(&bad_guys[i].base,&bad_guys[j].base) == YES)
{
/* We have detected a collision and now call the collision functions of the collided objects. */
badguy_collision(&bad_guys[j], &bad_guys[i], CO_BADGUY);
}
/* CO_BADGUY & CO_PLAYER check */
- for(i = 0; i < NUM_BAD_GUYS; ++i)
+ for(i = 0; i < num_bad_guys; ++i)
{
- if(bad_guys[i].alive)
+ if(bad_guys[i].base.alive)
{
- if(rectcollision_offset(&bad_guys[i].it,&tux.it,0,48) == YES && tux.ym < 0)
+ if(bad_guys[i].dying == NO && rectcollision_offset(&bad_guys[i].base,&tux.base,0,0) == YES && tux.base.ym > 0)
{
/* We have detected a collision and now call the collision functions of the collided objects. */
badguy_collision(&bad_guys[i], &tux, CO_PLAYER);
}
- if(rectcollision(&bad_guys[i].it,&tux.it) == YES)
+ if(rectcollision(&bad_guys[i].base,&tux.base) == YES)
{
player_collision(&tux, &bad_guys[i], CO_BADGUY);
}
}
/* CO_UPGRADE & CO_PLAYER check */
- for(i = 0; i < NUM_UPGRADES; ++i)
+ for(i = 0; i < num_upgrades; ++i)
{
- if(upgrades[i].alive)
+ if(upgrades[i].base.alive)
{
- if(rectcollision(&upgrades[i].it,&tux.it) == YES)
+ if(rectcollision(&upgrades[i].base,&tux.base) == YES)
{
/* We have detected a collision and now call the collision functions of the collided objects. */
upgrade_collision(&upgrades[i], &tux, CO_PLAYER);
CO_PLAYER
};
-int rectcollision(itop_type* one, itop_type* two);
-int rectcollision_offset(itop_type* one, itop_type* two, float off_x, float off_y);
+int rectcollision(base_type* one, base_type* two);
+int rectcollision_offset(base_type* one, base_type* two, float off_x, float off_y);
/* Checks for all possible collisions.
And calls the collision_handlers, which the collision_objects provide for this case (or not). */
#define SUPERTUX_DEFINES_H
/* Version: */
-#define VERSION "0.0.5"
+#define VERSION "0.0.5-0.0.6-CVS"
/* Frames per second: */
void activate_bad_guys(void)
{
int x,y;
-
+
/* Activate bad guys: */
for (y = 0; y < 15; y++)
{
if (current_level.tiles[y][x] >= '0' && current_level.tiles[y][x] <= '9')
{
- add_bad_guy(x * 32, y * 32, current_level.tiles[y][x] - '0');
+ add_bad_guy(x * 32, y * 32, current_level.tiles[y][x] - '0');
current_level.tiles[y][x] = '.';
}
}
unloadlevelgfx();
unloadlevelsong();
unloadshared();
+ arrays_free();
return(0);
} /* if (lives < 0) */
}
player_level_begin(&tux);
set_defaults();
loadlevel(¤t_level,"default",level);
+ arrays_free();
+ arrays_init();
activate_bad_guys();
unloadlevelgfx();
loadlevelgfx(¤t_level);
/* Handle bouncy distros: */
- for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
+ for (i = 0; i < num_bouncy_distros; i++)
{
bouncy_distro_action(&bouncy_distros[i]);
}
/* Handle broken bricks: */
- for (i = 0; i < NUM_BROKEN_BRICKS; i++)
+ for (i = 0; i < num_broken_bricks; i++)
{
broken_brick_action(&broken_bricks[i]);
}
/* Handle bouncy bricks: */
- for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
+ for (i = 0; i < num_bouncy_bricks; i++)
{
bouncy_brick_action(&bouncy_bricks[i]);
}
/* Handle floating scores: */
- for (i = 0; i < NUM_FLOATING_SCORES; i++)
+ for (i = 0; i < num_floating_scores; i++)
{
floating_score_action(&floating_scores[i]);
}
/* Handle bullets: */
- for (i = 0; i < NUM_BULLETS; ++i)
+ for (i = 0; i < num_bullets; ++i)
{
bullet_action(&bullets[i]);
}
/* Handle upgrades: */
- for (i = 0; i < NUM_UPGRADES; i++)
+ for (i = 0; i < num_upgrades; i++)
{
upgrade_action(&upgrades[i]);
- } /* for (i = 0; i < NUM_UPGRADES; i++) */
+ }
/* Handle bad guys: */
- for (i = 0; i < NUM_BAD_GUYS; i++)
+ for (i = 0; i < num_bad_guys; i++)
{
badguy_action(&bad_guys[i]);
}
/* (Bouncy bricks): */
- for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
+ for (i = 0; i < num_bouncy_bricks; i++)
{
bouncy_brick_draw(&bouncy_bricks[i]);
}
/* (Bad guys): */
- for (i = 0; i < NUM_BAD_GUYS; i++)
+ for (i = 0; i < num_bad_guys; i++)
{
badguy_draw(&bad_guys[i]);
}
/* (Bullets): */
- for (i = 0; i < NUM_BULLETS; i++)
+ for (i = 0; i < num_bullets; i++)
{
bullet_draw(&bullets[i]);
}
/* (Floating scores): */
- for (i = 0; i < NUM_FLOATING_SCORES; i++)
+ for (i = 0; i < num_floating_scores; i++)
{
floating_score_draw(&floating_scores[i]);
}
/* (Upgrades): */
- for (i = 0; i < NUM_UPGRADES; i++)
+ for (i = 0; i < num_upgrades; i++)
{
upgrade_draw(&upgrades[i]);
}
/* (Bouncy distros): */
- for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
+ for (i = 0; i < num_bouncy_distros; i++)
{
bouncy_distro_draw(&bouncy_distros[i]);
}
/* (Broken bricks): */
- for (i = 0; i < NUM_BROKEN_BRICKS; i++)
+ for (i = 0; i < num_broken_bricks; i++)
{
broken_brick_draw(&broken_bricks[i]);
}
/* Init the game: */
-
+ arrays_init();
+
initmenu();
menumenu = MENU_GAME;
initgame();
unloadlevelgfx();
unloadlevelsong();
unloadshared();
+ arrays_free();
return(quit);
}
/* Bad guys: */
- for (i = 0; i < NUM_BAD_GUYS; i++)
+ for (i = 0; i < num_bad_guys; i++)
{
- if (bad_guys[i].alive &&
- bad_guys[i].x >= x - 32 && bad_guys[i].x <= x + 32 &&
- bad_guys[i].y >= y - 16 && bad_guys[i].y <= y + 16)
+ if (bad_guys[i].base.alive &&
+ bad_guys[i].base.x >= x - 32 && bad_guys[i].base.x <= x + 32 &&
+ bad_guys[i].base.y >= y - 16 && bad_guys[i].base.y <= y + 16)
{
if (bad_guys[i].kind == BAD_BSOD ||
bad_guys[i].kind == BAD_LAPTOP)
{
bad_guys[i].dying = FALLING;
- bad_guys[i].ym = -8;
+ bad_guys[i].base.ym = -8;
play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
}
}
/* Upgrades: */
- for (i = 0; i < NUM_UPGRADES; i++)
+ for (i = 0; i < num_upgrades; i++)
{
- if (upgrades[i].alive && upgrades[i].height == 32 &&
- upgrades[i].x >= x - 32 && upgrades[i].x <= x + 32 &&
- upgrades[i].y >= y - 16 && upgrades[i].y <= y + 16)
+ if (upgrades[i].base.alive && upgrades[i].base.height == 32 &&
+ upgrades[i].base.x >= x - 32 && upgrades[i].base.x <= x + 32 &&
+ upgrades[i].base.y >= y - 16 && upgrades[i].base.y <= y + 16)
{
- upgrades[i].xm = -upgrades[i].xm;
- upgrades[i].ym = -8;
+ upgrades[i].base.xm = -upgrades[i].base.xm;
+ upgrades[i].base.ym = -8;
play_sound(sounds[SND_BUMP_UPGRADE], SOUND_CENTER_SPEAKER);
}
}
}
-
-/* Add an upgrade: */
-
-void add_upgrade(float x, float y, int kind)
-{
- int i, found;
-
- found = -1;
-
- for (i = 0; i < NUM_UPGRADES && found == -1; i++)
- {
- if (!upgrades[i].alive)
- found = i;
- }
-
- if (found != -1)
- {
- upgrades[found].alive = YES;
- upgrades[found].kind = kind;
- upgrades[found].x = x;
- upgrades[found].y = y;
- upgrades[found].xm = 2;
- upgrades[found].ym = -2;
- upgrades[found].height = 0;
- }
-}
-
-/* Add a bullet: */
-
-void add_bullet(float x, float y, float xm, int dir)
-{
- int i, found;
-
- printf("X: %f Y: %f -- YOOYOYOYO\n",x,y);
-
- found = -1;
-
- for (i = 0; i < NUM_BULLETS && found == -1; i++)
- {
- if (!bullets[i].alive)
- found = i;
- }
-
- if (found != -1)
- {
- bullets[found].alive = YES;
-
- if (dir == RIGHT)
- {
- bullets[found].x = x + 32;
- bullets[found].xm = BULLET_XM + xm;
- }
- else
- {
- bullets[found].x = x;
- bullets[found].xm = -BULLET_XM + xm;
- }
-
- bullets[found].y = y;
- bullets[found].ym = BULLET_STARTING_YM;
-
- play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
- }
-}
-
-
/* (Status): */
void drawstatus(void)
{
fwrite(&level,4,1,fi);
fwrite(&score,4,1,fi);
fwrite(&distros,4,1,fi);
- fwrite(&tux.x,4,1,fi);
- fwrite(&tux.y,4,1,fi);
+ fwrite(&tux.base.x,4,1,fi);
+ fwrite(&tux.base.y,4,1,fi);
fwrite(&scroll_x,4,1,fi);
fwrite(¤t_level.time_left,4,1,fi);
}
player_level_begin(&tux);
set_defaults();
loadlevel(¤t_level,"default",level);
+ arrays_free();
+ arrays_init();
activate_bad_guys();
unloadlevelgfx();
loadlevelgfx(¤t_level);
fread(&level,4,1,fi);
fread(&score,4,1,fi);
fread(&distros,4,1,fi);
- fread(&tux.x,4,1,fi);
- fread(&tux.y,4,1,fi);
+ fread(&tux.base.x,4,1,fi);
+ fread(&tux.base.y,4,1,fi);
fread(&scroll_x,4,1,fi);
fread(¤t_level.time_left,4,1,fi);
fclose(fi);
UPGRADE_HERRING
};
-/* Array sizes: */
-
-#define NUM_BOUNCY_DISTROS 8
-#define NUM_BROKEN_BRICKS 32
-#define NUM_BOUNCY_BRICKS 4
-#define NUM_FLOATING_SCORES 6
-#define NUM_UPGRADES 2
-
-
/* Scores: */
#define SCORE_BRICK 5
int isbrick(float x, float y);
int isice(float x, float y);
int isfullbox(float x, float y);
-int rectcollision(itop_type* one, itop_type* two);
+int rectcollision(base_type* one, base_type* two);
void drawshape(float x, float y, unsigned char c);
unsigned char shape(float x, float y);
void bumpbrick(float x, float y);
#include "globals.h"
#include "intro.h"
#include "screen.h"
-#include "type.h"
+#include "texture.h"
+#include "timer.h"
char * intro_text[] = {
"Tux and Gown were having a nice picnic..",
#ifndef SUPERTUX_LEVEL_H
#define SUPERTUX_LEVEL_H
-#include "type.h"
+#include "texture.h"
#define LEVEL_NAME_MAX 20
texture_type selection;
int last_time, now_time;
+void le_quit(void)
+{
+ unloadlevelgfx();
+ unloadshared();
+ arrays_free();
+ texture_free(&selection);
+}
+
void le_activate_bad_guys(void)
{
int x,y;
frame = 0; /* support for frames in some tiles, like waves and bad guys */
+ arrays_init();
+
loadshared();
set_defaults();
le_change(cursor_x, cursor_y, '=');
else /* let's add a bad guy */
le_change(cursor_x, cursor_y, '0');
-
- for(i = 0; i < NUM_BAD_GUYS; ++i)
- if (bad_guys[i].alive == NO)
- {
- bad_guys[i].alive = YES;
- bad_guys[i].kind = BAD_BSOD;
- bad_guys[i].x = (((int)cursor_x/32)*32);
- bad_guys[i].y = (((int)cursor_y/32)*32);
- i = NUM_BAD_GUYS;
- }
+
+ add_bad_guy((((int)cursor_x/32)*32), (((int)cursor_y/32)*32), BAD_BSOD);
break;
case SDLK_1:
if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
else /* let's add a bad guy */
le_change(cursor_x, cursor_y, '1');
- for(i = 0; i < NUM_BAD_GUYS; ++i)
- if (bad_guys[i].alive == NO)
- {
- bad_guys[i].alive = YES;
- bad_guys[i].kind = BAD_LAPTOP;
- bad_guys[i].x = (((int)cursor_x/32)*32);
- bad_guys[i].y = (((int)cursor_y/32)*32);
- i = NUM_BAD_GUYS;
- }
+ add_bad_guy((((int)cursor_x/32)*32), (((int)cursor_y/32)*32), BAD_LAPTOP);
break;
case SDLK_2:
le_change(cursor_x, cursor_y, '2');
- for(i = 0; i < NUM_BAD_GUYS; ++i)
- if (bad_guys[i].alive == NO)
- {
- bad_guys[i].alive = YES;
- bad_guys[i].kind = BAD_MONEY;
- bad_guys[i].x = (((int)cursor_x/32)*32);
- bad_guys[i].y = (((int)cursor_y/32)*32);
- i = NUM_BAD_GUYS;
- }
+ add_bad_guy((((int)cursor_x/32)*32), (((int)cursor_y/32)*32), BAD_MONEY);
break;
case SDLK_PLUS:
if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
drawshape(x * 32, y * 32, current_level.tiles[y][x + (pos_x / 32)]);
/* Draw the Bad guys: */
- for (i = 0; i < NUM_BAD_GUYS; ++i)
+ for (i = 0; i < num_bad_guys; ++i)
{
/* printf("\nbad_guys[%i].alive = %i", i, bad_guys[i].alive); */
- if(bad_guys[i].alive == NO)
+ if(bad_guys[i].base.alive == NO)
continue;
/* to support frames: img_bsod_left[(frame / 5) % 4] */
if(bad_guys[i].kind == BAD_BSOD)
- texture_draw(&img_bsod_left[(frame / 5) % 4], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE);
+ texture_draw(&img_bsod_left[(frame / 5) % 4], ((int)(bad_guys[i].base.x - pos_x)/32)*32, bad_guys[i].base.y, NO_UPDATE);
else if(bad_guys[i].kind == BAD_LAPTOP)
- texture_draw(&img_laptop_left[(frame / 5) % 3], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE);
+ texture_draw(&img_laptop_left[(frame / 5) % 3], ((int)(bad_guys[i].base.x - pos_x)/32)*32, bad_guys[i].base.y, NO_UPDATE);
else if (bad_guys[i].kind == BAD_MONEY)
- texture_draw(&img_money_left[(frame / 5) % 2], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE);
+ texture_draw(&img_money_left[(frame / 5) % 2], ((int)(bad_guys[i].base.x - pos_x)/32)*32, bad_guys[i].base.y, NO_UPDATE);
}
{
done = drawmenu();
if(done)
+ {
+ le_quit();
return 0;
+ }
}
if(done == DONE_QUIT)
+ {
+ le_quit();
return 1;
+ }
SDL_Delay(50);
now_time = SDL_GetTicks();
flipscreen();
}
- unloadlevelgfx();
- unloadshared();
-
- texture_free(&selection);
-
return done;
}
xx = (x / 32);
/* if there is a bad guy over there, remove it */
- for(i = 0; i < NUM_BAD_GUYS; ++i)
- if (bad_guys[i].alive)
- if(xx == bad_guys[i].x/32 && yy == bad_guys[i].y/32)
- bad_guys[i].alive = NO;
+ for(i = 0; i < num_bad_guys; ++i)
+ if (bad_guys[i].base.alive)
+ if(xx == bad_guys[i].base.x/32 && yy == bad_guys[i].base.y/32)
+ bad_guys[i].base.alive = NO;
}
/* Save data for this level: */
void player_init(player_type* pplayer)
{
- pplayer->it.alive = NULL;
- pplayer->it.x = &pplayer->x;
- pplayer->it.y = &pplayer->y;
- pplayer->it.width = &pplayer->width;
- pplayer->it.height = &pplayer->height;
- pplayer->it.updated = &pplayer->updated;
+ pplayer->base.width = 32;
+ pplayer->base.height = 32;
- pplayer->width = 32;
- pplayer->height = 32;
-
- pplayer->updated = SDL_GetTicks();
+ pplayer->base.updated = SDL_GetTicks();
pplayer->size = SMALL;
pplayer->got_coffee = NO;
- pplayer->x = 0;
- pplayer->xm = 0;
- pplayer->y = 240;
- pplayer->ym = 0;
+ pplayer->base.x = 0;
+ pplayer->base.y = 240;
+ pplayer->base.xm = 0;
+ pplayer->base.ym = 0;
pplayer->dir = RIGHT;
pplayer->duck = NO;
void player_level_begin(player_type* pplayer)
{
- pplayer->x = 0;
- pplayer->xm = 0;
- pplayer->y = 240;
- pplayer->ym = 0;
+ pplayer->base.x = 0;
+ pplayer->base.y = 240;
+ pplayer->base.xm = 0;
+ pplayer->base.ym = 0;
}
void player_action(player_type* pplayer)
{
- double frame_ratio = get_frame_ratio(&pplayer->it);
+ double frame_ratio = get_frame_ratio(&pplayer->base);
/* --- HANDLE TUX! --- */
/* Move tux: */
- pplayer->x = pplayer->x + pplayer->xm * frame_ratio;
- pplayer->y = pplayer->y + pplayer->ym * frame_ratio;
+ pplayer->base.x= pplayer->base.x+ pplayer->base.xm * frame_ratio;
+ pplayer->base.y = pplayer->base.y + pplayer->base.ym * frame_ratio;
player_keep_in_bounds(pplayer);
if (!pplayer->dying)
{
- if (issolid(pplayer->x, pplayer->y + 31) &&
- !issolid(pplayer->x - pplayer->xm, pplayer->y + 31))
+ if (issolid(pplayer->base.x, pplayer->base.y + 31) &&
+ !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y + 31))
{
- while (issolid(pplayer->x, pplayer->y + 31))
+ while (issolid(pplayer->base.x, pplayer->base.y + 31))
{
- if (pplayer->xm < 0)
- pplayer->x++;
- else if (pplayer->xm > 0)
- pplayer->x--;
+ if (pplayer->base.xm < 0)
+ pplayer->base.x++;
+ else if (pplayer->base.xm > 0)
+ pplayer->base.x--;
}
- pplayer->xm = 0;
+ pplayer->base.xm = 0;
}
- if (issolid(pplayer->x, pplayer->y) &&
- !issolid(pplayer->x - pplayer->xm, pplayer->y))
+ if (issolid(pplayer->base.x, pplayer->base.y) &&
+ !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y))
{
- while (issolid(pplayer->x, (pplayer->y)))
+ while (issolid(pplayer->base.x, (pplayer->base.y)))
{
- if (pplayer->xm < 0)
- pplayer->x++;
- else if (pplayer->xm > 0)
- pplayer->x--;
+ if (pplayer->base.xm < 0)
+ pplayer->base.x++;
+ else if (pplayer->base.xm > 0)
+ pplayer->base.x--;
}
- pplayer->xm = 0;
+ pplayer->base.xm = 0;
}
- if (issolid(pplayer->x, pplayer->y + 31))
+ if (issolid(pplayer->base.x, pplayer->base.y + 31))
{
/* Set down properly: */
int debug_int = 0;
- while (issolid(pplayer->x, pplayer->y + 31))
+ 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!");
- if (pplayer->ym < 0)
- pplayer->y++;
- else if (pplayer->ym > 0)
- pplayer->y--;
+ 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->ym > 0)
+ if (pplayer->base.ym > 0)
score_multiplier = 1;
/* Stop jumping! */
- pplayer->ym = 0;
+ pplayer->base.ym = 0;
pplayer->jumping = NO;
}
/* Bump into things: */
- if (issolid(pplayer->x, pplayer->y) ||
+ if (issolid(pplayer->base.x, pplayer->base.y) ||
(pplayer->size == BIG && !pplayer->duck &&
- (issolid(pplayer->x, pplayer->y - 32))))
+ (issolid(pplayer->base.x, pplayer->base.y - 32))))
{
- if (!issolid(pplayer->x - pplayer->xm, pplayer->y) &&
+ if (!issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y) &&
(pplayer->size == SMALL || pplayer->duck ||
- !issolid(pplayer->x - pplayer->xm, pplayer->y - 32)))
+ !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32)))
{
- pplayer->x = pplayer->x - pplayer->xm;
- pplayer->xm = 0;
+ pplayer->base.x = pplayer->base.x- pplayer->base.xm;
+ pplayer->base.xm = 0;
}
- else if (!issolid(pplayer->x, pplayer->y - pplayer->ym) &&
+ else if (!issolid(pplayer->base.x, pplayer->base.y - pplayer->base.ym) &&
(pplayer->size == SMALL || pplayer->duck ||
- !issolid(pplayer->x, pplayer->y - 32 - pplayer->ym)))
+ !issolid(pplayer->base.x, pplayer->base.y - 32 - pplayer->base.ym)))
{
- if (pplayer->ym <= 0)
+ if (pplayer->base.ym <= 0)
{
/* Jumping up? */
if (!pplayer->duck)
{
- if (isbrick(pplayer->x, pplayer->y - 32) ||
- isfullbox(pplayer->x, pplayer->y - 32))
+ if (isbrick(pplayer->base.x, pplayer->base.y - 32) ||
+ isfullbox(pplayer->base.x, pplayer->base.y - 32))
{
- trygrabdistro(pplayer->x, pplayer->y - 64, BOUNCE);
- trybumpbadguy(pplayer->x, pplayer->y - 96);
+ trygrabdistro(pplayer->base.x, pplayer->base.y - 64, BOUNCE);
+ trybumpbadguy(pplayer->base.x, pplayer->base.y - 96);
- if (isfullbox(pplayer->x, pplayer->y - 32))
+ if (isfullbox(pplayer->base.x, pplayer->base.y - 32))
{
- bumpbrick(pplayer->x, pplayer->y - 32);
+ bumpbrick(pplayer->base.x, pplayer->base.y - 32);
}
- trybreakbrick(pplayer->x, pplayer->y - 32);
- tryemptybox(pplayer->x, pplayer->y - 32);
+ trybreakbrick(pplayer->base.x, pplayer->base.y - 32);
+ tryemptybox(pplayer->base.x, pplayer->base.y - 32);
}
- if (isbrick(pplayer->x + 31, pplayer->y - 32) ||
- isfullbox(pplayer->x + 31, pplayer->y - 32))
+ if (isbrick(pplayer->base.x+ 31, pplayer->base.y - 32) ||
+ isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32))
{
- trygrabdistro(pplayer->x + 31,
- pplayer->y - 64,
+ trygrabdistro(pplayer->base.x+ 31,
+ pplayer->base.y - 64,
BOUNCE);
- trybumpbadguy(pplayer->x + 31,
- pplayer->y - 96);
+ trybumpbadguy(pplayer->base.x+ 31,
+ pplayer->base.y - 96);
- if (isfullbox(pplayer->x + 31, pplayer->y - 32))
+ if (isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32))
{
- bumpbrick(pplayer->x + 31, pplayer->y - 32);
+ bumpbrick(pplayer->base.x+ 31, pplayer->base.y - 32);
}
- trybreakbrick(pplayer->x + 31,
- pplayer->y - 32);
- tryemptybox(pplayer->x + 31,
- pplayer->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->x, pplayer->y) ||
- isfullbox(pplayer->x, pplayer->y))
+ if (isbrick(pplayer->base.x, pplayer->base.y) ||
+ isfullbox(pplayer->base.x, pplayer->base.y))
{
- trygrabdistro(pplayer->x, pplayer->y - 32,BOUNCE);
- trybumpbadguy(pplayer->x, pplayer->y - 64);
- if (isfullbox(pplayer->x, pplayer->y))
- bumpbrick(pplayer->x, pplayer->y);
- trybreakbrick(pplayer->x, pplayer->y);
- tryemptybox(pplayer->x, pplayer->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->x + 31, pplayer->y) ||
- isfullbox(pplayer->x + 31, pplayer->y))
+ if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
+ isfullbox(pplayer->base.x+ 31, pplayer->base.y))
{
- trygrabdistro(pplayer->x + 31,
- pplayer->y - 32,
+ trygrabdistro(pplayer->base.x+ 31,
+ pplayer->base.y - 32,
BOUNCE);
- trybumpbadguy(pplayer->x + 31,
- pplayer->y - 64);
- if (isfullbox(pplayer->x + 31, pplayer->y))
- bumpbrick(pplayer->x + 31, pplayer->y);
- trybreakbrick(pplayer->x + 31, pplayer->y);
- tryemptybox(pplayer->x + 31, pplayer->y);
+ 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);
}
}
}
/* It's a brick and we're small, make the brick
bounce, and grab any distros above it: */
- if (isbrick(pplayer->x, pplayer->y) ||
- isfullbox(pplayer->x, pplayer->y))
+ if (isbrick(pplayer->base.x, pplayer->base.y) ||
+ isfullbox(pplayer->base.x, pplayer->base.y))
{
- trygrabdistro(pplayer->x, pplayer->y - 32,BOUNCE);
- trybumpbadguy(pplayer->x, pplayer->y - 64);
- bumpbrick(pplayer->x, pplayer->y);
- tryemptybox(pplayer->x, pplayer->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->x + 31, pplayer->y) ||
- isfullbox(pplayer->x + 31, pplayer->y))
+ if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
+ isfullbox(pplayer->base.x+ 31, pplayer->base.y))
{
- trygrabdistro(pplayer->x + 31, pplayer->y - 32,BOUNCE);
- trybumpbadguy(pplayer->x + 31, pplayer->y - 64);
- bumpbrick(pplayer->x + 31, pplayer->y);
- tryemptybox(pplayer->x + 31, pplayer->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->x, pplayer->y) == 'x' ||
- shape(pplayer->x, pplayer->y) == 'y')
+ if (shape(pplayer->base.x, pplayer->base.y) == 'x' ||
+ shape(pplayer->base.x, pplayer->base.y) == 'y')
{
- add_bouncy_distro(((pplayer->x + 1)
+ add_bouncy_distro(((pplayer->base.x+ 1)
/ 32) * 32,
- (int)(pplayer->y / 32) * 32);
+ (int)(pplayer->base.y / 32) * 32);
if (counting_distros == NO)
{
}
if (distro_counter <= 0)
- level_change(¤t_level,pplayer->x, pplayer->y, 'a');
+ 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->x + 31, pplayer->y) == 'x' ||
- shape(pplayer->x + 31, pplayer->y) == 'y')
+ else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' ||
+ shape(pplayer->base.x+ 31, pplayer->base.y) == 'y')
{
- add_bouncy_distro(((pplayer->x + 1 + 31)
+ add_bouncy_distro(((pplayer->base.x+ 1 + 31)
/ 32) * 32,
- (int)(pplayer->y / 32) * 32);
+ (int)(pplayer->base.y / 32) * 32);
if (counting_distros == NO)
{
}
if (distro_counter <= 0)
- level_change(¤t_level,pplayer->x + 31 + scroll_x, pplayer->y, 'a');
+ level_change(¤t_level,pplayer->base.x+ 31 + scroll_x, pplayer->base.y, 'a');
play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
score = score + SCORE_DISTRO;
/* Bump head: */
- pplayer->y = (int)(pplayer->y / 32) * 32 + 30;
+ pplayer->base.y = (int)(pplayer->base.y / 32) * 32 + 30;
}
else
{
/* Land on feet: */
- pplayer->y = (int)(pplayer->y / 32) * 32 - 32;
+ pplayer->base.y = (int)(pplayer->base.y / 32) * 32 - 32;
}
- pplayer->ym = 0;
+ pplayer->base.ym = 0;
pplayer->jumping = NO;
/*pplayer->jump_counter = MAX_JUMP_COUNT;*/
/*timer_init(&pplayer->jump_timer);*/
{
if (pplayer->input.right == UP && pplayer->input.left == UP)
{
- if (isice(pplayer->x, pplayer->y + 32) ||
- !issolid(pplayer->x, pplayer->y + 32))
+ 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->xm > 0)
- pplayer->xm--;
- else if (pplayer->xm < 0)
- pplayer->xm++;
+ if (pplayer->base.xm > 0)
+ pplayer->base.xm--;
+ else if (pplayer->base.xm < 0)
+ pplayer->base.xm++;
}
else
{
/* Quickly, otherwise: */
- pplayer->xm = pplayer->xm / 2;
+ pplayer->base.xm = pplayer->base.xm / 2;
}
}
/* Drop vertically: */
- if (!issolid(pplayer->x, pplayer->y + 32))
+ if (!issolid(pplayer->base.x, pplayer->base.y + 32))
{
- pplayer->ym = pplayer->ym + GRAVITY;
+ pplayer->base.ym = pplayer->base.ym + GRAVITY;
- if (pplayer->ym > MAX_YM)
- pplayer->ym = MAX_YM;
+ if (pplayer->base.ym > MAX_YM)
+ pplayer->base.ym = MAX_YM;
}
}
/* End of level? */
- if (pplayer->x >= endpos && endpos != 0)
+ if (pplayer->base.x>= endpos && endpos != 0)
{
next_level = 1;
}
{
if (pplayer->jumping == NO)
{
- if (pplayer->xm < -SKID_XM && !pplayer->skidding &&
+ if (pplayer->base.xm < -SKID_XM && !pplayer->skidding &&
pplayer->dir == LEFT)
{
pplayer->skidding = SKID_TIME;
pplayer->dir = RIGHT;
}
- if (pplayer->xm < 0 && !isice(pplayer->x, pplayer->y + 32) &&
+ if (pplayer->base.xm < 0 && !isice(pplayer->base.x, pplayer->base.y + 32) &&
!pplayer->skidding)
{
- pplayer->xm = 0;
+ pplayer->base.xm = 0;
}
if (!pplayer->duck)
if (pplayer->input.fire == UP)
{
- pplayer->xm = pplayer->xm + RUN_SPEED;
+ pplayer->base.xm = pplayer->base.xm + RUN_SPEED;
- if (pplayer->xm > MAX_RUN_XM)
- pplayer->xm = MAX_RUN_XM;
+ if (pplayer->base.xm > MAX_RUN_XM)
+ pplayer->base.xm = MAX_RUN_XM;
}
else if ( pplayer->input.fire == DOWN)
{
- pplayer->xm = pplayer->xm + WALK_SPEED;
+ pplayer->base.xm = pplayer->base.xm + WALK_SPEED;
- if (pplayer->xm > MAX_WALK_XM)
- pplayer->xm = MAX_WALK_XM;
+ if (pplayer->base.xm > MAX_WALK_XM)
+ pplayer->base.xm = MAX_WALK_XM;
}
}
else
/* Not facing the direction we're jumping?
Go half-speed: */
- pplayer->xm = pplayer->xm + WALK_SPEED / 2;
+ pplayer->base.xm = pplayer->base.xm + WALK_SPEED / 2;
- if (pplayer->xm > MAX_WALK_XM / 2)
- pplayer->xm = MAX_WALK_XM / 2;
+ if (pplayer->base.xm > MAX_WALK_XM / 2)
+ pplayer->base.xm = MAX_WALK_XM / 2;
}
}
}
{
if (pplayer->jumping == NO)
{
- if (pplayer->xm > SKID_XM && !pplayer->skidding &&
+ if (pplayer->base.xm > SKID_XM && !pplayer->skidding &&
pplayer->dir == RIGHT)
{
pplayer->skidding = SKID_TIME;
pplayer->dir = LEFT;
}
- if (pplayer->xm > 0 && !isice(pplayer->x, pplayer->y + 32) &&
+ if (pplayer->base.xm > 0 && !isice(pplayer->base.x, pplayer->base.y + 32) &&
!pplayer->skidding)
{
- pplayer->xm = 0;
+ pplayer->base.xm = 0;
}
if (!pplayer->duck)
if (pplayer->input.fire == UP)
{
- pplayer->xm = pplayer->xm - RUN_SPEED;
+ pplayer->base.xm = pplayer->base.xm - RUN_SPEED;
- if (pplayer->xm < -MAX_RUN_XM)
- pplayer->xm = -MAX_RUN_XM;
+ if (pplayer->base.xm < -MAX_RUN_XM)
+ pplayer->base.xm = -MAX_RUN_XM;
}
else if (pplayer->input.fire == DOWN)
{
- pplayer->xm = pplayer->xm - WALK_SPEED;
+ pplayer->base.xm = pplayer->base.xm - WALK_SPEED;
- if (pplayer->xm < -MAX_WALK_XM)
- pplayer->xm = -MAX_WALK_XM;
+ if (pplayer->base.xm < -MAX_WALK_XM)
+ pplayer->base.xm = -MAX_WALK_XM;
}
}
else
/* Not facing the direction we're jumping?
Go half-speed: */
- pplayer->xm = pplayer->xm - WALK_SPEED / 2;
+ pplayer->base.xm = pplayer->base.xm - WALK_SPEED / 2;
- if (pplayer->xm < -MAX_WALK_XM / 2)
- pplayer->xm = -MAX_WALK_XM / 2;
+ if (pplayer->base.xm < -MAX_WALK_XM / 2)
+ pplayer->base.xm = -MAX_WALK_XM / 2;
}
}
}
/* Taking off? */
- if (!issolid(pplayer->x, pplayer->y + 32) ||
- pplayer->ym != 0)
+ 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! */
/* Make sure we're not standing back up into a solid! */
if (pplayer->size == SMALL || pplayer->duck == NO ||
- !issolid(pplayer->x, pplayer->y))
+ !issolid(pplayer->base.x, pplayer->base.y))
{
pplayer->jumping = YES;
if (timer_check(&pplayer->jump_timer))
{
- pplayer->ym = pplayer->ym - JUMP_SPEED;
+ pplayer->base.ym = pplayer->base.ym - JUMP_SPEED;
}
}
else
if (pplayer->input.fire == DOWN && pplayer->input.old_fire == UP && pplayer->got_coffee)
{
- add_bullet(pplayer->x, pplayer->y, pplayer->xm, pplayer->dir);
+ add_bullet(pplayer->base.x, pplayer->base.y, pplayer->base.xm, pplayer->dir);
}
{
/* Make sure we're not standing back up into a solid! */
- if (!issolid(pplayer->x, pplayer->y - 32))
+ if (!issolid(pplayer->base.x, pplayer->base.y - 32))
pplayer->duck = NO;
}
else
/* Grab distros: */
if (!pplayer->dying)
{
- trygrabdistro(pplayer->x , pplayer->y, NO_BOUNCE);
- trygrabdistro(pplayer->x + 31, pplayer->y, NO_BOUNCE);
+ 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->x, pplayer->y - 32, NO_BOUNCE);
- trygrabdistro(pplayer->x + 31, pplayer->y - 32, NO_BOUNCE);
+ trygrabdistro(pplayer->base.x, pplayer->base.y - 32, NO_BOUNCE);
+ trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32, NO_BOUNCE);
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&cape_right[frame % 2],
- pplayer->x - scroll_x, pplayer->y,
+ pplayer->base.x- scroll_x, pplayer->base.y,
NO_UPDATE);
}
else
{
texture_draw(&cape_left[frame % 2],
- pplayer->x - scroll_x, pplayer->y,
+ pplayer->base.x- scroll_x, pplayer->base.y,
NO_UPDATE);
}
}
{
if (pplayer->dir == RIGHT)
{
- texture_draw(&tux_right[pplayer->frame], pplayer->x - scroll_x, pplayer->y, NO_UPDATE);
+ texture_draw(&tux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
}
else
{
- texture_draw(&tux_left[pplayer->frame], pplayer->x - scroll_x, pplayer->y, NO_UPDATE);
+ texture_draw(&tux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
}
}
else
if (pplayer->dir == RIGHT)
{
- texture_draw(&firetux_right[pplayer->frame], pplayer->x - scroll_x, pplayer->y, NO_UPDATE);
+ texture_draw(&firetux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
}
else
{
- texture_draw(&firetux_left[pplayer->frame], pplayer->x - scroll_x, pplayer->y, NO_UPDATE);
+ texture_draw(&firetux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
}
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&bigcape_right[frame % 2],
- pplayer->x - scroll_x - 8 - 16, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8 - 16, pplayer->base.y - 32,
NO_UPDATE);
}
else
{
texture_draw(&bigcape_left[frame % 2],
- pplayer->x -scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x-scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
}
{
if (!pplayer->skidding)
{
- if (!pplayer->jumping || pplayer->ym > 0)
+ if (!pplayer->jumping || pplayer->base.ym > 0)
{
if (pplayer->dir == RIGHT)
{
texture_draw(&bigtux_right[pplayer->frame],
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
else
{
texture_draw(&bigtux_left[pplayer->frame],
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&bigtux_right_jump,
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
else
{
texture_draw(&bigtux_left_jump,
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&skidtux_right,
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
else
{
texture_draw(&skidtux_left,
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
}
{
if (pplayer->dir == RIGHT)
{
- texture_draw(&ducktux_right, pplayer->x - scroll_x - 8, pplayer->y - 16,
+ texture_draw(&ducktux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
NO_UPDATE);
}
else
{
- texture_draw(&ducktux_left, pplayer->x - scroll_x - 8, pplayer->y - 16,
+ texture_draw(&ducktux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
NO_UPDATE);
}
}
{
if (!pplayer->skidding)
{
- if (!pplayer->jumping || pplayer->ym > 0)
+ if (!pplayer->jumping || pplayer->base.ym > 0)
{
if (pplayer->dir == RIGHT)
{
texture_draw(&bigfiretux_right[pplayer->frame],
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
else
{
texture_draw(&bigfiretux_left[pplayer->frame],
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&bigfiretux_right_jump,
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
else
{
texture_draw(&bigfiretux_left_jump,
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
}
if (pplayer->dir == RIGHT)
{
texture_draw(&skidfiretux_right,
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
else
{
texture_draw(&skidfiretux_left,
- pplayer->x - scroll_x - 8, pplayer->y - 32,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
NO_UPDATE);
}
}
{
if (pplayer->dir == RIGHT)
{
- texture_draw(&duckfiretux_right, pplayer->x - scroll_x - 8, pplayer->y - 16,
+ texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
NO_UPDATE);
}
else
{
- texture_draw(&duckfiretux_left, pplayer->x - scroll_x - 8, pplayer->y - 16,
+ texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
NO_UPDATE);
}
}
pbad_c->mode = KICK;
play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
- if (pplayer->x <= pbad_c->x)
+ if (pplayer->base.x<= pbad_c->base.x)
{
pbad_c->dir = RIGHT;
- pbad_c->x = pbad_c->x + 16;
+ pbad_c->base.x = pbad_c->base.x + 16;
}
else
{
pbad_c->dir = LEFT;
- pbad_c->x = pbad_c->x - 16;
+ pbad_c->base.x = pbad_c->base.x - 16;
}
timer_start(&pbad_c->timer,5000);
else if (pbad_c->mode == FLAT && pplayer->input.fire == DOWN)
{
pbad_c->mode = HELD;
- pbad_c->y-=8;
+ pbad_c->base.y-=8;
}
else if (pbad_c->mode == KICK)
{
- if (pplayer->y < pbad_c->y - 16 &&
+ if (pplayer->base.y < pbad_c->base.y - 16 &&
timer_started(&pbad_c->timer))
{
/* Step on (stop being kicked) */
else
{
pbad_c->dying = FALLING;
- pbad_c->ym = -8;
+ pbad_c->base.ym = -8;
play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
}
}
else
{
pbad_c->dying = FALLING;
- pbad_c->ym = -8;
+ pbad_c->base.ym = -8;
play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
}
}
void player_kill(player_type* pplayer, int mode)
{
- pplayer->ym = -5;
+ pplayer->base.ym = -5;
play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER);
if (pplayer->dir == RIGHT)
- pplayer->xm = -8;
+ pplayer->base.xm = -8;
else if (tux.dir == LEFT)
- pplayer->xm = 8;
+ pplayer->base.xm = 8;
if (mode == SHRINK && pplayer->size == BIG)
{
void player_dying(player_type *pplayer)
{
- pplayer->ym = pplayer->ym + GRAVITY;
+ pplayer->base.ym = pplayer->base.ym + GRAVITY;
/* He died :^( */
void player_keep_in_bounds(player_type* pplayer)
{
/* Keep tux in bounds: */
- if (pplayer->x < 0)
- pplayer->x = 0;
- else if(pplayer->x < scroll_x)
- pplayer->x = scroll_x;
- else if (pplayer->x < 160 + scroll_x && scroll_x > 0 && debug_mode == YES)
+ if (pplayer->base.x< 0)
+ pplayer->base.x= 0;
+ else if(pplayer->base.x< scroll_x)
+ pplayer->base.x= scroll_x;
+ else if (pplayer->base.x< 160 + scroll_x && scroll_x > 0 && debug_mode == YES)
{
- scroll_x = pplayer->x - 160;
- /*pplayer->x += 160;*/
+ scroll_x = pplayer->base.x- 160;
+ /*pplayer->base.x+= 160;*/
if(scroll_x < 0)
scroll_x = 0;
}
- else if (pplayer->x > screen->w / 2 + scroll_x && scroll_x < ((current_level.width * 32) - screen->w))
+ else if (pplayer->base.x> screen->w / 2 + scroll_x && scroll_x < ((current_level.width * 32) - screen->w))
{
/* Scroll the screen in past center: */
- scroll_x = pplayer->x - screen->w / 2;
- /*pplayer->x = 320 + scroll_x;*/
+ scroll_x = pplayer->base.x- screen->w / 2;
+ /*pplayer->base.x= 320 + scroll_x;*/
if (scroll_x > ((current_level.width * 32) - screen->w))
scroll_x = ((current_level.width * 32) - screen->w);
}
- else if (pplayer->x > 608 + scroll_x)
+ else if (pplayer->base.x> 608 + scroll_x)
{
/* ... unless there's no more to scroll! */
- /*pplayer->x = 608 + scroll_x;*/
+ /*pplayer->base.x= 608 + scroll_x;*/
}
/* Keep in-bounds, vertically: */
- if (pplayer->y < 0)
- pplayer->y = 0;
- else if (pplayer->y > screen->h)
+ if (pplayer->base.y < 0)
+ pplayer->base.y = 0;
+ else if (pplayer->base.y > screen->h)
{
player_kill(&tux,KILL);
}
#include <SDL.h>
#include "bitmask.h"
#include "type.h"
+#include "timer.h"
+#include "texture.h"
#include "collision.h"
/* Times: */
int frame_main;
int frame;
int lives;
- float x;
- float y;
- float xm;
- float ym;
- float width;
- float height;
+ base_type base;
timer_type invincible_timer;
timer_type jump_timer;
- unsigned int updated;
- itop_type it;
}
player_type;
//
//
+#include <stdlib.h>
#include "scene.h"
+/* Initialize all 'dynamic' arrays */
+void arrays_init(void)
+{
+num_bad_guys = 0;
+num_bouncy_distros = 0;
+num_broken_bricks = 0;
+num_bouncy_bricks = 0;
+num_floating_scores = 0;
+num_upgrades = 0;
+num_bullets = 0;
+bad_guys = NULL;
+bouncy_distros = NULL;
+broken_bricks = NULL;
+bouncy_bricks = NULL;
+floating_scores = NULL;
+upgrades = NULL;
+bullets = NULL;
+}
+
+/* Free memory of 'dynamic' arrays */
+void arrays_free(void)
+{
+free(bad_guys);
+free(bouncy_distros);
+free(broken_bricks);
+free(bouncy_bricks);
+free(floating_scores);
+free(upgrades);
+free(bullets);
+}
+
void set_defaults(void)
{
int i;
/* Reset arrays: */
- for (i = 0; i < NUM_BOUNCY_DISTROS; i++)
- bouncy_distros[i].alive = NO;
-
- for (i = 0; i < NUM_BROKEN_BRICKS; i++)
- broken_bricks[i].alive = NO;
+ for (i = 0; i < num_bouncy_distros; i++)
+ bouncy_distros[i].base.alive = NO;
- for (i = 0; i < NUM_BOUNCY_BRICKS; i++)
- bouncy_bricks[i].alive = NO;
+ for (i = 0; i < num_broken_bricks; i++)
+ broken_bricks[i].base.alive = NO;
- for (i = 0; i < NUM_BAD_GUYS; i++)
+ for (i = 0; i < num_bouncy_bricks; i++)
+ bouncy_bricks[i].base.alive = NO;
+
+ for (i = 0; i < num_bad_guys; i++)
{
/*bad_guys[i].alive = NO;*/
badguy_init(&bad_guys[i]);
}
- for (i = 0; i < NUM_FLOATING_SCORES; i++)
- floating_scores[i].alive = NO;
+ for (i = 0; i < num_floating_scores; i++)
+ floating_scores[i].base.alive = NO;
- for (i = 0; i < NUM_UPGRADES; i++)
+ for (i = 0; i < num_upgrades; i++)
{
/*upgrades[i].alive = NO;*/
upgrade_init(&upgrades[i]);
}
- for (i = 0; i < NUM_BULLETS; i++)
+ for (i = 0; i < num_bullets; i++)
{
/*bullets[i].alive = NO;*/
bullet_init(&bullets[i]);
found = -1;
- for (i = 0; i < NUM_FLOATING_SCORES && found == -1; i++)
+ for (i = 0; i < num_floating_scores && found == -1; i++)
{
- if (!floating_scores[i].alive)
+ if (!floating_scores[i].base.alive)
found = i;
}
-
+
+ if (found == -1)
+ {
+ ++num_floating_scores;
+ floating_scores = realloc(floating_scores,num_floating_scores*sizeof(floating_score_type));
+ floating_score_init(&floating_scores[num_floating_scores-1],x,y,s);
+ found = -1;
+ }
if (found != -1)
{
- floating_score_init(&floating_scores[i],x,y,s);
+ floating_score_init(&floating_scores[found],x,y,s);
}
}
found = -1;
- for (i = 0; i < NUM_BOUNCY_DISTROS && found == -1; i++)
+ for (i = 0; i < num_bouncy_distros && found == -1; i++)
{
- if (!bouncy_distros[i].alive)
+ if (!bouncy_distros[i].base.alive)
found = i;
}
-
+
+ if (found == -1)
+ {
+ ++num_bouncy_distros;
+ bouncy_distros = realloc(bouncy_distros,num_bouncy_distros*sizeof(bouncy_distro_type));
+ found = num_bouncy_distros - 1;
+ }
+
if (found != -1)
{
- bouncy_distros[found].alive = YES;
- bouncy_distros[found].x = x;
- bouncy_distros[found].y = y;
- bouncy_distros[found].ym = -6;
+ bouncy_distros[found].base.alive = YES;
+ bouncy_distros[found].base.x = x;
+ bouncy_distros[found].base.y = y;
+ bouncy_distros[found].base.ym = -6;
}
}
found = -1;
- for (i = 0; i < NUM_BROKEN_BRICKS && found == -1; i++)
+ for (i = 0; i < num_broken_bricks && found == -1; i++)
{
- if (!broken_bricks[i].alive)
+ if (!broken_bricks[i].base.alive)
found = i;
}
+ if (found == -1)
+ {
+ ++num_broken_bricks;
+ broken_bricks = realloc(broken_bricks,num_broken_bricks*sizeof(broken_brick_type));
+ found = num_broken_bricks - 1;
+ }
+
if (found != -1)
{
- broken_bricks[found].alive = YES;
- broken_bricks[found].x = x;
- broken_bricks[found].y = y;
- broken_bricks[found].xm = xm;
- broken_bricks[found].ym = ym;
+ broken_bricks[found].base.alive = YES;
+ broken_bricks[found].base.x = x;
+ broken_bricks[found].base.y = y;
+ broken_bricks[found].base.xm = xm;
+ broken_bricks[found].base.ym = ym;
}
}
found = -1;
- for (i = 0; i < NUM_BOUNCY_BRICKS && found == -1; i++)
+ for (i = 0; i < num_bouncy_bricks && found == -1; i++)
{
- if (!bouncy_bricks[i].alive)
+ if (!bouncy_bricks[i].base.alive)
found = i;
}
+
+ if (found == -1)
+ {
+ ++num_bouncy_bricks;
+ bouncy_bricks = realloc(bouncy_bricks,num_bouncy_bricks*sizeof(bouncy_brick_type));
+ found = num_bouncy_bricks - 1;
+ }
if (found != -1)
{
- bouncy_bricks[found].alive = YES;
- bouncy_bricks[found].x = x;
- bouncy_bricks[found].y = y;
+ bouncy_bricks[found].base.alive = YES;
+ bouncy_bricks[found].base.x = x;
+ bouncy_bricks[found].base.y = y;
bouncy_bricks[found].offset = 0;
bouncy_bricks[found].offset_m = -BOUNCY_BRICK_SPEED;
bouncy_bricks[found].shape = shape(x, y);
found = -1;
- for (i = 0; i < NUM_BAD_GUYS && found == -1; i++)
+ for (i = 0; i < num_bad_guys && found == -1; i++)
{
- if (!bad_guys[i].alive)
+ if (!bad_guys[i].base.alive)
found = i;
}
+
+ if (found == -1)
+ {
+ ++num_bad_guys;
+ bad_guys = realloc(bad_guys,num_bad_guys*sizeof(bad_guy_type));
+ badguy_init(&bad_guys[num_bad_guys-1]);
+ found = num_bad_guys - 1;
+ }
if (found != -1)
{
- bad_guys[found].alive = YES;
+ bad_guys[found].base.alive = YES;
bad_guys[found].mode = NORMAL;
bad_guys[found].dying = NO;
bad_guys[found].kind = kind;
- bad_guys[found].x = x;
- bad_guys[found].y = y;
- bad_guys[found].xm = 1.3;
- bad_guys[found].ym = 1.5;
+ bad_guys[found].base.x = x;
+ bad_guys[found].base.y = y;
+ bad_guys[found].base.xm = 1.3;
+ bad_guys[found].base.ym = 1.5;
bad_guys[found].dir = LEFT;
bad_guys[found].seen = NO;
timer_init(&bad_guys[found].timer);
}
}
+
+/* Add an upgrade: */
+
+void add_upgrade(float x, float y, int kind)
+{
+ int i, r, found;
+ /* we use this pointer to check, if realloc() returned a new memory address */
+ upgrade_type * pointee = upgrades;
+
+ found = -1;
+ r = 0;
+
+ for (i = 0; i < num_upgrades && found == -1; i++)
+ {
+ if (!upgrades[i].base.alive)
+ found = i;
+ }
+
+ if (found == -1)
+ {
+ ++num_upgrades;
+ upgrades = realloc(upgrades,num_upgrades*sizeof(upgrade_type));
+ if(upgrades != pointee)
+ r = 1;
+ upgrade_init(&upgrades[num_upgrades-1]);
+ found = num_upgrades - 1;
+ }
+
+ if (found != -1)
+ {
+ if(r == 1)
+ {
+ for (i = 0; i < num_upgrades && found == -1; i++)
+ {
+ upgrade_init(&upgrades[i]);
+ }
+ }
+ upgrade_init(&upgrades[found]);
+ upgrades[found].base.alive = YES;
+ upgrades[found].kind = kind;
+ upgrades[found].base.x = x;
+ upgrades[found].base.y = y;
+ upgrades[found].base.xm = 2;
+ upgrades[found].base.ym = -2;
+ upgrades[found].base.height = 0;
+ }
+}
+
+/* Add a bullet: */
+
+void add_bullet(float x, float y, float xm, int dir)
+{
+ int i, found;
+
+ found = -1;
+
+ for (i = 0; i < num_bullets && found == -1; i++)
+ {
+ if (!bullets[i].base.alive)
+ found = i;
+ }
+
+ if (found == -1)
+ {
+ ++num_bullets;
+ bullets = realloc(bullets,num_bullets*sizeof(bullet_type));
+ bullet_init(&bullets[num_bullets-1]);
+ found = num_bullets - 1;
+ }
+
+ if (found != -1)
+ {
+ bullet_init(&bullets[found]);
+ bullets[found].base.alive = YES;
+
+ if (dir == RIGHT)
+ {
+ bullets[found].base.x = x + 32;
+ bullets[found].base.xm = BULLET_XM + xm;
+ }
+ else
+ {
+ bullets[found].base.x = x;
+ bullets[found].base.xm = -BULLET_XM + xm;
+ }
+
+ bullets[found].base.y = y;
+ bullets[found].base.ym = BULLET_STARTING_YM;
+
+ play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
+ }
+}
+
counting_distros, distro_counter;
float scroll_x;
int frame;
-bouncy_distro_type bouncy_distros[NUM_BOUNCY_DISTROS];
-broken_brick_type broken_bricks[NUM_BROKEN_BRICKS];
-bouncy_brick_type bouncy_bricks[NUM_BOUNCY_BRICKS];
-bad_guy_type bad_guys[NUM_BAD_GUYS];
-floating_score_type floating_scores[NUM_FLOATING_SCORES];
-upgrade_type upgrades[NUM_UPGRADES];
-bullet_type bullets[NUM_BULLETS];
+bouncy_distro_type *bouncy_distros;
+broken_brick_type *broken_bricks;
+bouncy_brick_type *bouncy_bricks;
+bad_guy_type *bad_guys;
+floating_score_type *floating_scores;
+upgrade_type *upgrades;
+bullet_type *bullets;
+int num_bad_guys;
+int num_bouncy_distros;
+int num_broken_bricks;
+int num_bouncy_bricks;
+int num_floating_scores;
+int num_upgrades;
+int num_bullets;
player_type tux;
SDL_Rect src, dest;
texture_type img_box_full, img_box_empty, img_mints, img_coffee, img_super_bkgd, img_red_glow;
void add_score(int x, int y, int s);
void set_defaults(void);
+void arrays_init(void);
+void arrays_free(void);
#endif /*SUPERTUX_SCENE_H*/
void bullet_init(bullet_type* pbullet)
{
- pbullet->it.alive = &pbullet->alive;
- pbullet->it.x = &pbullet->x;
- pbullet->it.y = &pbullet->y;
- pbullet->it.width = &pbullet->width;
- pbullet->it.height = &pbullet->height;
- pbullet->it.updated = &pbullet->updated;
-
- pbullet->width = 4;
- pbullet->height = 4;
- pbullet->updated = SDL_GetTicks();
- pbullet->alive = NO;
+ pbullet->base.width = 4;
+ pbullet->base.height = 4;
+ pbullet->base.updated = SDL_GetTicks();
+ pbullet->base.alive = NO;
}
void bullet_action(bullet_type* pbullet)
{
- double frame_ratio = get_frame_ratio(&pbullet->it);
+ double frame_ratio = get_frame_ratio(&pbullet->base);
- if (pbullet->alive)
+ if (pbullet->base.alive)
{
- pbullet->x = pbullet->x + pbullet->xm * frame_ratio;
- pbullet->y = pbullet->y + pbullet->ym * frame_ratio;
+ pbullet->base.x = pbullet->base.x + pbullet->base.xm * frame_ratio;
+ pbullet->base.y = pbullet->base.y + pbullet->base.ym * frame_ratio;
- if (issolid(pbullet->x, pbullet->y))
+ if (issolid(pbullet->base.x, pbullet->base.y))
{
- if (issolid(pbullet->x, pbullet->y - pbullet->ym))
- pbullet->alive = NO;
+ if (issolid(pbullet->base.x, pbullet->base.y - pbullet->base.ym))
+ pbullet->base.alive = NO;
else
{
- if (pbullet->ym >= 0)
+ if (pbullet->base.ym >= 0)
{
- pbullet->y = (int)(pbullet->y / 32) * 32 - 8;
+ pbullet->base.y = (int)(pbullet->base.y / 32) * 32 - 8;
}
- pbullet->ym = -pbullet->ym;
+ pbullet->base.ym = -pbullet->base.ym;
}
}
- pbullet->ym = pbullet->ym + GRAVITY;
+ pbullet->base.ym = pbullet->base.ym + GRAVITY;
- if (pbullet->x < scroll_x ||
- pbullet->x > scroll_x + screen->w)
+ if (pbullet->base.x < scroll_x ||
+ pbullet->base.x > scroll_x + screen->w)
{
- pbullet->alive = NO;
+ pbullet->base.alive = NO;
}
}
void bullet_draw(bullet_type* pbullet)
{
- if (pbullet->alive &&
- pbullet->x >= scroll_x - pbullet->width &&
- pbullet->x <= scroll_x + screen->w)
+ if (pbullet->base.alive &&
+ pbullet->base.x >= scroll_x - pbullet->base.width &&
+ pbullet->base.x <= scroll_x + screen->w)
{
- texture_draw(&img_bullet, pbullet->x - scroll_x, pbullet->y,
+ texture_draw(&img_bullet, pbullet->base.x - scroll_x, pbullet->base.y,
NO_UPDATE);
}
}
{
if(c_object == CO_BADGUY)
- pbullet->alive = NO;
+ pbullet->base.alive = NO;
}
void upgrade_init(upgrade_type *pupgrade)
{
- pupgrade->it.alive = &pupgrade->alive;
- pupgrade->it.x = &pupgrade->x;
- pupgrade->it.y = &pupgrade->y;
- pupgrade->it.width = &pupgrade->width;
- pupgrade->it.height = &pupgrade->height;
- pupgrade->it.updated = &pupgrade->updated;
-
- pupgrade->width = 32;
- pupgrade->height = 0;
- pupgrade->updated = SDL_GetTicks();
- pupgrade->alive = NO;
+ pupgrade->base.width = 32;
+ pupgrade->base.height = 0;
+ pupgrade->base.updated = SDL_GetTicks();
+ pupgrade->base.alive = NO;
}
void upgrade_action(upgrade_type *pupgrade)
{
- double frame_ratio = get_frame_ratio(&pupgrade->it);
+ double frame_ratio = get_frame_ratio(&pupgrade->base);
- if (pupgrade->alive)
+ if (pupgrade->base.alive)
{
- if (pupgrade->height < 32)
+ if (pupgrade->base.height < 32)
{
/* Rise up! */
- pupgrade->height++;
+ pupgrade->base.height++;
}
else
{
if (pupgrade->kind == UPGRADE_MINTS ||
pupgrade->kind == UPGRADE_HERRING)
{
- pupgrade->x = pupgrade->x + pupgrade->xm * frame_ratio;
- pupgrade->y = pupgrade->y + pupgrade->ym * frame_ratio;
+ 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->x, pupgrade->y + 31) ||
- issolid(pupgrade->x + 31, pupgrade->y + 31))
+ if (issolid(pupgrade->base.x, pupgrade->base.y + 31) ||
+ issolid(pupgrade->base.x + 31, pupgrade->base.y + 31))
{
- if (pupgrade->ym > 0)
+ if (pupgrade->base.ym > 0)
{
if (pupgrade->kind == UPGRADE_MINTS)
{
- pupgrade->ym = 0;
+ pupgrade->base.ym = 0;
}
else if (pupgrade->kind == UPGRADE_HERRING)
{
- pupgrade->ym = -24;
+ pupgrade->base.ym = -24;
}
- pupgrade->y = (int)(pupgrade->y / 32) * 32;
+ pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
}
}
else
- pupgrade->ym = pupgrade->ym + GRAVITY;
+ pupgrade->base.ym = pupgrade->base.ym + GRAVITY;
- if (issolid(pupgrade->x, pupgrade->y))
+ if (issolid(pupgrade->base.x, pupgrade->base.y))
{
- pupgrade->xm = -pupgrade->xm;
+ pupgrade->base.xm = -pupgrade->base.xm;
}
}
/* Off the screen? Kill it! */
- if (pupgrade->x < scroll_x)
- pupgrade->alive = NO;
+ if (pupgrade->base.x < scroll_x)
+ pupgrade->base.alive = NO;
}
}
void upgrade_draw(upgrade_type* pupgrade)
{
- if (pupgrade->alive)
+ if (pupgrade->base.alive)
{
- if (pupgrade->height < 32)
+ if (pupgrade->base.height < 32)
{
/* Rising up... */
- dest.x = pupgrade->x - scroll_x;
- dest.y = pupgrade->y + 32 - pupgrade->height;
+ dest.x = pupgrade->base.x - scroll_x;
+ dest.y = pupgrade->base.y + 32 - pupgrade->base.height;
dest.w = 32;
- dest.h = pupgrade->height;
+ dest.h = pupgrade->base.height;
src.x = 0;
src.y = 0;
src.w = 32;
- src.h = pupgrade->height;
+ src.h = pupgrade->base.height;
if (pupgrade->kind == UPGRADE_MINTS)
SDL_BlitSurface(img_mints.sdl_surface, &src, screen, &dest);
if (pupgrade->kind == UPGRADE_MINTS)
{
texture_draw(&img_mints,
- pupgrade->x - scroll_x, pupgrade->y,
+ pupgrade->base.x - scroll_x, pupgrade->base.y,
NO_UPDATE);
}
else if (pupgrade->kind == UPGRADE_COFFEE)
{
texture_draw(&img_coffee,
- pupgrade->x - scroll_x, pupgrade->y,
+ pupgrade->base.x - scroll_x, pupgrade->base.y,
NO_UPDATE);
}
else if (pupgrade->kind == UPGRADE_HERRING)
{
texture_draw(&img_golden_herring,
- pupgrade->x - scroll_x, pupgrade->y,
+ pupgrade->base.x - scroll_x, pupgrade->base.y,
NO_UPDATE);
}
}
/* p_c_object is CO_PLAYER, so assign it to pplayer */
pplayer = p_c_object;
- pupgrade->alive = NO;
+ pupgrade->base.alive = NO;
/* Affect the player: */
#define BULLET_STARTING_YM 1
#define BULLET_XM 5
-#define NUM_BULLETS 3
#ifndef SUPERTUX_SPECIAL_H
#define SUPERTUX_SPECIAL_H
#include <SDL.h>
#include "bitmask.h"
#include "type.h"
+#include "texture.h"
#include "collision.h"
typedef struct upgrade_type
{
- int alive;
int kind;
- float x;
- float y;
- float xm;
- float ym;
- float width;
- float height;
- unsigned int updated;
- itop_type it;
+ base_type base;
}
upgrade_type;
typedef struct bullet_type
{
- int alive;
- float x;
- float y;
- float xm;
- float ym;
- float width;
- float height;
- unsigned int updated;
- itop_type it;
+ base_type base;
}
bullet_type;
--- /dev/null
+//
+// C Implementation: texture
+//
+// Description:
+//
+//
+// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <SDL/SDL.h>
+#include <SDL/SDL_image.h>
+#include <SDL/SDL_opengl.h>
+#include "globals.h"
+#include "screen.h"
+#include "setup.h"
+#include "texture.h"
+
+void texture_load(texture_type* ptexture, char * file, int use_alpha)
+{
+ SDL_Surface * temp;
+
+ temp = IMG_Load(file);
+
+ if (temp == NULL)
+ st_abort("Can't load", file);
+
+ ptexture->sdl_surface = SDL_DisplayFormatAlpha(temp);
+
+ if (ptexture->sdl_surface == NULL)
+ st_abort("Can't covert to display format", file);
+
+ if (use_alpha == IGNORE_ALPHA)
+ SDL_SetAlpha(ptexture->sdl_surface, 0, 0);
+
+ SDL_FreeSurface(temp);
+
+ ptexture->w = ptexture->sdl_surface->w;
+ ptexture->h = ptexture->sdl_surface->h;
+
+ if(use_gl)
+ {
+ create_gl_texture(ptexture->sdl_surface,&ptexture->gl_texture);
+ }
+}
+
+void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface* sdl_surf, int use_alpha)
+{
+ /* SDL_Surface * temp;
+
+ temp = IMG_Load(file);
+
+ if (temp == NULL)
+ st_abort("Can't load", file);*/
+
+ ptexture->sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);
+
+ if (ptexture->sdl_surface == NULL)
+ st_abort("Can't covert to display format", "SURFACE");
+
+ if (use_alpha == IGNORE_ALPHA)
+ SDL_SetAlpha(ptexture->sdl_surface, 0, 0);
+
+ ptexture->w = ptexture->sdl_surface->w;
+ ptexture->h = ptexture->sdl_surface->h;
+
+ if(use_gl)
+ {
+ create_gl_texture(ptexture->sdl_surface,&ptexture->gl_texture);
+ }
+}
+
+void texture_draw(texture_type* ptexture, float x, float y, int update)
+{
+ if(use_gl)
+ {
+ glColor4ub(255, 255, 255,255);
+ glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ glEnable (GL_BLEND);
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0);
+ glVertex2f(x, y);
+ glTexCoord2f((float)ptexture->w, 0);
+ glVertex2f((float)ptexture->w+x, y);
+ glTexCoord2f((float)ptexture->w, (float)ptexture->h);
+ glVertex2f((float)ptexture->w+x, (float)ptexture->h+y);
+ glTexCoord2f(0, (float)ptexture->h);
+ glVertex2f(x, (float)ptexture->h+y);
+ glEnd();
+ }
+ else
+ {
+ SDL_Rect dest;
+
+ dest.x = x;
+ dest.y = y;
+ dest.w = ptexture->w;
+ dest.h = ptexture->h;
+
+ SDL_BlitSurface(ptexture->sdl_surface, NULL, screen, &dest);
+
+ if (update == UPDATE)
+ SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
+ }
+}
+
+void texture_draw_bg(texture_type* ptexture, int update)
+{
+if(use_gl)
+{
+ //glColor3ub(255, 255, 255);
+
+ glEnable(GL_TEXTURE_RECTANGLE_NV);
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0); glVertex2f(0, 0);
+ glTexCoord2f((float)ptexture->w, 0); glVertex2f(screen->w, 0);
+ glTexCoord2f((float)ptexture->w, (float)ptexture->h); glVertex2f(screen->w, screen->h);
+ glTexCoord2f(0, (float)ptexture->h); glVertex2f(0, screen->h);
+ glEnd();
+
+}
+else
+{
+ SDL_Rect dest;
+
+ dest.x = 0;
+ dest.y = 0;
+ dest.w = screen->w;
+ dest.h = screen->h;
+
+ SDL_BlitSurface(ptexture->sdl_surface, NULL, screen, &dest);
+
+ if (update == UPDATE)
+ SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
+}
+}
+
+void texture_draw_part(texture_type* ptexture, float x, float y, float w, float h, int update)
+{
+ if(use_gl)
+ {
+ glColor3ub(255, 255, 255);
+
+ glEnable(GL_TEXTURE_RECTANGLE_NV);
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(x, y);
+ glVertex2f(x, y);
+ glTexCoord2f(x+w, y);
+ glVertex2f(w+x, y);
+ glTexCoord2f(x+w, y+h);
+ glVertex2f(w+x, h+y);
+ glTexCoord2f(x, y+h);
+ glVertex2f(x, h+y);
+ glEnd();
+ }
+ else
+ {
+ SDL_Rect src, dest;
+
+ src.x = x;
+ src.y = y;
+ src.w = w;
+ src.h = h;
+
+ dest.x = x;
+ dest.y = y;
+ dest.w = w;
+ dest.h = h;
+
+
+ SDL_BlitSurface(ptexture->sdl_surface, &src, screen, &dest);
+
+ if (update == UPDATE)
+ update_rect(screen, dest.x, dest.y, dest.w, dest.h);
+ }
+}
+
+void texture_free(texture_type* ptexture)
+{
+ SDL_FreeSurface(ptexture->sdl_surface);
+ if(use_gl)
+ glDeleteTextures(1, &ptexture->gl_texture);
+}
+
--- /dev/null
+//
+// C Interface: texture
+//
+// Description:
+//
+//
+// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef SUPERTUX_TEXTURE_H
+#define SUPERTUX_TEXTURE_H
+
+/* Texture type */
+typedef struct texture_type
+ {
+ SDL_Surface* sdl_surface;
+ unsigned gl_texture;
+ int w;
+ int h;
+ }
+texture_type;
+
+void texture_setup(int opengl);
+void texture_load(texture_type* ptexture, char * file, int use_alpha);
+void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface * sdl_surf, int use_alpha);
+void texture_free(texture_type* ptexture);
+void texture_draw(texture_type* ptexture, float x, float y, int update);
+void texture_draw_bg(texture_type* ptexture, int update);
+void texture_draw_part(texture_type* ptexture, float x, float y, float w, float h, int update);
+
+#endif /*SUPERTUX_TEXTURE_H*/
+
--- /dev/null
+//
+// C Implementation: timer
+//
+// Description:
+//
+//
+// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <SDL/SDL.h>
+#include "defines.h"
+#include "timer.h"
+
+void timer_init(timer_type* ptimer)
+{
+ ptimer->period = 0;
+ ptimer->time = 0;
+}
+
+void timer_start(timer_type* ptimer, unsigned int period)
+{
+ ptimer->time = SDL_GetTicks();
+ ptimer->period = period;
+}
+
+void timer_stop(timer_type* ptimer)
+{
+ timer_init(ptimer);
+}
+
+int timer_check(timer_type* ptimer)
+{
+ if(ptimer->time != 0 && ptimer->time + ptimer->period > SDL_GetTicks())
+ return YES;
+ else
+ {
+ ptimer->time = 0;
+ return NO;
+ }
+}
+
+int timer_started(timer_type* ptimer)
+{
+ if(ptimer->time != 0)
+ return YES;
+ else
+ return NO;
+}
+
+int timer_get_left(timer_type* ptimer)
+{
+ return (ptimer->period - (SDL_GetTicks() - ptimer->time));
+}
+
+int timer_get_gone(timer_type* ptimer)
+{
+ return (SDL_GetTicks() - ptimer->time);
+}
--- /dev/null
+//
+// C Interface: timer
+//
+// Description:
+//
+//
+// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef SUPERTUX_TIMER_H
+#define SUPERTUX_TIMER_H
+
+/* Timer type */
+typedef struct timer_type
+ {
+ unsigned int period;
+ unsigned int time;
+ }
+timer_type;
+
+void timer_init(timer_type* ptimer);
+void timer_start(timer_type* ptimer, unsigned int period);
+void timer_stop(timer_type* ptimer);
+int timer_check(timer_type* ptimer);
+int timer_started(timer_type* ptimer);
+int timer_get_left(timer_type* ptimer);
+int timer_get_gone(timer_type* ptimer);
+
+#endif /*SUPERTUX_TIMER_H*/
+
#include "screen.h"
#include "high_scores.h"
#include "menu.h"
-#include "type.h"
+#include "texture.h"
+#include "timer.h"
/* --- TITLE SCREEN --- */
#include "type.h"
#include "scene.h"
-double get_frame_ratio(itop_type* pit)
+double get_frame_ratio(base_type* pbase)
{
unsigned int cur_time = SDL_GetTicks();
- double frame_ratio = (float)(cur_time-*pit->updated)/(float)(FRAME_RATE);
- *pit->updated = cur_time;
+ double frame_ratio = (float)(cur_time-pbase->updated)/(float)(FRAME_RATE);
+ pbase->updated = cur_time;
return frame_ratio;
}
-
-void timer_init(timer_type* ptimer)
-{
- ptimer->period = 0;
- ptimer->time = 0;
-}
-
-void timer_start(timer_type* ptimer, unsigned int period)
-{
- ptimer->time = SDL_GetTicks();
- ptimer->period = period;
-}
-
-void timer_stop(timer_type* ptimer)
-{
- timer_init(ptimer);
-}
-
-int timer_check(timer_type* ptimer)
-{
- if(ptimer->time != 0 && ptimer->time + ptimer->period > SDL_GetTicks())
- return YES;
- else
- {
- ptimer->time = 0;
- return NO;
- }
-}
-
-int timer_started(timer_type* ptimer)
-{
- if(ptimer->time != 0)
- return YES;
- else
- return NO;
-}
-
-int timer_get_left(timer_type* ptimer)
-{
- return (ptimer->period - (SDL_GetTicks() - ptimer->time));
-}
-
-int timer_get_gone(timer_type* ptimer)
-{
- return (SDL_GetTicks() - ptimer->time);
-}
-
-void texture_load(texture_type* ptexture, char * file, int use_alpha)
-{
- SDL_Surface * temp;
-
- temp = IMG_Load(file);
-
- if (temp == NULL)
- st_abort("Can't load", file);
-
- ptexture->sdl_surface = SDL_DisplayFormatAlpha(temp);
-
- if (ptexture->sdl_surface == NULL)
- st_abort("Can't covert to display format", file);
-
- if (use_alpha == IGNORE_ALPHA)
- SDL_SetAlpha(ptexture->sdl_surface, 0, 0);
-
- SDL_FreeSurface(temp);
-
- ptexture->w = ptexture->sdl_surface->w;
- ptexture->h = ptexture->sdl_surface->h;
-
- if(use_gl)
- {
- create_gl_texture(ptexture->sdl_surface,&ptexture->gl_texture);
- }
-}
-
-void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface* sdl_surf, int use_alpha)
-{
- /* SDL_Surface * temp;
-
- temp = IMG_Load(file);
-
- if (temp == NULL)
- st_abort("Can't load", file);*/
-
- ptexture->sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);
-
- if (ptexture->sdl_surface == NULL)
- st_abort("Can't covert to display format", "SURFACE");
-
- if (use_alpha == IGNORE_ALPHA)
- SDL_SetAlpha(ptexture->sdl_surface, 0, 0);
-
- ptexture->w = ptexture->sdl_surface->w;
- ptexture->h = ptexture->sdl_surface->h;
-
- if(use_gl)
- {
- create_gl_texture(ptexture->sdl_surface,&ptexture->gl_texture);
- }
-}
-
-void texture_draw(texture_type* ptexture, float x, float y, int update)
-{
- if(use_gl)
- {
- glColor4ub(255, 255, 255,255);
- glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glEnable (GL_BLEND);
- glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(x, y);
- glTexCoord2f((float)ptexture->w, 0);
- glVertex2f((float)ptexture->w+x, y);
- glTexCoord2f((float)ptexture->w, (float)ptexture->h);
- glVertex2f((float)ptexture->w+x, (float)ptexture->h+y);
- glTexCoord2f(0, (float)ptexture->h);
- glVertex2f(x, (float)ptexture->h+y);
- glEnd();
- }
- else
- {
- SDL_Rect dest;
-
- dest.x = x;
- dest.y = y;
- dest.w = ptexture->w;
- dest.h = ptexture->h;
-
- SDL_BlitSurface(ptexture->sdl_surface, NULL, screen, &dest);
-
- if (update == UPDATE)
- SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
- }
-}
-
-void texture_draw_bg(texture_type* ptexture, int update)
-{
-if(use_gl)
-{
- //glColor3ub(255, 255, 255);
-
- glEnable(GL_TEXTURE_RECTANGLE_NV);
- glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0); glVertex2f(0, 0);
- glTexCoord2f((float)ptexture->w, 0); glVertex2f(screen->w, 0);
- glTexCoord2f((float)ptexture->w, (float)ptexture->h); glVertex2f(screen->w, screen->h);
- glTexCoord2f(0, (float)ptexture->h); glVertex2f(0, screen->h);
- glEnd();
-
-}
-else
-{
- SDL_Rect dest;
-
- dest.x = 0;
- dest.y = 0;
- dest.w = screen->w;
- dest.h = screen->h;
-
- SDL_BlitSurface(ptexture->sdl_surface, NULL, screen, &dest);
-
- if (update == UPDATE)
- SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
-}
-}
-
-void texture_draw_part(texture_type* ptexture, float x, float y, float w, float h, int update)
-{
- if(use_gl)
- {
- glColor3ub(255, 255, 255);
-
- glEnable(GL_TEXTURE_RECTANGLE_NV);
- glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
-
- glBegin(GL_QUADS);
- glTexCoord2f(x, y);
- glVertex2f(x, y);
- glTexCoord2f(x+w, y);
- glVertex2f(w+x, y);
- glTexCoord2f(x+w, y+h);
- glVertex2f(w+x, h+y);
- glTexCoord2f(x, y+h);
- glVertex2f(x, h+y);
- glEnd();
- }
- else
- {
- SDL_Rect src, dest;
-
- src.x = x;
- src.y = y;
- src.w = w;
- src.h = h;
-
- dest.x = x;
- dest.y = y;
- dest.w = w;
- dest.h = h;
-
-
- SDL_BlitSurface(ptexture->sdl_surface, &src, screen, &dest);
-
- if (update == UPDATE)
- update_rect(screen, dest.x, dest.y, dest.w, dest.h);
- }
-}
-
-void texture_free(texture_type* ptexture)
-{
- SDL_FreeSurface(ptexture->sdl_surface);
- if(use_gl)
- glDeleteTextures(1, &ptexture->gl_texture);
-}
-
#include <SDL/SDL.h>
-/* 'Interoperability' type */
+/* 'Base' type for game objects */
-typedef struct itop_type
+typedef struct base_type
{
- int* alive;
- float* x;
- float* y;
- float* width;
- float* height;
- int* updated;
+ int alive;
+ float x;
+ float y;
+ float xm;
+ float ym;
+ float width;
+ float height;
+ int updated;
}
-itop_type;
+base_type;
-double get_frame_ratio(itop_type* pit);
-
-/* Timer type */
-typedef struct timer_type
- {
- unsigned int period;
- unsigned int time;
- }
-timer_type;
-
-void timer_init(timer_type* ptimer);
-void timer_start(timer_type* ptimer, unsigned int period);
-void timer_stop(timer_type* ptimer);
-int timer_check(timer_type* ptimer);
-int timer_started(timer_type* ptimer);
-int timer_get_left(timer_type* ptimer);
-int timer_get_gone(timer_type* ptimer);
-
-/* Texture type */
-typedef struct texture_type
- {
- SDL_Surface* sdl_surface;
- unsigned gl_texture;
- int w;
- int h;
- }
-texture_type;
-
-void texture_load(texture_type* ptexture, char * file, int use_alpha);
-void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface * sdl_surf, int use_alpha);
-void texture_free(texture_type* ptexture);
-void texture_draw(texture_type* ptexture, float x, float y, int update);
-void texture_draw_bg(texture_type* ptexture, int update);
-void texture_draw_part(texture_type* ptexture, float x, float y, float w, float h, int update);
+double get_frame_ratio(base_type* pbase);
#endif /*SUPERTUX_TYPE_H*/
void bouncy_distro_action(bouncy_distro_type* pbouncy_distro)
{
- if (pbouncy_distro->alive)
+ if (pbouncy_distro->base.alive)
{
- pbouncy_distro->y = pbouncy_distro->y + pbouncy_distro->ym;
+ pbouncy_distro->base.y = pbouncy_distro->base.y + pbouncy_distro->base.ym;
- pbouncy_distro->ym++;
+ pbouncy_distro->base.ym++;
- if (pbouncy_distro->ym >= 0)
- pbouncy_distro->alive = NO;
+ if (pbouncy_distro->base.ym >= 0)
+ pbouncy_distro->base.alive = NO;
}
}
void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro)
{
- if (pbouncy_distro->alive)
+ if (pbouncy_distro->base.alive)
{
texture_draw(&img_distro[0],
- pbouncy_distro->x - scroll_x,
- pbouncy_distro->y,
+ pbouncy_distro->base.x - scroll_x,
+ pbouncy_distro->base.y,
NO_UPDATE);
}
}
void broken_brick_action(broken_brick_type* pbroken_brick)
{
- if (pbroken_brick->alive)
+ if (pbroken_brick->base.alive)
{
- pbroken_brick->x = pbroken_brick->x + pbroken_brick->xm;
- pbroken_brick->y = pbroken_brick->y + pbroken_brick->ym;
+ pbroken_brick->base.x = pbroken_brick->base.x + pbroken_brick->base.xm;
+ pbroken_brick->base.y = pbroken_brick->base.y + pbroken_brick->base.ym;
- pbroken_brick->ym++;
+ pbroken_brick->base.ym++;
- if (pbroken_brick->ym >= 0)
- pbroken_brick->alive = NO;
+ if (pbroken_brick->base.ym >= 0)
+ pbroken_brick->base.alive = NO;
}
}
void broken_brick_draw(broken_brick_type* pbroken_brick)
{
- if (pbroken_brick->alive)
+ if (pbroken_brick->base.alive)
{
src.x = rand() % 16;
src.y = rand() % 16;
src.w = 16;
src.h = 16;
- dest.x = pbroken_brick->x - scroll_x;
- dest.y = pbroken_brick->y;
+ dest.x = pbroken_brick->base.x - scroll_x;
+ dest.y = pbroken_brick->base.y;
dest.w = 16;
dest.h = 16;
void bouncy_brick_action(bouncy_brick_type* pbouncy_brick)
{
- if (pbouncy_brick->alive)
+ if (pbouncy_brick->base.alive)
{
pbouncy_brick->offset = (pbouncy_brick->offset +
pbouncy_brick->offset_m);
/* Stop bouncing? */
if (pbouncy_brick->offset == 0)
- pbouncy_brick->alive = NO;
+ pbouncy_brick->base.alive = NO;
}
}
void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick)
{
- if (pbouncy_brick->alive)
+ if (pbouncy_brick->base.alive)
{
- if (pbouncy_brick->x >= scroll_x - 32 &&
- pbouncy_brick->x <= scroll_x + screen->w)
+ if (pbouncy_brick->base.x >= scroll_x - 32 &&
+ pbouncy_brick->base.x <= scroll_x + screen->w)
{
- dest.x = pbouncy_brick->x - scroll_x;
- dest.y = pbouncy_brick->y;
+ dest.x = pbouncy_brick->base.x - scroll_x;
+ dest.y = pbouncy_brick->base.y;
dest.w = 32;
dest.h = 32;
current_level.bkgd_green,
current_level.bkgd_blue));
- drawshape(pbouncy_brick->x - scroll_x,
- pbouncy_brick->y + pbouncy_brick->offset,
+ drawshape(pbouncy_brick->base.x - scroll_x,
+ pbouncy_brick->base.y + pbouncy_brick->offset,
pbouncy_brick->shape);
}
}
void floating_score_init(floating_score_type* pfloating_score, int x, int y, int s)
{
- pfloating_score->alive = YES;
- pfloating_score->x = x;
- pfloating_score->y = y - 16;
+ pfloating_score->base.alive = YES;
+ pfloating_score->base.x = x;
+ pfloating_score->base.y = y - 16;
timer_start(&pfloating_score->timer,1000);
pfloating_score->value = s;
}
void floating_score_action(floating_score_type* pfloating_score)
{
- if (pfloating_score->alive)
+ if (pfloating_score->base.alive)
{
- pfloating_score->y = pfloating_score->y - 2;
+ pfloating_score->base.y = pfloating_score->base.y - 2;
if(!timer_check(&pfloating_score->timer))
- pfloating_score->alive = NO;
+ pfloating_score->base.alive = NO;
}
}
void floating_score_draw(floating_score_type* pfloating_score)
{
- if (pfloating_score->alive)
+ if (pfloating_score->base.alive)
{
char str[10];
sprintf(str, "%d", pfloating_score->value);
drawtext(str,
- pfloating_score->x + 16 - strlen(str) * 8,
- pfloating_score->y,
+ pfloating_score->base.x + 16 - strlen(str) * 8,
+ pfloating_score->base.y,
letters_gold, NO_UPDATE, 1);
}
}
typedef struct bouncy_distro_type /*It is easier to read the sources IMHO, if we don't write something like int a,b,c; */
{
- int alive;
- float x;
- float y;
- float ym;
+ base_type base;
}
bouncy_distro_type;
typedef struct broken_brick_type
{
- int alive;
- float x;
- float y;
- float xm;
- float ym;
+ base_type base;
}
broken_brick_type;
typedef struct bouncy_brick_type
{
- int alive;
- float x;
- float y;
float offset;
float offset_m;
int shape;
+ base_type base;
}
bouncy_brick_type;
typedef struct floating_score_type
{
- int alive;
- float x;
- float y;
int value;
timer_type timer;
+ base_type base;
}
floating_score_type;