/*bm_bsod = img_bsod_left[0];*/
}
-void badguy_init(bad_guy_type* pbad)
+void badguy_init(bad_guy_type* pbad, float x, float y, int kind)
{
pbad->base.updated = SDL_GetTicks();
- pbad->base.alive = NO;
pbad->base.width = 32;
pbad->base.height = 32;
-
+ pbad->base.alive = YES;
+ pbad->mode = NORMAL;
+ pbad->dying = NO;
+ pbad->kind = kind;
+ pbad->base.x = x;
+ pbad->base.y = y;
+ pbad->base.xm = 1.3;
+ pbad->base.ym = 1.5;
+ pbad->dir = LEFT;
+ pbad->seen = NO;
+ timer_init(&pbad->timer);
}
void badguy_action(bad_guy_type* pbad)
}
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;*/
+ /* 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. */
play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
pbad->mode = FLAT;
- pbad->base.xm = 4;
+ pbad->base.xm = 4;
timer_start(&pbad->timer,10000);
void badguy_create_bitmasks();
-void badguy_init(bad_guy_type* pbad);
+void badguy_init(bad_guy_type* pbad, float x, float y, int kind);
void badguy_action(bad_guy_type* pbad);
void badguy_draw(bad_guy_type* pbad);
void badguy_collision(bad_guy_type* pbad, void* p_c_object, int c_object);
/* Speed constraints: */
-#define MAX_WALK_XM 8
-#define MAX_RUN_XM 3
+#define MAX_WALK_XM 2.3
+#define MAX_RUN_XM 3.2
#define MAX_YM 10
#define MAX_JUMP_TIME 1000
#define MAX_LIVES 4
#define YM_FOR_JUMP 50
#define KILL_BOUNCE_YM 8
-#define SKID_XM 4
-#define SKID_TIME 8
+#define SKID_XM 2
+#define SKID_TIME 4
/* Size constraints: */
bullet_action(&bullets[i]);
}
-
- /* Handle background timer: */
-
- if (super_bkgd_time)
- super_bkgd_time--;
-
-
/* Handle upgrades: */
for (i = 0; i < num_upgrades; i++)
clearscreen(255, 255, 255);
else
{
- if (super_bkgd_time == 0)
- clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue);
- else
+ if (timer_check(&super_bkgd_timer))
texture_draw(&img_super_bkgd, 0, 0, NO_UPDATE);
+ else
+ clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue);
}
/* Draw background: */
if (pplayer->input.fire == UP)
{
- pplayer->base.xm = pplayer->base.xm + RUN_SPEED;
+ pplayer->base.xm = pplayer->base.xm + WALK_SPEED;
- if (pplayer->base.xm > MAX_RUN_XM)
- pplayer->base.xm = MAX_RUN_XM;
+ if (pplayer->base.xm > MAX_WALK_XM)
+ pplayer->base.xm = MAX_WALK_XM;
}
else if ( pplayer->input.fire == DOWN)
{
- pplayer->base.xm = pplayer->base.xm + WALK_SPEED;
+ pplayer->base.xm = pplayer->base.xm + RUN_SPEED;
- if (pplayer->base.xm > MAX_WALK_XM)
- pplayer->base.xm = MAX_WALK_XM;
+ if (pplayer->base.xm > MAX_RUN_XM)
+ pplayer->base.xm = MAX_RUN_XM;
}
}
else
if (pplayer->input.fire == UP)
{
- pplayer->base.xm = pplayer->base.xm - RUN_SPEED;
+ pplayer->base.xm = pplayer->base.xm - WALK_SPEED;
- if (pplayer->base.xm < -MAX_RUN_XM)
- pplayer->base.xm = -MAX_RUN_XM;
+ if (pplayer->base.xm < -MAX_WALK_XM)
+ pplayer->base.xm = -MAX_WALK_XM;
}
else if (pplayer->input.fire == DOWN)
{
- pplayer->base.xm = pplayer->base.xm - WALK_SPEED;
+ pplayer->base.xm = pplayer->base.xm - RUN_SPEED;
- if (pplayer->base.xm < -MAX_WALK_XM)
- pplayer->base.xm = -MAX_WALK_XM;
+ if (pplayer->base.xm < -MAX_RUN_XM)
+ pplayer->base.xm = -MAX_RUN_XM;
}
}
else
void set_defaults(void)
{
- int i;
-
- /* Reset arrays: */
-
- for (i = 0; i < num_bouncy_distros; i++)
- bouncy_distros[i].base.alive = NO;
-
- for (i = 0; i < num_broken_bricks; i++)
- broken_bricks[i].base.alive = NO;
-
- 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].base.alive = NO;
-
- for (i = 0; i < num_upgrades; i++)
- {
- /*upgrades[i].alive = NO;*/
- upgrade_init(&upgrades[i]);
- }
-
- for (i = 0; i < num_bullets; i++)
- {
- /*bullets[i].alive = NO;*/
- bullet_init(&bullets[i]);
- }
-
-
/* Set defaults: */
scroll_x = 0;
score_multiplier = 1;
- super_bkgd_time = 0;
+ timer_init(&super_bkgd_timer);
counting_distros = NO;
distro_counter = 0;
if (found != -1)
{
- bouncy_distros[found].base.alive = YES;
- bouncy_distros[found].base.x = x;
- bouncy_distros[found].base.y = y;
- bouncy_distros[found].base.ym = -6;
+ bouncy_distro_init(&bouncy_distros[found],x,y);
}
}
void add_broken_brick(float x, float y)
{
- add_broken_brick_piece(x, y, -4, -16);
- add_broken_brick_piece(x, y + 16, -6, -12);
+ add_broken_brick_piece(x, y, -1, -4);
+ add_broken_brick_piece(x, y + 16, -1.5, -3);
- add_broken_brick_piece(x + 16, y, 4, -16);
- add_broken_brick_piece(x + 16, y + 16, 6, -12);
+ add_broken_brick_piece(x + 16, y, 1, -4);
+ add_broken_brick_piece(x + 16, y + 16, 1.5, -3);
}
if (found != -1)
{
- 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;
+ broken_brick_init(&broken_bricks[found], x, y, xm, ym);
}
}
if (found != -1)
{
- 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);
+ bouncy_brick_init(&bouncy_bricks[found],x,y);
}
}
{
++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].base.alive = YES;
- bad_guys[found].mode = NORMAL;
- bad_guys[found].dying = NO;
- bad_guys[found].kind = kind;
- 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);
+ badguy_init(&bad_guys[found], x, y, kind);
}
}
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;
+ int i, found;
found = -1;
- r = 0;
for (i = 0; i < num_upgrades && found == -1; i++)
{
{
++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;
+ upgrade_init(&upgrades[found], x, y, kind);
}
}
{
++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;
+ bullet_init(&bullets[found], x, y, xm, dir);
play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
}
#define FRAME_RATE 10 // 100 Frames per second (10ms)
int score, highscore, distros, level, next_level, game_pause,
-done, quit, score_multiplier, super_bkgd_time, endpos,
-counting_distros, distro_counter;
+done, quit, score_multiplier, endpos, counting_distros, distro_counter;
+timer_type super_bkgd_timer;
float scroll_x;
int frame;
bouncy_distro_type *bouncy_distros;
bm_bullet = bitmask_create_SDL(img_bullet.sdl_surface);
}
-void bullet_init(bullet_type* pbullet)
+void bullet_init(bullet_type* pbullet, float x, float y, float xm, int dir)
{
pbullet->base.width = 4;
pbullet->base.height = 4;
pbullet->base.updated = SDL_GetTicks();
- pbullet->base.alive = NO;
+ pbullet->base.alive = YES;
+
+ if (dir == RIGHT)
+ {
+ pbullet->base.x = x + 32;
+ pbullet->base.xm = BULLET_XM + xm;
+ }
+ else
+ {
+ pbullet->base.x = x;
+ pbullet->base.xm = -BULLET_XM + xm;
+ }
+
+ pbullet->base.y = y;
+ pbullet->base.ym = BULLET_STARTING_YM;
}
void bullet_action(bullet_type* pbullet)
}
-void upgrade_init(upgrade_type *pupgrade)
+void upgrade_init(upgrade_type *pupgrade, float x, float y, int kind)
{
pupgrade->base.width = 32;
pupgrade->base.height = 0;
+ pupgrade->base.alive = YES;
+ pupgrade->kind = kind;
+ pupgrade->base.x = x;
+ pupgrade->base.y = y;
+ pupgrade->base.xm = 2;
+ pupgrade->base.ym = -2;
+ pupgrade->base.height = 0;
pupgrade->base.updated = SDL_GetTicks();
- pupgrade->base.alive = NO;
}
void upgrade_action(upgrade_type *pupgrade)
if (pupgrade->base.x < scroll_x)
pupgrade->base.alive = NO;
-
- }
+
+ }
}
}
void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
{
-player_type* pplayer = NULL;
+ player_type* pplayer = NULL;
switch (c_object)
{
/* p_c_object is CO_PLAYER, so assign it to pplayer */
pplayer = p_c_object;
-
+
pupgrade->base.alive = NO;
/* Affect the player: */
{
play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
pplayer->size = BIG;
- super_bkgd_time = 8;
+ timer_start(&super_bkgd_timer, 350);
}
else if (pupgrade->kind == UPGRADE_COFFEE)
{
play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
pplayer->got_coffee = YES;
- super_bkgd_time = 4;
+ timer_start(&super_bkgd_timer, 250);
}
else if (pupgrade->kind == UPGRADE_HERRING)
{
play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
- super_bkgd_time = 4;
+ timer_start(&super_bkgd_timer, 250);
/* play the herring song ^^ */
if (current_music != HURRYUP_MUSIC)
{
texture_type img_golden_herring;
-void upgrade_init(upgrade_type *pupgrade);
+void upgrade_init(upgrade_type *pupgrade, float x, float y, int kind);
void upgrade_action(upgrade_type *pupgrade);
void upgrade_draw(upgrade_type *pupgrade);
void upgrade_collision(upgrade_type *pupgrade, void* p_c_object, int c_object);
-void bullet_init(bullet_type *pbullet);
+void bullet_init(bullet_type* pbullet, float x, float y, float xm, int dir);
void bullet_action(bullet_type *pbullet);
void bullet_draw(bullet_type *pbullet);
void bullet_collision(bullet_type *pbullet, int c_object);
unsigned int cur_time = SDL_GetTicks();
double frame_ratio = (float)(cur_time-pbase->updated)/(float)(FRAME_RATE);
pbase->updated = cur_time;
- return frame_ratio;
+ return (frame_ratio == 0 ? 1 : frame_ratio);
}
#include "defines.h"
#include "world.h"
+
+void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y)
+{
+ pbouncy_distro->base.alive = YES;
+ pbouncy_distro->base.x = x;
+ pbouncy_distro->base.y = y;
+ pbouncy_distro->base.ym = -6;
+}
+
void bouncy_distro_action(bouncy_distro_type* pbouncy_distro)
{
if (pbouncy_distro->base.alive)
}
}
+void broken_brick_init(broken_brick_type* pbroken_brick, float x, float y, float xm, float ym)
+{
+ pbroken_brick->base.alive = YES;
+ pbroken_brick->base.x = x;
+ pbroken_brick->base.y = y;
+ pbroken_brick->base.xm = xm;
+ pbroken_brick->base.ym = ym;
+ timer_start(&pbroken_brick->timer,200);
+ pbroken_brick->base.updated = SDL_GetTicks();
+}
+
void broken_brick_action(broken_brick_type* pbroken_brick)
{
+ double frame_ratio = get_frame_ratio(&pbroken_brick->base);
+
if (pbroken_brick->base.alive)
{
- 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->base.x = pbroken_brick->base.x + pbroken_brick->base.xm * frame_ratio;
+ pbroken_brick->base.y = pbroken_brick->base.y + pbroken_brick->base.ym * frame_ratio;
- pbroken_brick->base.ym++;
-
- if (pbroken_brick->base.ym >= 0)
+ if (!timer_check(&pbroken_brick->timer))
pbroken_brick->base.alive = NO;
}
}
}
}
+void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y)
+{
+ pbouncy_brick->base.alive = YES;
+ pbouncy_brick->base.x = x;
+ pbouncy_brick->base.y = y;
+ pbouncy_brick->offset = 0;
+ pbouncy_brick->offset_m = -BOUNCY_BRICK_SPEED;
+ pbouncy_brick->shape = shape(x, y);
+ pbouncy_brick->base.updated = SDL_GetTicks();
+}
+
void bouncy_brick_action(bouncy_brick_type* pbouncy_brick)
{
+
+ double frame_ratio = get_frame_ratio(&pbouncy_brick->base);
+
if (pbouncy_brick->base.alive)
{
+
pbouncy_brick->offset = (pbouncy_brick->offset +
- pbouncy_brick->offset_m);
+ pbouncy_brick->offset_m * frame_ratio);
/* Go back down? */
/* Stop bouncing? */
- if (pbouncy_brick->offset == 0)
+ if (pbouncy_brick->offset >= 0)
pbouncy_brick->base.alive = NO;
}
}
}
}
-void floating_score_init(floating_score_type* pfloating_score, int x, int y, int s)
+void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s)
{
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;
+ pfloating_score->base.updated = SDL_GetTicks();
+
}
void floating_score_action(floating_score_type* pfloating_score)
{
+double frame_ratio = get_frame_ratio(&pfloating_score->base);
+
if (pfloating_score->base.alive)
{
- pfloating_score->base.y = pfloating_score->base.y - 2;
+ pfloating_score->base.y = pfloating_score->base.y - 2 * frame_ratio;
if(!timer_check(&pfloating_score->timer))
pfloating_score->base.alive = NO;
texture_type img_distro[4];
-void bouncy_distro_init(bouncy_distro_type* pbouncy_distro);
+void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y);
void bouncy_distro_action(bouncy_distro_type* pbouncy_distro);
void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro);
void bouncy_distro_collision(bouncy_distro_type* pbouncy_distro, int c_object);
#define BOUNCY_BRICK_MAX_OFFSET 8
-#define BOUNCY_BRICK_SPEED 4
+#define BOUNCY_BRICK_SPEED 0.9
typedef struct broken_brick_type
{
base_type base;
+ timer_type timer;
}
broken_brick_type;
+void broken_brick_init(broken_brick_type* pbroken_brick, float x, float y, float xm, float ym);
void broken_brick_action(broken_brick_type* pbroken_brick);
void broken_brick_draw(broken_brick_type* pbroken_brick);
}
bouncy_brick_type;
+void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y);
void bouncy_brick_action(bouncy_brick_type* pbouncy_brick);
void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick);
}
floating_score_type;
-void floating_score_init(floating_score_type* pfloating_score, int x, int y, int s);
+void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s);
void floating_score_action(floating_score_type* pfloating_score);
void floating_score_draw(floating_score_type* pfloating_score);