// Description:
//
//
-// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
+// Author: Tobias Glaesser <tobi.web@gmx.de> & Bill Kendrick, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
void badguy_init(bad_guy_type* pbad, float x, float y, int kind)
{
- pbad->base.updated = SDL_GetTicks();
pbad->base.width = 32;
pbad->base.height = 32;
pbad->base.alive = YES;
pbad->base.x = x;
pbad->base.y = y;
pbad->base.xm = 1.3;
- pbad->base.ym = 1.5;
+ pbad->base.ym = 4.8;
pbad->dir = LEFT;
pbad->seen = NO;
timer_init(&pbad->timer);
void badguy_action(bad_guy_type* pbad)
{
- double frame_ratio = get_frame_ratio(&pbad->base);
-
if (pbad->base.alive)
{
if (pbad->seen)
/* Move vertically: */
- pbad->base.y = pbad->base.y + pbad->base.ym *frame_ratio;
+ pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
/* Fall if we get off the ground: */
{
if (pbad->base.ym < MAX_YM)
{
- pbad->base.ym = pbad->base.ym + GRAVITY;
+ pbad->base.ym = pbad->base.ym + GRAVITY * frame_ratio;
}
}
else
}
}
else
- pbad->base.ym = pbad->base.ym + GRAVITY;
+ pbad->base.ym = pbad->base.ym + GRAVITY * frame_ratio;
if (pbad->base.y > screen->h)
pbad->base.alive = NO;
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/supertux/
- April 11, 2000 - December 28, 2003
+ April 11, 2000 - February 1, 2004
*/
#define MAX_WALK_XM 2.3
#define MAX_RUN_XM 3.2
-#define MAX_YM 10.0
-#define MAX_JUMP_TIME 1000
+#define MAX_YM 20.0
+#define MAX_JUMP_TIME 375
#define MAX_LIVES 4.0
#define WALK_SPEED 1.0
#define RUN_SPEED 1.5
-#define JUMP_SPEED 1.5
+#define JUMP_SPEED 1.2
#define GRAVITY 1.0
-#define YM_FOR_JUMP 50.0
+#define YM_FOR_JUMP 6.0
#define KILL_BOUNCE_YM 8.0
#define SKID_XM 2.0
Super Tux - Game Loop!
- by Bill Kendrick
+ by Bill Kendrick & Tobias Glaesser
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/supertux/
- April 11, 2000 - January 1st, 2004
+ April 11, 2000 - February 1st, 2004
*/
#include <stdio.h>
SDLKey key;
char level_subset[100];
char str[60];
-timer_type time_left;
float fps_fps;
/* Local function prototypes: */
clearscreen(0, 0, 0);
sprintf(str, "LEVEL %d", level);
- drawcenteredtext(str, 200, letters_red, NO_UPDATE, 1);
+ text_drawf(&red_text, str, 0, 200, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
sprintf(str, "%s", current_level.name);
- drawcenteredtext(str, 224, letters_gold, NO_UPDATE, 1);
+ text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
sprintf(str, "TUX x %d", tux.lives);
- drawcenteredtext(str, 256, letters_blue, NO_UPDATE, 1);
+ text_drawf(&blue_text, str, 0, 256, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
flipscreen();
void start_timers(void)
{
timer_start(&time_left,current_level.time_left*1000);
+ st_pause_ticks_init();
+ update_time = st_get_ticks();
}
void activate_bad_guys(void)
/* Check for menu-events, if the menu is shown */
if(show_menu)
- menu_event(key);
+ menu_event(&event.key.keysym);
+
+ if(player_keydown_event(&tux,key))
+ break;
- if(player_keydown_event(&tux,key))
- break;
-
switch(key)
{
case SDLK_ESCAPE: /* Escape: Open/Close the menu: */
if(!game_pause)
{
if(show_menu)
+ {
show_menu = 0;
+ st_pause_ticks_stop();
+ }
else
+ {
show_menu = 1;
+ st_pause_ticks_start();
+ }
}
break;
default:
break;
case SDL_KEYUP: /* A keyrelease! */
key = event.key.keysym.sym;
-
- if(player_keyup_event(&tux,key))
- break;
-
+
+ if(player_keyup_event(&tux,key))
+ break;
+
switch(key)
{
case SDLK_p:
if(!show_menu)
{
if(game_pause)
+ {
game_pause = 0;
+ st_pause_ticks_stop();
+ }
else
+ {
game_pause = 1;
+ st_pause_ticks_start();
+ }
}
break;
case SDLK_TAB:
if(debug_mode == YES)
timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
break;
+ case SDLK_l:
+ if(debug_mode == YES)
+ --tux.lives;
+ break;
+ case SDLK_s:
+ if(debug_mode == YES)
+ score += 1000;
+ break;
default:
break;
}
switch(event.jaxis.axis)
{
case JOY_X:
- printf("X: %d\n", event.jaxis.value);
if (event.jaxis.value < -1024)
tux.input.left = DOWN;
else if (event.jaxis.value > 1024)
level++;
next_level = 0;
drawresultscreen();
- player_level_begin(&tux);
+ player_level_begin(&tux);
}
else
{
{
drawendscreen();
- if (score > highscore)
+ if (score > hs_score)
save_hs(score);
unloadlevelgfx();
unloadlevelsong();
/* --- GAME DRAW! --- */
-void game_draw()
+void game_draw(void)
{
- int x, y, i;
+ int x, y, i, s;
/* Draw screen: */
if (tux.dying && (frame % 4) == 0)
clearscreen(255, 255, 255);
+ else if(timer_check(&super_bkgd_timer))
+ texture_draw(&img_super_bkgd, 0, 0, NO_UPDATE);
else
{
- if (timer_check(&super_bkgd_timer))
- texture_draw(&img_super_bkgd, 0, 0, NO_UPDATE);
+ /* Draw the real background */
+ if(current_level.bkgd_image[0] != '\0')
+ {
+ s = scroll_x / 30;
+ texture_draw_part(&img_bkgd,s,0,0,0,img_bkgd.w - s, img_bkgd.h, NO_UPDATE);
+ texture_draw_part(&img_bkgd,0,0,screen->w - s ,0,s,img_bkgd.h, NO_UPDATE);
+ }
else
- clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue);
+ {
+ clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue);
+ }
}
/* Draw background: */
if(game_pause)
- drawcenteredtext("PAUSE",230,letters_red, NO_UPDATE, 1);
+ text_drawf(&red_text, "PAUSE", 0, 230, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
if(show_menu)
done = drawmenu();
{
/*Uint32 last_time, now_time*/
- int fps_cnt;
+ int fps_cnt, jump;
timer_type fps_timer, frame_timer;
/* Clear screen: */
loadlevelgfx(¤t_level);
activate_bad_guys();
loadlevelsong();
- highscore = load_hs();
+ load_hs();
player_init(&tux);
/* --- MAIN GAME LOOP!!! --- */
+ jump = NO;
done = 0;
quit = 0;
frame = 0;
game_draw();
do
{
- /*last_time = SDL_GetTicks();*/
+ jump = NO;
+
+ /* Set the time the last update and the time of the current update */
+ last_update_time = update_time;
+ update_time = st_get_ticks();
+
+ /* Calculate the movement-factor */
+ frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
+
if(!timer_check(&frame_timer))
- {
- timer_start(&frame_timer,25);
- ++frame;
- }
+ {
+ timer_start(&frame_timer,25);
+ ++frame;
+ }
/* Handle events: */
tux.input.old_fire = tux.input.fire;
+ printf("%lf\n",frame_ratio);
+
game_event();
}
else
SDL_Delay(50);
-
+
+ if(tux.input.down == DOWN)
+ SDL_Delay(30);
+
/*Draw the current scene to the screen */
+ /*If the machine running the game is too slow
+ skip the drawing of the frame (so the calculations are more precise and
+ the FPS aren't affected).*/
+ /*if( ! fps_fps < 50.0 )
+ game_draw();
+ else
+ jump = YES;*/ /*FIXME: Implement this tweak right.*/
game_draw();
/* Time stops in pause mode */
continue;
}
- /* Pause til next frame: */
+ /* Pause till next frame, if the machine running the game is too fast: */
+ /* FIXME: Works great for in OpenGl mode, where the CPU doesn't have to do that much. But
+ the results in SDL mode aren't perfect (thought the 100 FPS are reached), even on an AMD2500+. */
+ if(last_update_time >= update_time - 12 && jump != YES )
+ SDL_Delay(10);
- /*now_time = SDL_GetTicks();
- if (now_time < last_time + FPS)
- SDL_Delay(last_time + FPS - now_time);*/
- /*printf("%d",timer_get_left(&frame_timer));*/
- /*SDL_Delay(timer_get_left(&frame_timer) );*/
- SDL_Delay(10);
-
/* Handle time: */
/* Calculate frames per second */
if(show_fps)
{
- fps_fps = ((float)1000 / (float)timer_get_gone(&fps_timer)) * (float)fps_cnt;
- ++fps_cnt;
+ ++fps_cnt;
+ fps_fps = (1000.0 / (float)timer_get_gone(&fps_timer)) * (float)fps_cnt;
if(!timer_check(&fps_timer))
{
else if (c >= 'c' && c <= 'f')
texture_draw(&img_cloud[1][c - 'c'], x, y, NO_UPDATE);
else if (c >= 'G' && c <= 'J')
- texture_draw(&img_bkgd[0][c - 'G'], x, y, NO_UPDATE);
+ texture_draw(&img_bkgd_tile[0][c - 'G'], x, y, NO_UPDATE);
else if (c >= 'g' && c <= 'j')
- texture_draw(&img_bkgd[1][c - 'g'], x, y, NO_UPDATE);
+ texture_draw(&img_bkgd_tile[1][c - 'g'], x, y, NO_UPDATE);
else if (c == '#')
texture_draw(&img_solid[0], x, y, NO_UPDATE);
else if (c == '[')
int i;
sprintf(str, "%d", score);
- drawtext("SCORE", 0, 0, letters_blue, NO_UPDATE, 1);
- drawtext(str, 96, 0, letters_gold, NO_UPDATE, 1);
-
- sprintf(str, "%d", highscore);
- drawtext("HIGH", 0, 20, letters_blue, NO_UPDATE, 1);
- drawtext(str, 96, 20, letters_gold, NO_UPDATE, 1);
+ text_draw(&blue_text, "SCORE", 0, 0, 1, NO_UPDATE);
+ text_draw(&gold_text, str, 96, 0, 1, NO_UPDATE);
+ sprintf(str, "%d", hs_score);
+ text_draw(&blue_text, "HIGH", 0, 20, 1, NO_UPDATE);
+ text_draw(&gold_text, str, 96, 20, 1, NO_UPDATE);
+
if (timer_get_left(&time_left) > TIME_WARNING || (frame % 10) < 5)
{
sprintf(str, "%d", timer_get_left(&time_left) / 1000 );
- drawtext("TIME", 224, 0, letters_blue, NO_UPDATE, 1);
- drawtext(str, 304, 0, letters_gold, NO_UPDATE, 1);
+ text_draw(&blue_text, "TIME", 224, 0, 1, NO_UPDATE);
+ text_draw(&gold_text, str, 304, 0, 1, NO_UPDATE);
}
sprintf(str, "%d", distros);
- drawtext("DISTROS", screen->h, 0, letters_blue, NO_UPDATE, 1);
- drawtext(str, 608, 0, letters_gold, NO_UPDATE, 1);
+ text_draw(&blue_text, "DISTROS", screen->h, 0, 1, NO_UPDATE);
+ text_draw(&gold_text, str, 608, 0, 1, NO_UPDATE);
- drawtext("LIVES", screen->h, 20, letters_blue, NO_UPDATE, 1);
+ text_draw(&blue_text, "LIVES", screen->h, 20, 1, NO_UPDATE);
if(show_fps)
{
- drawtext("FPS", screen->h, 40, letters_blue, NO_UPDATE, 1);
sprintf(str, "%f", fps_fps);
- if(use_gl) /* FIXME: We need this check as text doesn't work in OpenGl mode. */
- printf("%f\n",fps_fps);
- drawtext(str, screen->h + 60, 40, letters_gold, NO_UPDATE, 1);
+ text_draw(&blue_text, "FPS", screen->h, 40, 1, NO_UPDATE);
+ text_draw(&blue_text, str, screen->h + 60, 40, 1, NO_UPDATE);
}
for(i=0; i < tux.lives; ++i)
clearscreen(0, 0, 0);
- drawcenteredtext("GAMEOVER", 200, letters_red, NO_UPDATE, 1);
+ text_drawf(&blue_text, "GAMEOVER", 0, 200, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
sprintf(str, "SCORE: %d", score);
- drawcenteredtext(str, 224, letters_gold, NO_UPDATE, 1);
+ text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
sprintf(str, "DISTROS: %d", distros);
- drawcenteredtext(str, 256, letters_blue, NO_UPDATE, 1);
+ text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
flipscreen();
SDL_Delay(2000);
clearscreen(0, 0, 0);
- drawcenteredtext("Result:", 200, letters_red, NO_UPDATE, 1);
+ text_drawf(&red_text, "Result:", 0, 200, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
sprintf(str, "SCORE: %d", score);
- drawcenteredtext(str, 224, letters_gold, NO_UPDATE, 1);
+ text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
sprintf(str, "DISTROS: %d", distros);
- drawcenteredtext(str, 256, letters_blue, NO_UPDATE, 1);
+ text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
flipscreen();
SDL_Delay(2000);
#define SUPERTUX_GLOBALS_H
#include <SDL.h>
+#include "text.h"
SDL_Surface * screen;
-SDL_Surface * letters_black, * letters_gold, * letters_blue, * letters_red;
+text_type black_text, gold_text, blue_text, red_text;
int use_gl, use_joystick, use_fullscreen, debug_mode, show_fps;
#include "globals.h"
#include "high_scores.h"
+#include "menu.h"
+#include "screen.h"
+#include "texture.h"
FILE * opendata(char * mode)
{
strcpy(filename, st_dir);
/* Open the high score file: */
-
+
#ifdef LINUX
+
strcat(filename, "/highscore");
#else
#ifdef WIN32
- strcat(filename, "/st_highscore.dat");
- #endif
+
+ strcat(filename, "/st_highscore.dat");
+#endif
#endif
fi = fopen(filename, mode);
free( filename );
-
+
if (fi == NULL)
{
fprintf(stderr, "Warning: I could not open the high score file ");
/* Load data from high score file: */
-int load_hs(void)
+void load_hs(void)
{
FILE * fi;
char temp[128];
- int score = 100;
-
+ hs_score = 100;
+ int c, strl;
+ strcpy(hs_name, "Grandma");
+ c = 0;
+
/* Try to open file: */
fi = opendata("r");
if (strstr(temp, "highscore=") == temp)
{
- score = atoi(temp + 10);
+ hs_score = atoi(temp + 10);
- if (score == 0)
- score = 100;
+ if (hs_score == 0)
+ hs_score = 100;
+ }
+ if (strstr(temp, "name=") == temp)
+ {
+ fprintf(stderr, "name found\n");
+ strl = strlen("name=");
+ hs_name[strl-1]='\0';
+ for(c = strl; c < strlen(temp); c++)
+ hs_name[c-strl] = temp[c];
}
}
}
fclose(fi);
}
- return score;
}
void save_hs(int score)
{
- FILE * fi;
+ texture_type bkgd;
+ texture_load(&bkgd, DATA_PREFIX "/images/highscore/highscore.png", IGNORE_ALPHA);
+
+ hs_score = score;
+
+ /* ask for player's name */
+ menumenu = MENU_HIGHSCORE;
+ show_menu = 1;
+ SDL_Event event;
+ while(show_menu)
+ {
+ texture_draw_bg(&bkgd, NO_UPDATE);
+ drawmenu();
+ flipscreen();
+ while(SDL_PollEvent(&event))
+ if(event.type == SDL_KEYDOWN)
+ menu_event(&event.key.keysym);
+ }
+
+
+ FILE * fi;
/* Try to open file: */
{
fprintf(fi, "# Supertux highscore file\n\n");
- fprintf(fi, "highscore=%d\n", score);
+ fprintf(fi, "name=%s\n", hs_name);
+ fprintf(fi, "highscore=%d\n", hs_score);
fprintf(fi, "# (File automatically created.)\n");
# include <stdio.h>
+int hs_score;
+char hs_name[62]; /* highscores global variables*/
+
void save_hs(int score);
-int load_hs();
+void load_hs();
FILE * opendata(char * mode);
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/supertux/
- April 11, 2000 - April 23, 2000
+ April 11, 2000 - February 1st, 2004
*/
#include <stdio.h>
texture_draw(&tux_sit, 270, 400, UPDATE);
texture_draw(&gown_sit, 320, 400, UPDATE);
- drawcenteredtext(intro_text[0], 456, letters_blue, UPDATE, 1);
+ text_drawf(&blue_text, intro_text[0], 0, -8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
}
/* Helicopter begins to fly in: */
erasecenteredtext(intro_text[0], 456, bkgd.sdl_surface, NO_UPDATE, 1);
- drawcenteredtext(intro_text[1], 456, letters_red, NO_UPDATE, 1);
+ text_drawf(&blue_text, intro_text[1], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
}
if (timer_get_gone(&timer) >= 2000 && timer_get_gone(&timer) < 4000)
{
/* Helicopter flying in: */
- texture_draw_part(&bkgd, 0, 32, screen->w, (copter[0].h), NO_UPDATE);
+ texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h), NO_UPDATE);
texture_draw(&copter[i % 2],
(float)(timer_get_gone(&timer) - 2000) / 5 - (copter[0].w), 32,
if (timer_get_gone(&timer) >= 4000 && timer_get_gone(&timer) < 8000)
{
/* Helicopter sits: */
- texture_draw_part(&bkgd, 0, 32, screen->w, (copter[0].h), NO_UPDATE);
+ texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h), NO_UPDATE);
texture_draw(&copter[i % 2], 400 - (copter[0].w), 32, NO_UPDATE);
update_rect(screen, 0, 32, screen->w, (copter[0].h));
erasecenteredtext(intro_text[1], 456, bkgd.sdl_surface, UPDATE, 1);
- drawcenteredtext(intro_text[2], 456, letters_red, UPDATE, 1);
+ text_drawf(&blue_text, intro_text[2], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
}
/* Beam gown up! */
texture_draw_part(&bkgd,
- 320,
+ 320, 32 + (copter[0].h), 320,
32 + (copter[0].h),
(gown_upset.w),
368 + (gown_upset.h) - (copter[0].h), NO_UPDATE);
texture_draw(&tux_mad, 270, 400, UPDATE);
erasecenteredtext(intro_text[2], 456, bkgd.sdl_surface, UPDATE, 1);
- drawcenteredtext(intro_text[3], 456, letters_gold, UPDATE, 1);
+ text_drawf(&blue_text, intro_text[3], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
}
{
/* Helicopter starting to speed off: */
- texture_draw_part(&bkgd, 0, 32, screen->w, (copter_squish.h), NO_UPDATE);
+ texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_squish.h), NO_UPDATE);
texture_draw(&copter_squish,
400 - (copter[0].w), 32,
{
/* Helicopter speeding off: */
- texture_draw_part(&bkgd, 0, 32, screen->w, (copter_stretch.h), NO_UPDATE);
+ texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_stretch.h), NO_UPDATE);
texture_draw(&copter_stretch,
(timer_get_gone(&timer) - 8250) /*(i - (8250 / FPS)) * 30*/ + 400 - (copter[0].w),
strcpy(plevel->song_title, str);
plevel->song_title[strlen(plevel->song_title)-1] = '\0';
-
+ /* (Level background image) */
+ fgets(str, sizeof(plevel->bkgd_image), fi);
+ strcpy(plevel->bkgd_image, str);
+ plevel->bkgd_image[strlen(plevel->bkgd_image)-1] = '\0';
/* (Level background color) */
fgets(str, 10, fi);
}
+/* Unload data for this level: */
+
+void unloadlevel(st_level* plevel)
+{
+ free(plevel->tiles);
+ plevel->name[0] = '\0';
+ plevel->theme[0] = '\0';
+ plevel->song_title[0] = '\0';
+ plevel->bkgd_image[0] = '\0';
+}
+
/* Load graphics: */
void loadlevelgfx(st_level *plevel)
load_level_image(&img_solid[1],plevel->theme,"solid1.png", USE_ALPHA);
load_level_image(&img_solid[2],plevel->theme,"solid2.png", USE_ALPHA);
load_level_image(&img_solid[3],plevel->theme,"solid3.png", USE_ALPHA);
-
- load_level_image(&img_bkgd[0][0],plevel->theme,"bkgd-00.png", USE_ALPHA);
- load_level_image(&img_bkgd[0][1],plevel->theme,"bkgd-01.png", USE_ALPHA);
- load_level_image(&img_bkgd[0][2],plevel->theme,"bkgd-02.png", USE_ALPHA);
- load_level_image(&img_bkgd[0][3],plevel->theme,"bkgd-03.png", USE_ALPHA);
-
- load_level_image(&img_bkgd[1][0],plevel->theme,"bkgd-10.png", USE_ALPHA);
- load_level_image(&img_bkgd[1][1],plevel->theme,"bkgd-11.png", USE_ALPHA);
- load_level_image(&img_bkgd[1][2],plevel->theme,"bkgd-12.png", USE_ALPHA);
- load_level_image(&img_bkgd[1][3],plevel->theme,"bkgd-13.png", USE_ALPHA);
+
+ load_level_image(&img_bkgd_tile[0][0],plevel->theme,"bkgd-00.png", USE_ALPHA);
+ load_level_image(&img_bkgd_tile[0][1],plevel->theme,"bkgd-01.png", USE_ALPHA);
+ load_level_image(&img_bkgd_tile[0][2],plevel->theme,"bkgd-02.png", USE_ALPHA);
+ load_level_image(&img_bkgd_tile[0][3],plevel->theme,"bkgd-03.png", USE_ALPHA);
+
+ load_level_image(&img_bkgd_tile[1][0],plevel->theme,"bkgd-10.png", USE_ALPHA);
+ load_level_image(&img_bkgd_tile[1][1],plevel->theme,"bkgd-11.png", USE_ALPHA);
+ load_level_image(&img_bkgd_tile[1][2],plevel->theme,"bkgd-12.png", USE_ALPHA);
+ load_level_image(&img_bkgd_tile[1][3],plevel->theme,"bkgd-13.png", USE_ALPHA);
+
+ if(strcmp(plevel->bkgd_image,"") != 0)
+ {
+ char fname[1024];
+ snprintf(fname, 1024, "%s/background/%s", st_dir, plevel->bkgd_image);
+ if(!faccessible(fname))
+ snprintf(fname, 1024, "%s/images/background/%s", DATA_PREFIX, plevel->bkgd_image);
+ texture_load(&img_bkgd, fname, IGNORE_ALPHA);
+ printf("%s",fname);
+ }
}
/* Free graphics data for this level: */
for (i = 0; i < 4; i++)
{
texture_free(&img_solid[i]);
- texture_free(&img_bkgd[0][i]);
- texture_free(&img_bkgd[1][i]);
+ texture_free(&img_bkgd_tile[0][i]);
+ texture_free(&img_bkgd_tile[1][i]);
}
+ texture_free(&img_bkgd);
}
/* Load a level-specific graphic... */
snprintf(fname, 1024, "%s/themes/%s/%s", st_dir, theme, file);
if(!faccessible(fname))
- snprintf(fname, 1024, "%s/images/themes/%s/%s", DATA_PREFIX, theme, file);
-
+ snprintf(fname, 1024, "%s/images/themes/%s/%s", DATA_PREFIX, theme, file);
+
texture_load(ptexture, fname, use_alpha);
}
char name[LEVEL_NAME_MAX];
char theme[100];
char song_title[100];
+ char bkgd_image[100];
unsigned char* tiles[15];
int time_left;
int bkgd_red;
int width;
} st_level;
-texture_type img_bkgd[2][4], img_solid[4], img_brick[2];
+texture_type img_bkgd, img_bkgd_tile[2][4], img_solid[4], img_brick[2];
void loadlevel(st_level* plevel, char * subset, int level);
+void unloadlevel(st_level* plevel);
void loadlevelgfx(st_level* plevel);
void unloadlevelgfx();
void load_level_image(texture_type* ptexture, char* theme, char * file, int use_alpha);
* *
***************************************************************************/
-/* December 28, 2003 - January 1st, 2004 */
+/* December 28, 2003 - February 1st, 2004 */
/* leveleditor.c - A built-in level editor for SuperTux
by Ricardo Cruz <rick2@aeiou.pt> */
key = event.key.keysym.sym;
if(show_menu)
{
- menu_event(key);
+ menu_event(&event.key.keysym);
break;
}
switch(key)
/* Draw the Bad guys: */
for (i = 0; i < num_bad_guys; ++i)
{
- /* printf("\nbad_guys[%i].alive = %i", i, bad_guys[i].alive); */
if(bad_guys[i].base.alive == NO)
continue;
/* to support frames: img_bsod_left[(frame / 5) % 4] */
texture_draw(&selection, ((int)(cursor_x - pos_x)/32)*32, cursor_y, NO_UPDATE);
sprintf(str, "%d", current_level.time_left);
- drawtext("TIME", 324, 0, letters_blue, NO_UPDATE, 1);
- drawtext(str, 404, 0, letters_gold, NO_UPDATE, 1);
+ text_draw(&blue_text, "TIME", 324, 0, 1, NO_UPDATE);
+ text_draw(&gold_text, str, 404, 0, 1, NO_UPDATE);
sprintf(str, "%s", current_level.name);
- drawtext("NAME", 0, 0, letters_blue, NO_UPDATE, 1);
- drawtext(str, 80, 0, letters_gold, NO_UPDATE, 1);
+ text_draw(&blue_text, "NAME", 0, 0, 1, NO_UPDATE);
+ text_draw(&gold_text, str, 80, 0, 1, NO_UPDATE);
- drawtext("F1 for Help", 10, 430, letters_blue, NO_UPDATE, 1);
+ text_draw(&blue_text, "F1 for Help", 10, 430, 1, NO_UPDATE);
if(show_menu)
{
fclose(fi);
- drawcenteredtext("SAVED!", 240, letters_gold, NO_UPDATE, 1);
+ text_drawf(&gold_text, "SAVED!", 0, 240, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
flipscreen();
SDL_Delay(1000);
}
"Esc - Menu"};
- drawcenteredtext("- Help -", 30, letters_red, NO_UPDATE, 2);
- drawtext("Keys:", 80, 60, letters_gold, NO_UPDATE, 1);
+ text_drawf(&red_text, "- Help -", 0, 30, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
+ text_draw(&gold_text, "Keys:", 80, 60, 1, NO_UPDATE);
int i;
for(i = 0; i < sizeof(text)/sizeof(char *); i++)
- drawtext(text[i], 40, 90+(i*16), letters_blue, NO_UPDATE, 1);
+ text_draw(&blue_text, text[i], 40, 90+(i*16), 1, NO_UPDATE);
- drawcenteredtext("Press Any Key to Continue", 460, letters_gold, NO_UPDATE, 1);
+ text_drawf(&gold_text, "Press Any Key to Continue", 0, 460, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
flipscreen();
#include <ctype.h>
#endif
+#include <string.h>
+
#include "defines.h"
#include "globals.h"
#include "menu.h"
#include "sound.h"
#include "leveleditor.h"
#include "gameloop.h"
+#include "timer.h"
+#include "high_scores.h"
/* Set defaults */
void initmenu(void)
menuitem = 0;
menumenu = 0;
menuaction = -1;
+
+ delete_character = 0;
+ strcpy(input_string, "");
}
/* ---- Menu Options - Item Sound On/off ----*/
{
if(use_sound == YES)
{
- drawcenteredtext("Sound ON", 224, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Sound ON", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
else
{
- drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
if(menuaction == MN_HIT)
else
{
if(use_sound == YES)
- drawcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Sound ON", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
else
- drawcenteredtext("Sound OFF", 224, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
}
else
/* let the user move over the deactivated option */
if (menuitem == 1)
{
- drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
else
{
- drawcenteredtext("Sound OFF", 224, letters_black, NO_UPDATE, 2);
+ text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
}
}
{
if(use_music == YES)
{
- drawcenteredtext("Music ON", 256, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Music ON", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
else
{
- drawcenteredtext("Music OFF", 256, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
if(menuaction == MN_HIT)
{ /* Disable/Enable music */
use_music = YES;
if (!playing_music())
{
- play_current_music();
+ play_current_music();
}
}
menu_change = YES;
{
if(use_music == YES)
{
- drawcenteredtext("Music ON", 256, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Music ON", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
else
{
- drawcenteredtext("Music OFF", 256, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
}
}
/* let the user move over the deactivated option */
if (menuitem == 2)
{
- drawcenteredtext("Music OFF", 256, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
else
{
- drawcenteredtext("Music OFF", 256, letters_black, NO_UPDATE, 2);
+ text_drawf(&black_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
}
}
/*The menu looks different, when the game is started */
if(menuitem == 0)
{
- drawcenteredtext("Start Game", 192, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Start Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* we are ready to start the game, if this item got hit */
{
game_started = 1;
}
}
else
- drawcenteredtext("Start Game", 192, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Start Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuitem == 1)
{
- drawcenteredtext("Options", 224, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Options", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Switch to the 'Options' menu */
{
menumenu = MENU_OPTIONS;
}
}
else
- drawcenteredtext("Options", 224, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Options", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuitem == 2)
{
- drawcenteredtext("Level editor", 256, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Level editor", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Set variables, so that the level editor is executed */
{
level_editor_started = YES;
}
}
else
- drawcenteredtext("Level editor", 256, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Level editor", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuitem == 3)
{
- drawcenteredtext("Quit", 288, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Quit", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Quit a running game or the application */
{
return 1;
}
else
{
- drawcenteredtext("Quit", 288, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Quit", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
return 0;
/*The menu looks different, when the game is started */
if(menuitem == 0)
{
- drawcenteredtext("Return To Game", 192, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Return To Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
- show_menu = 0;
+ {
+ show_menu = 0;
+ st_pause_ticks_stop();
+ }
}
else
- drawcenteredtext("Return To Game", 192, letters_blue, NO_UPDATE, 2);
-
+ text_drawf(&blue_text, "Return To Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
+
if(menuitem == 1)
{
- drawcenteredtext("Save Game", 224, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Save Game", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
- {
- show_menu = 0;
- savegame();
- }
+ {
+ show_menu = 0;
+ savegame();
+ }
}
else
- drawcenteredtext("Save Game", 224, letters_blue, NO_UPDATE, 2);
-
+ text_drawf(&blue_text, "Save Game", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
+
if(menuitem == 2)
{
- drawcenteredtext("Load Game", 256, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Load Game", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
- {
- char *x = NULL; /* In C, you can do this... */
+ {
+ char *x = NULL; /* In C, you can do this... */
- show_menu = 0;
- loadgame(x);
- }
+ show_menu = 0;
+ loadgame(x);
+ }
}
else
- drawcenteredtext("Load Game", 256, letters_blue, NO_UPDATE, 2);
-
+ text_drawf(&blue_text, "Load Game", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
+
if(menuitem == 3)
{
- drawcenteredtext("Options", 288, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Options", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Switch to the 'Options' menu */
{
menumenu = MENU_OPTIONS;
}
}
else
- drawcenteredtext("Options", 288, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Options", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuitem == 4)
{
- drawcenteredtext("Quit Game", 320, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Quit Game", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Quit a running game */
return 1;
}
else
{
- drawcenteredtext("Quit Game", 320, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Quit Game", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
return 0;
if(menuitem == 0)
{
if(use_fullscreen)
- drawcenteredtext("Fullscreen ON", 192, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Fullscreen ON", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
else
- drawcenteredtext("Fullscreen OFF", 192, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Fullscreen OFF", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Disable/Enable fullscreen */
{
if(use_fullscreen)
else
{
if(use_fullscreen)
- drawcenteredtext("Fullscreen ON", 192, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Fullscreen ON", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
else
- drawcenteredtext("Fullscreen OFF", 192, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Fullscreen OFF", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
}
/* handle menu sound on/off option */
if(menuitem == 3)
{
- drawcenteredtext("Back", 288, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Back", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Go back to main menu. */
{
if(game_started)
}
}
else
- drawcenteredtext("Back", 288, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Back", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
return 0;
}
if(menuitem == 0)
{
- drawcenteredtext("Return To Level Editor", 192, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Return To Level Editor", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
show_menu = 0;
}
else
- drawcenteredtext("Return To Level Editor", 192, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Return To Level Editor", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuitem == 1)
{
- drawcenteredtext("New Level", 224, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "New Level", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
{
show_menu = 0;
}
}
else
- drawcenteredtext("New Level", 224, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "New Level", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
+
if(menuitem == 2)
{
- drawcenteredtext("Load Level", 256, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Load Level", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Create a new Level and load it into the level-editor. */
{
show_menu = 0;
}
}
else
- drawcenteredtext("Load Level", 256, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Load Level", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
+
if(menuitem == 3)
{
- drawcenteredtext("Save Level", 288, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Save Level", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Save the current level in the level-editor. */
{
show_menu = 0;
}
}
else
- drawcenteredtext("Save Level", 288, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Save Level", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuitem == 4)
{
- drawcenteredtext("Quit Level Editor", 320, letters_red, NO_UPDATE, 2);
+ text_drawf(&red_text, "Quit Level Editor", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
if(menuaction == MN_HIT) /* Quit the level-editor. (to the main-menu) */
{
return 1;
}
}
else
- drawcenteredtext("Quit Level Editor", 320, letters_blue, NO_UPDATE, 2);
+ text_drawf(&blue_text, "Quit Level Editor", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
return 0;
}
+/* Menu HighScore (ask for player's name) */
+int menu_highscore()
+{
+while(delete_character > 0) /* remove charactes */
+ {
+ hs_name[strlen(hs_name)-1] = '\0';
+ delete_character--;
+ }
+
+char str[60];
+strcat(hs_name, input_string);
+
+text_drawf(&red_text, "Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
+text_draw(&red_text, "Your score:", 30, 250, 1, NO_UPDATE);
+sprintf(str, "%d", hs_score);
+text_draw(&blue_text, str, 350, 250, 1, NO_UPDATE);
+
+text_draw(&red_text, "Enter your name:", 30, 280, 1, NO_UPDATE);
+text_draw(&blue_text, hs_name, 350, 280, 1, NO_UPDATE);
+
+strcpy(input_string, "");
+
+if(menuaction == MN_HIT) /* name written */
+ show_menu = 0;
+
+return 0;
+}
+
/* --- MENU --- */
/* Draw the menu and execute the (menu)events */
int drawmenu(void)
if(menuaction == MN_UP)
- {
- /* Go one menu-item up */
- --menuitem;
- }
+ --menuitem; /* Go one menu-item up */
else if(menuaction == MN_DOWN)
- ++menuitem; /* Go one menu-item down */
+ ++menuitem; /* Go one menu-item down */
- if(menumenu == MENU_MAIN)
- {
+ switch(menumenu)
+ {
+ case MENU_MAIN:
quit = menu_main();
- }
- else if(menumenu == MENU_GAME)
- {
+ break;
+ case MENU_GAME:
quit = menu_game();
- }
- else if(menumenu == MENU_OPTIONS)
- {
+ break;
+ case MENU_OPTIONS:
quit = menu_options();
- }
- else if(menumenu == MENU_LEVELEDITOR)
- {
+ break;
+ case MENU_LEVELEDITOR:
quit = menu_leveleditor();
- }
+ break;
+ case MENU_HIGHSCORE:
+ quit = menu_highscore();
+ break;
+ default:
+ break;
+ }
menuaction = -1;
}
/* Check for menu event */
-void menu_event(SDLKey key)
+void menu_event(SDL_keysym* keysym)
{
+SDLKey key = keysym->sym;
+SDLMod keymod;
+keymod = SDL_GetModState();
+char ch[2];
+
+/* If the current unicode character is an ASCII character,
+ assign it to ch. */
+if ( (keysym->unicode & 0xFF80) == 0 ) {
+ ch[0] = keysym->unicode & 0x7F;
+ ch[1] = '\0';
+}
+else {
+ /* An International Character. */
+}
+switch(key)
+ {
+ case SDLK_UP: /* Menu Up */
+ menuaction = MN_UP;
+ menu_change = YES;
+ break;
+ case SDLK_DOWN: /* Menu Down */
+ menuaction = MN_DOWN;
+ menu_change = YES;
+ break;
+ case SDLK_SPACE: /* Menu Hit */
+ case SDLK_RETURN:
+ menuaction = MN_HIT;
+ menu_change = YES;
+ break;
+
+ case SDLK_DELETE:
+ case SDLK_BACKSPACE:
+ delete_character++;
+ break;
+ default:
+ if( key >= SDLK_0 && key <= SDLK_9)
+ strcat( input_string, /* (key - SDLK_0) */ ch);
+ else if( key >= SDLK_a && SDLK_z )
+ {
+ strcat( input_string, ch);
+ }
+ break;
+ }
- if (key == SDLK_UP)
- {
- /* Menu Up */
-
- menuaction = MN_UP;
- menu_change = YES;
- }
- else if (key == SDLK_DOWN)
- {
- /* Menu Down */
-
- menuaction = MN_DOWN;
- menu_change = YES;
- }
- else if (key == SDLK_SPACE || key == SDLK_RETURN)
- {
- /* Menu Hit */
-
- menuaction = MN_HIT;
- menu_change = YES;
- }
/* FIXME: NO JOYSTICK SUPPORT */
/*#ifdef JOY_YES
else if (event.type == SDL_JOYBUTTONDOWN)
{
- Joystick button: Continue:
-
+ Joystick button: Continue:
+
done = 1;
}
#endif*/
-
}
MENU_MAIN,
MENU_GAME,
MENU_OPTIONS,
- MENU_LEVELEDITOR
+ MENU_LEVELEDITOR,
+ MENU_HIGHSCORE
};
+/* input implementation variables */
+int delete_character;
+char input_string[62];
+
/* Initialize the menu variables */
void initmenu(void);
int drawmenu(void);
/* Check for a menu event */
-void menu_event(SDLKey key);
+void menu_event(SDL_keysym* keysym);
#endif /*SUPERTUX_MENU_H*/
// Description:
//
//
-// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
+// Author: Tobias Glaesser <tobi.web@gmx.de> & Bill Kendrick, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
pplayer->base.width = 32;
pplayer->base.height = 32;
- pplayer->base.updated = SDL_GetTicks();
pplayer->size = SMALL;
pplayer->got_coffee = NO;
pplayer->keymap.left = SDLK_LEFT;
pplayer->keymap.right = SDLK_RIGHT;
pplayer->keymap.fire = SDLK_LCTRL;
-
+
timer_init(&pplayer->invincible_timer);
timer_init(&pplayer->skidding_timer);
timer_init(&pplayer->safe_timer);
int player_keydown_event(player_type* pplayer, SDLKey key)
{
- if(key == pplayer->keymap.right)
- {
- pplayer->input.right = DOWN;
- return YES;
- }
- else if( key == pplayer->keymap.left)
- {
- pplayer->input.left = DOWN;
- return YES;
- }
- else if(key == pplayer->keymap.jump)
- {
- pplayer->input.up = DOWN;
- return YES;
- }
- else if(key == pplayer->keymap.duck)
- {
- pplayer->input.down = DOWN;
- return YES;
- }
- else if(key == pplayer->keymap.fire)
- {
- pplayer->input.fire = DOWN;
- return YES;
- }
- else
- return NO;
+ if(key == pplayer->keymap.right)
+ {
+ pplayer->input.right = DOWN;
+ return YES;
+ }
+ else if( key == pplayer->keymap.left)
+ {
+ pplayer->input.left = DOWN;
+ return YES;
+ }
+ else if(key == pplayer->keymap.jump)
+ {
+ pplayer->input.up = DOWN;
+ return YES;
+ }
+ else if(key == pplayer->keymap.duck)
+ {
+ pplayer->input.down = DOWN;
+ return YES;
+ }
+ else if(key == pplayer->keymap.fire)
+ {
+ pplayer->input.fire = DOWN;
+ return YES;
+ }
+ else
+ return NO;
}
-
+
int player_keyup_event(player_type* pplayer, SDLKey key)
{
- if(key == pplayer->keymap.right)
- {
- pplayer->input.right = UP;
- return YES;
- }
- else if( key == pplayer->keymap.left)
- {
- pplayer->input.left = UP;
- return YES;
- }
- else if(key == pplayer->keymap.jump)
- {
- pplayer->input.up = UP;
- return YES;
- }
- else if(key == pplayer->keymap.duck)
- {
- pplayer->input.down = UP;
- return YES;
- }
- else if(key == pplayer->keymap.fire)
- {
- pplayer->input.fire = UP;
- return YES;
- }
- else
- return NO;
+ if(key == pplayer->keymap.right)
+ {
+ pplayer->input.right = UP;
+ return YES;
+ }
+ else if( key == pplayer->keymap.left)
+ {
+ pplayer->input.left = UP;
+ return YES;
+ }
+ else if(key == pplayer->keymap.jump)
+ {
+ pplayer->input.up = UP;
+ return YES;
+ }
+ else if(key == pplayer->keymap.duck)
+ {
+ pplayer->input.down = UP;
+ return YES;
+ }
+ else if(key == pplayer->keymap.fire)
+ {
+ pplayer->input.fire = UP;
+ return YES;
+ }
+ else
+ return NO;
}
void player_level_begin(player_type* pplayer)
pplayer->base.y = 240;
pplayer->base.xm = 0;
pplayer->base.ym = 0;
-
+
pplayer->input.down = UP;
pplayer->input.fire = UP;
pplayer->input.left = UP;
void player_action(player_type* pplayer)
{
-
- double frame_ratio = get_frame_ratio(&pplayer->base);
-
/* --- HANDLE TUX! --- */
player_input(pplayer);
++debug_int;
if(debug_int > 32)
DEBUG_MSG("FIXME - UNDER certain circumstances I'm hanging in a loop here!");
-
+ /*the circumstances are:
+ issolid() is true and base.ym == 0
+ use of floating point varibles for base stuff*/
if (pplayer->base.ym < 0)
pplayer->base.y++;
else if (pplayer->base.ym > 0)
pplayer->base.ym = 0;
pplayer->jumping = NO;
+ pplayer->input.up = UP;
}
timer_check(&pplayer->safe_timer);
-
+
/* ---- DONE HANDLING TUX! --- */
/* Handle invincibility timer: */
- if (timer_check(&pplayer->invincible_timer))
+ if (current_music == HERRING_MUSIC && !timer_check(&pplayer->invincible_timer))
{
- if (current_music == HERRING_MUSIC)
+ /*
+ no, we are no more invincible
+ or we were not in invincible mode
+ but are we in hurry ?
+ */
+
+
+ if (timer_get_left(&time_left) < TIME_WARNING)
{
- if (current_level.time_left <= TIME_WARNING)
- {
- /* stop the herring_song, prepare to play the correct
- * fast level_song !
- */
- current_music = HURRYUP_MUSIC;
- }
- else
- {
- current_music = LEVEL_MUSIC;
- }
- /* stop the old music if it's being played */
- if (playing_music())
- halt_music();
+ /* yes, we are in hurry
+ stop the herring_song, prepare to play the correct
+ fast level_song !
+ */
+ current_music = HURRYUP_MUSIC;
}
+ else
+ {
+ current_music = LEVEL_MUSIC;
+ }
+
+ /* stop the old music if it's being played */
+ if (playing_music())
+ halt_music();
}
/* Handle skidding: */
timer_check(&pplayer->skidding_timer);
-
+
/* End of level? */
if (pplayer->base.x>= endpos && endpos != 0)
}
-void player_input(player_type *pplayer)
+void player_handle_horizontal_input(player_type *pplayer, int dir)
{
- /* Handle key and joystick state: */
-
-
- if (pplayer->input.right == DOWN && pplayer->input.left == UP)
- {
- if (pplayer->jumping == NO)
- {
- if (pplayer->base.xm < -SKID_XM && !timer_started(&pplayer->skidding_timer) &&
- pplayer->dir == LEFT)
- {
- timer_start(&pplayer->skidding_timer, SKID_TIME);
-
- play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
-
- }
- pplayer->dir = RIGHT;
- }
-
- if (pplayer->base.xm < 0 && !isice(pplayer->base.x, pplayer->base.y + 32) &&
- !timer_started(&pplayer->skidding_timer))
- {
- pplayer->base.xm = 0;
- }
-
- if (!pplayer->duck)
- {
- if (pplayer->dir == RIGHT)
- {
- /* Facing the direction we're jumping? Go full-speed: */
-
- if (pplayer->input.fire == UP)
- {
- pplayer->base.xm = pplayer->base.xm + WALK_SPEED;
-
- 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 + RUN_SPEED;
-
- if (pplayer->base.xm > MAX_RUN_XM)
- pplayer->base.xm = MAX_RUN_XM;
- }
- }
- else
- {
- /* Not facing the direction we're jumping?
- Go half-speed: */
-
- pplayer->base.xm = pplayer->base.xm + WALK_SPEED / 2;
-
- if (pplayer->base.xm > MAX_WALK_XM / 2)
- pplayer->base.xm = MAX_WALK_XM / 2;
- }
- }
- }
- else if (pplayer->input.left == DOWN && pplayer->input.right == UP)
- {
- if (pplayer->jumping == NO)
- {
- if (pplayer->base.xm > SKID_XM && !timer_started(&pplayer->skidding_timer) &&
- pplayer->dir == RIGHT)
- {
- timer_start(&pplayer->skidding_timer,SKID_TIME);
- play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
- }
- pplayer->dir = LEFT;
- }
-
- if (pplayer->base.xm > 0 && !isice(pplayer->base.x, pplayer->base.y + 32) &&
- !timer_started(&pplayer->skidding_timer))
- {
- pplayer->base.xm = 0;
- }
-
- if (!pplayer->duck)
- {
- if (pplayer->dir == LEFT)
- {
- /* Facing the direction we're jumping? Go full-speed: */
-
- if (pplayer->input.fire == UP)
- {
- pplayer->base.xm = pplayer->base.xm - WALK_SPEED;
-
- 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 - RUN_SPEED;
-
- if (pplayer->base.xm < -MAX_RUN_XM)
- pplayer->base.xm = -MAX_RUN_XM;
- }
- }
- else
- {
- /* Not facing the direction we're jumping?
- Go half-speed: */
-
- pplayer->base.xm = pplayer->base.xm - WALK_SPEED / 2;
-
- if (pplayer->base.xm < -MAX_WALK_XM / 2)
- pplayer->base.xm = -MAX_WALK_XM / 2;
- }
- }
- }
-
- /* Jump/jumping? */
-
- if ( pplayer->input.up == DOWN)
+ if (pplayer->jumping == NO)
{
- if(!timer_started(&pplayer->jump_timer))
- {
- timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
-
-
- /* Taking off? */
-
- if (!issolid(pplayer->base.x, pplayer->base.y + 32) ||
- pplayer->base.ym != 0)
- {
- /* If they're not on the ground, or are currently moving
- vertically, don't jump! */
-
- pplayer->jumping = NO;
- timer_stop(&pplayer->jump_timer);
- }
- else
- {
- /* Make sure we're not standing back up into a solid! */
-
- if (pplayer->size == SMALL || pplayer->duck == NO ||
- !issolid(pplayer->base.x, pplayer->base.y))
- {
- pplayer->jumping = YES;
-
- if (pplayer->size == SMALL)
- play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER);
- else
- play_sound(sounds[SND_BIGJUMP], SOUND_CENTER_SPEAKER);
- }
- }
- }
-
- /* Keep jumping for a while: */
-
- if (timer_check(&pplayer->jump_timer))
+ if ((dir ? (pplayer->base.xm < -SKID_XM) : (pplayer->base.xm > SKID_XM)) && !timer_started(&pplayer->skidding_timer) &&
+ pplayer->dir == !dir)
{
- pplayer->base.ym = pplayer->base.ym - JUMP_SPEED;
- }
- }
- else
- timer_stop(&pplayer->jump_timer);
-
-
- /* Shoot! */
-
- if (pplayer->input.fire == DOWN && pplayer->input.old_fire == UP && pplayer->got_coffee)
- {
- add_bullet(pplayer->base.x, pplayer->base.y, pplayer->base.xm, pplayer->dir);
- }
-
-
- /* Duck! */
+ timer_start(&pplayer->skidding_timer, SKID_TIME);
- if (pplayer->input.down == DOWN)
- {
- if (pplayer->size == BIG)
- pplayer->duck = YES;
- }
- else
- {
- if (pplayer->size == BIG && pplayer->duck == YES)
- {
- /* Make sure we're not standing back up into a solid! */
+ play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
- if (!issolid(pplayer->base.x, pplayer->base.y - 32))
- pplayer->duck = NO;
}
- else
- pplayer->duck = NO;
+ pplayer->dir = dir;
}
- /* (Tux): */
-
- if (pplayer->input.right == UP && pplayer->input.left == UP)
+ if ((dir ? (pplayer->base.xm < 0) : (pplayer->base.xm > 0)) && !isice(pplayer->base.x, pplayer->base.y + 32) &&
+ !timer_started(&pplayer->skidding_timer))
{
- pplayer->frame_main = 1;
- pplayer->frame = 1;
- }
- else
- {
- if ((pplayer->input.fire == DOWN && (frame % 2) == 0) ||
- (frame % 4) == 0)
- pplayer->frame_main = (pplayer->frame_main + 1) % 4;
-
- pplayer->frame = pplayer->frame_main;
-
- if (pplayer->frame == 3)
- pplayer->frame = 1;
+ pplayer->base.xm = 0;
}
-}
-
-void player_grabdistros(player_type *pplayer)
-{
- /* Grab distros: */
- if (!pplayer->dying)
+ if (!pplayer->duck)
{
- 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)
+ if (pplayer->dir == dir)
{
- trygrabdistro(pplayer->base.x, pplayer->base.y - 32, NO_BOUNCE);
- trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32, NO_BOUNCE);
- }
- }
-
-
- /* Enough distros for a One-up? */
+ /* Facing the direction we're jumping? Go full-speed: */
- if (distros >= DISTROS_LIFEUP)
- {
- distros = distros - DISTROS_LIFEUP;
- if(pplayer->lives < MAX_LIVES)
- pplayer->lives++;
- /*We want to hear the sound even, if MAX_LIVES is reached*/
- play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
- }
-}
-
-void player_draw(player_type* pplayer)
-{
-
- if (!timer_started(&pplayer->safe_timer) || (frame % 2) == 0)
- {
- if (pplayer->size == SMALL)
- {
- if (timer_started(&pplayer->invincible_timer))
+ if (pplayer->input.fire == UP)
{
- /* Draw cape: */
+ pplayer->base.xm = pplayer->base.xm + ( dir ? WALK_SPEED : -WALK_SPEED) * frame_ratio;
- if (pplayer->dir == RIGHT)
- {
- texture_draw(&cape_right[frame % 2],
- pplayer->base.x- scroll_x, pplayer->base.y,
- NO_UPDATE);
- }
- else
+ if(dir)
{
- texture_draw(&cape_left[frame % 2],
- pplayer->base.x- scroll_x, pplayer->base.y,
- NO_UPDATE);
- }
- }
-
-
- if (!pplayer->got_coffee)
- {
- if (pplayer->dir == RIGHT)
- {
- texture_draw(&tux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
- }
- else
- {
- texture_draw(&tux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
- }
- }
- else
- {
- /* Tux got coffee! */
-
- if (pplayer->dir == RIGHT)
- {
- texture_draw(&firetux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
+ if (pplayer->base.xm > MAX_WALK_XM)
+ pplayer->base.xm = MAX_WALK_XM;
}
else
{
- texture_draw(&firetux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
+ if (pplayer->base.xm < -MAX_WALK_XM)
+ pplayer->base.xm = -MAX_WALK_XM;
}
}
- }
- else
- {
- if (timer_started(&pplayer->invincible_timer))
+ else if ( pplayer->input.fire == DOWN)
{
- /* Draw cape: */
+ pplayer->base.xm = pplayer->base.xm + ( dir ? RUN_SPEED : -RUN_SPEED) * frame_ratio;
- if (pplayer->dir == RIGHT)
+ if(dir)
{
- texture_draw(&bigcape_right[frame % 2],
- pplayer->base.x- scroll_x - 8 - 16, pplayer->base.y - 32,
- NO_UPDATE);
- }
- else
- {
- texture_draw(&bigcape_left[frame % 2],
- pplayer->base.x-scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- }
-
- if (!pplayer->got_coffee)
- {
- if (!pplayer->duck)
- {
- if (!timer_started(&pplayer->skidding_timer))
- {
- if (!pplayer->jumping || pplayer->base.ym > 0)
- {
- if (pplayer->dir == RIGHT)
- {
- texture_draw(&bigtux_right[pplayer->frame],
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- else
- {
- texture_draw(&bigtux_left[pplayer->frame],
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- }
- else
- {
- if (pplayer->dir == RIGHT)
- {
- texture_draw(&bigtux_right_jump,
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- else
- {
- texture_draw(&bigtux_left_jump,
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- }
- }
- else
- {
- if (pplayer->dir == RIGHT)
- {
- texture_draw(&skidtux_right,
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- else
- {
- texture_draw(&skidtux_left,
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- }
+ if (pplayer->base.xm > MAX_RUN_XM)
+ pplayer->base.xm = MAX_RUN_XM;
}
else
{
- if (pplayer->dir == RIGHT)
- {
- texture_draw(&ducktux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
- NO_UPDATE);
- }
- else
- {
- texture_draw(&ducktux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
- NO_UPDATE);
- }
+ if (pplayer->base.xm < -MAX_RUN_XM)
+ pplayer->base.xm = -MAX_RUN_XM;
}
}
else
{
- /* Tux has coffee! */
-
- if (!pplayer->duck)
- {
- if (!timer_started(&pplayer->skidding_timer))
- {
- if (!pplayer->jumping || pplayer->base.ym > 0)
- {
- if (pplayer->dir == RIGHT)
- {
- texture_draw(&bigfiretux_right[pplayer->frame],
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- else
- {
- texture_draw(&bigfiretux_left[pplayer->frame],
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- }
- else
- {
- if (pplayer->dir == RIGHT)
- {
- texture_draw(&bigfiretux_right_jump,
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- else
- {
- texture_draw(&bigfiretux_left_jump,
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- }
- }
- else
- {
- if (pplayer->dir == RIGHT)
- {
- texture_draw(&skidfiretux_right,
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- else
- {
- texture_draw(&skidfiretux_left,
- pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
- NO_UPDATE);
- }
- }
- }
- else
- {
- if (pplayer->dir == RIGHT)
- {
- texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
- NO_UPDATE);
- }
- else
- {
- texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
- NO_UPDATE);
- }
- }
- }
- }
- }
-
-}
-
-void player_collision(player_type* pplayer, void* p_c_object, int c_object)
-{
- bad_guy_type* pbad_c = NULL;
-
- switch (c_object)
- {
- case CO_BADGUY:
- pbad_c = p_c_object;
- /* Hurt the player if he just touched it: */
-
- if (!pbad_c->dying && !pplayer->dying &&
- !timer_started(&pplayer->safe_timer) &&
- pbad_c->mode != HELD)
- {
- if (pbad_c->mode == FLAT && pplayer->input.fire != DOWN)
- {
- /* Kick: */
-
- pbad_c->mode = KICK;
- play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
-
- if (pplayer->base.x<= pbad_c->base.x)
- {
- pbad_c->dir = RIGHT;
- pbad_c->base.x = pbad_c->base.x + 16;
- }
- else
- {
- pbad_c->dir = LEFT;
- 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->base.y-=8;
- }
- else if (pbad_c->mode == KICK)
- {
- if (pplayer->base.y < pbad_c->base.y - 16 &&
- timer_started(&pbad_c->timer))
- {
- /* Step on (stop being kicked) */
+ /* Not facing the direction we're jumping?
+ Go half-speed: */
- pbad_c->mode = FLAT;
- play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
- timer_start(&pbad_c->timer, 10000);
- }
- else
- {
- /* Hurt if you get hit by kicked laptop: */
+ pplayer->base.xm = pplayer->base.xm + ( dir ? (WALK_SPEED / 2) : -(WALK_SPEED / 2)) * frame_ratio;
- if (timer_started(&pbad_c->timer))
- {
- if (!timer_started(&pplayer->invincible_timer))
- {
- player_kill(pplayer,SHRINK);
- }
- else
- {
- pbad_c->dying = FALLING;
- pbad_c->base.ym = -8;
- play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
- }
- }
- }
- }
- else
- {
- if (!timer_started(&pplayer->invincible_timer ))
+ if(dir)
{
- player_kill(pplayer,SHRINK);
+ if (pplayer->base.xm > MAX_WALK_XM / 2)
+ pplayer->base.xm = MAX_WALK_XM / 2;
}
else
{
- pbad_c->dying = FALLING;
- pbad_c->base.ym = -8;
- play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
+ if (pplayer->base.xm < -MAX_WALK_XM / 2)
+ pplayer->base.xm = -MAX_WALK_XM / 2;
}
}
}
- score_multiplier++;
- break;
- }
-
-}
-
-/* Kill Player! */
-
-void player_kill(player_type* pplayer, int mode)
-{
- pplayer->base.ym = -5;
-
- play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER);
-
- if (pplayer->dir == RIGHT)
- pplayer->base.xm = -8;
- else if (tux.dir == LEFT)
- pplayer->base.xm = 8;
-
- if (mode == SHRINK && pplayer->size == BIG)
- {
- if (pplayer->got_coffee)
- pplayer->got_coffee = NO;
-
- pplayer->size = SMALL;
- timer_start(&pplayer->safe_timer,TUX_SAFE_TIME);
- }
- else
- {
- pplayer->dying = 1;
}
}
-void player_dying(player_type *pplayer)
+void player_handle_vertical_input(player_type *pplayer)
{
- pplayer->base.ym = pplayer->base.ym + GRAVITY;
-
- /* He died :^( */
-
- --pplayer->lives;
- player_remove_powerups(pplayer);
- pplayer->dying = NO;
-
- player_level_begin(pplayer);
-
-}
-
-/* Remove Tux's power ups */
-void player_remove_powerups(player_type* pplayer)
-{
- pplayer->got_coffee = NO;
- pplayer->size = SMALL;
-}
-
-void player_keep_in_bounds(player_type* pplayer)
-{
- /* Keep tux in bounds: */
- 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->base.x- 160;
- /*pplayer->base.x+= 160;*/
-
- if(scroll_x < 0)
- scroll_x = 0;
-
- }
- 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->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->base.x> 608 + scroll_x)
- {
- /* ... unless there's no more to scroll! */
-
- /*pplayer->base.x= 608 + scroll_x;*/
- }
-
- /* Keep in-bounds, vertically: */
-
- if (pplayer->base.y < 0)
- pplayer->base.y = 0;
- else if (pplayer->base.y > screen->h)
- {
- player_kill(&tux,KILL);
- }
-}
+ if(!timer_started(&pplayer->jump_timer))
+ {
+ timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
+
+
+ /* Taking off? */
+
+ if (!issolid(pplayer->base.x, pplayer->base.y + 32) ||
+ pplayer->base.ym != 0)
+ {
+ /* If they're not on the ground, or are currently moving
+ vertically, don't jump! */
+
+ pplayer->jumping = NO;
+ timer_stop(&pplayer->jump_timer);
+ }
+ else
+ {
+ /* Make sure we're not standing back up into a solid! */
+
+ if (pplayer->size == SMALL || pplayer->duck == NO ||
+ !issolid(pplayer->base.x, pplayer->base.y))
+ {
+ pplayer->jumping = YES;
+
+ if (pplayer->size == SMALL)
+ play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER);
+ else
+ play_sound(sounds[SND_BIGJUMP], SOUND_CENTER_SPEAKER);
+ }
+ }
+ }
+
+ /* Keep jumping for a while: */
+
+ if (timer_check(&pplayer->jump_timer))
+ {
+ pplayer->base.ym = pplayer->base.ym - JUMP_SPEED * frame_ratio;
+ if (pplayer->base.ym < -YM_FOR_JUMP)
+ pplayer->base.ym = -YM_FOR_JUMP;
+ }
+ }
+
+ void player_input(player_type *pplayer)
+ {
+ /* Handle key and joystick state: */
+
+
+ if (pplayer->input.right == DOWN && pplayer->input.left == UP)
+ {
+ player_handle_horizontal_input(pplayer,RIGHT);
+ }
+ else if (pplayer->input.left == DOWN && pplayer->input.right == UP)
+ {
+ player_handle_horizontal_input(pplayer,LEFT);
+ }
+
+ /* Jump/jumping? */
+
+ if ( pplayer->input.up == DOWN)
+ {
+ player_handle_vertical_input(pplayer);
+ }
+ else
+ timer_stop(&pplayer->jump_timer);
+
+ /* Shoot! */
+
+ if (pplayer->input.fire == DOWN && pplayer->input.old_fire == UP && pplayer->got_coffee)
+ {
+ add_bullet(pplayer->base.x, pplayer->base.y, pplayer->base.xm, pplayer->dir);
+ }
+
+
+ /* Duck! */
+
+ if (pplayer->input.down == DOWN)
+ {
+ if (pplayer->size == BIG)
+ pplayer->duck = YES;
+ }
+ else
+ {
+ if (pplayer->size == BIG && pplayer->duck == YES)
+ {
+ /* Make sure we're not standing back up into a solid! */
+
+ if (!issolid(pplayer->base.x, pplayer->base.y - 32))
+ pplayer->duck = NO;
+ }
+ else
+ pplayer->duck = NO;
+ }
+
+ /* (Tux): */
+
+ if (pplayer->input.right == UP && pplayer->input.left == UP)
+ {
+ pplayer->frame_main = 1;
+ pplayer->frame = 1;
+ }
+ else
+ {
+ if ((pplayer->input.fire == DOWN && (frame % 2) == 0) ||
+ (frame % 4) == 0)
+ pplayer->frame_main = (pplayer->frame_main + 1) % 4;
+
+ pplayer->frame = pplayer->frame_main;
+
+ if (pplayer->frame == 3)
+ pplayer->frame = 1;
+ }
+
+ }
+
+ void player_grabdistros(player_type *pplayer)
+ {
+ /* Grab distros: */
+ if (!pplayer->dying)
+ {
+ trygrabdistro(pplayer->base.x, pplayer->base.y, NO_BOUNCE);
+ trygrabdistro(pplayer->base.x+ 31, pplayer->base.y, NO_BOUNCE);
+
+ if (pplayer->size == BIG && !pplayer->duck)
+ {
+ trygrabdistro(pplayer->base.x, pplayer->base.y - 32, NO_BOUNCE);
+ trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32, NO_BOUNCE);
+ }
+ }
+
+
+ /* Enough distros for a One-up? */
+
+ if (distros >= DISTROS_LIFEUP)
+ {
+ distros = distros - DISTROS_LIFEUP;
+ if(pplayer->lives < MAX_LIVES)
+ pplayer->lives++;
+ /*We want to hear the sound even, if MAX_LIVES is reached*/
+ play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
+ }
+ }
+
+ void player_draw(player_type* pplayer)
+ {
+
+ if (!timer_started(&pplayer->safe_timer) || (frame % 2) == 0)
+ {
+ if (pplayer->size == SMALL)
+ {
+ if (timer_started(&pplayer->invincible_timer))
+ {
+ /* Draw cape: */
+
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&cape_right[frame % 2],
+ pplayer->base.x- scroll_x, pplayer->base.y,
+ NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&cape_left[frame % 2],
+ pplayer->base.x- scroll_x, pplayer->base.y,
+ NO_UPDATE);
+ }
+ }
+
+
+ if (!pplayer->got_coffee)
+ {
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&tux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&tux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
+ }
+ }
+ else
+ {
+ /* Tux got coffee! */
+
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&firetux_right[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&firetux_left[pplayer->frame], pplayer->base.x- scroll_x, pplayer->base.y, NO_UPDATE);
+ }
+ }
+ }
+ else
+ {
+ if (timer_started(&pplayer->invincible_timer))
+ {
+ /* Draw cape: */
+
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&bigcape_right[frame % 2],
+ pplayer->base.x- scroll_x - 8 - 16, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&bigcape_left[frame % 2],
+ pplayer->base.x-scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ }
+
+ if (!pplayer->got_coffee)
+ {
+ if (!pplayer->duck)
+ {
+ if (!timer_started(&pplayer->skidding_timer))
+ {
+ if (!pplayer->jumping || pplayer->base.ym > 0)
+ {
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&bigtux_right[pplayer->frame],
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&bigtux_left[pplayer->frame],
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ }
+ else
+ {
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&bigtux_right_jump,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&bigtux_left_jump,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ }
+ }
+ else
+ {
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&skidtux_right,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&skidtux_left,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ }
+ }
+ else
+ {
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&ducktux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
+ NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&ducktux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
+ NO_UPDATE);
+ }
+ }
+ }
+ else
+ {
+ /* Tux has coffee! */
+
+ if (!pplayer->duck)
+ {
+ if (!timer_started(&pplayer->skidding_timer))
+ {
+ if (!pplayer->jumping || pplayer->base.ym > 0)
+ {
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&bigfiretux_right[pplayer->frame],
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&bigfiretux_left[pplayer->frame],
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ }
+ else
+ {
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&bigfiretux_right_jump,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&bigfiretux_left_jump,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ }
+ }
+ else
+ {
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&skidfiretux_right,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&skidfiretux_left,
+ pplayer->base.x- scroll_x - 8, pplayer->base.y - 32,
+ NO_UPDATE);
+ }
+ }
+ }
+ else
+ {
+ if (pplayer->dir == RIGHT)
+ {
+ texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
+ NO_UPDATE);
+ }
+ else
+ {
+ texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
+ NO_UPDATE);
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ void player_collision(player_type* pplayer, void* p_c_object, int c_object)
+ {
+ bad_guy_type* pbad_c = NULL;
+
+ switch (c_object)
+ {
+ case CO_BADGUY:
+ pbad_c = p_c_object;
+ /* Hurt the player if he just touched it: */
+
+ if (!pbad_c->dying && !pplayer->dying &&
+ !timer_started(&pplayer->safe_timer) &&
+ pbad_c->mode != HELD)
+ {
+ if (pbad_c->mode == FLAT && pplayer->input.fire != DOWN)
+ {
+ /* Kick: */
+
+ pbad_c->mode = KICK;
+ play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
+
+ if (pplayer->base.x<= pbad_c->base.x)
+ {
+ pbad_c->dir = RIGHT;
+ pbad_c->base.x = pbad_c->base.x + 16;
+ }
+ else
+ {
+ pbad_c->dir = LEFT;
+ 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->base.y-=8;
+ }
+ else if (pbad_c->mode == KICK)
+ {
+ if (pplayer->base.y < pbad_c->base.y - 16 &&
+ timer_started(&pbad_c->timer))
+ {
+ /* Step on (stop being kicked) */
+
+ pbad_c->mode = FLAT;
+ play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
+ timer_start(&pbad_c->timer, 10000);
+ }
+ else
+ {
+ /* Hurt if you get hit by kicked laptop: */
+
+ if (timer_started(&pbad_c->timer))
+ {
+ if (!timer_started(&pplayer->invincible_timer))
+ {
+ player_kill(pplayer,SHRINK);
+ }
+ else
+ {
+ pbad_c->dying = FALLING;
+ pbad_c->base.ym = -8;
+ play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
+ }
+ }
+ }
+ }
+ else
+ {
+ if (!timer_started(&pplayer->invincible_timer ))
+ {
+ player_kill(pplayer,SHRINK);
+ }
+ else
+ {
+ pbad_c->dying = FALLING;
+ pbad_c->base.ym = -8;
+ play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
+ }
+ }
+ }
+ score_multiplier++;
+ break;
+ }
+
+ }
+
+ /* Kill Player! */
+
+ void player_kill(player_type* pplayer, int mode)
+ {
+ pplayer->base.ym = -5;
+
+ play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER);
+
+ if (pplayer->dir == RIGHT)
+ pplayer->base.xm = -8;
+ else if (pplayer->dir == LEFT)
+ pplayer->base.xm = 8;
+
+ if (mode == SHRINK && pplayer->size == BIG)
+ {
+ if (pplayer->got_coffee)
+ pplayer->got_coffee = NO;
+
+ pplayer->size = SMALL;
+
+ timer_start(&pplayer->safe_timer,TUX_SAFE_TIME);
+ }
+ else
+ {
+ pplayer->dying = 1;
+ }
+ }
+
+ void player_dying(player_type *pplayer)
+ {
+ pplayer->base.ym = pplayer->base.ym + GRAVITY;
+
+ /* He died :^( */
+
+ --pplayer->lives;
+ player_remove_powerups(pplayer);
+ pplayer->dying = NO;
+
+ player_level_begin(pplayer);
+
+ }
+
+ /* Remove Tux's power ups */
+ void player_remove_powerups(player_type* pplayer)
+ {
+ pplayer->got_coffee = NO;
+ pplayer->size = SMALL;
+ }
+
+ void player_keep_in_bounds(player_type* pplayer)
+ {
+ /* Keep tux in bounds: */
+ 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->base.x- 160;
+ /*pplayer->base.x+= 160;*/
+
+ if(scroll_x < 0)
+ scroll_x = 0;
+
+ }
+ 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->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->base.x> 608 + scroll_x)
+ {
+ /* ... unless there's no more to scroll! */
+
+ /*pplayer->base.x= 608 + scroll_x;*/
+ }
+
+ /* Keep in-bounds, vertically: */
+
+ if (pplayer->base.y < 0)
+ pplayer->base.y = 0;
+ else if (pplayer->base.y > screen->h)
+ {
+ player_kill(&tux,KILL);
+ }
+ }
#include "timer.h"
#include "texture.h"
#include "collision.h"
+#include "sound.h"
/* Times: */
#include "level.h"
#define FRAME_RATE 10 // 100 Frames per second (10ms)
-int score, highscore, distros, level, next_level, game_pause,
+int score, distros, level, next_level, game_pause,
done, quit, score_multiplier, endpos, counting_distros, distro_counter;
timer_type super_bkgd_timer;
float scroll_x;
SDL_Rect src, dest;
texture_type img_box_full, img_box_empty, img_mints, img_coffee, img_super_bkgd, img_red_glow;
st_level current_level;
+unsigned int last_update_time;
+unsigned int update_time;
+timer_type time_left;
+double frame_ratio;
void add_score(int x, int y, int s);
void set_defaults(void);
if(use_gl)
{
glBegin(GL_QUADS);
- glColor3ub(r/256, g/256, b/256);
+ glColor3ub(r, g, b);
glVertex2i(x, y);
glVertex2i(x+w, y);
glVertex2i(x+w, y+h);
SDL_UpdateRect(scr, x, y, w, h);
}
-void drawtext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize)
-{
- /* i - helps to keep tracking of the all string length
- j - helps to keep track of the length of the current line */
- int i, j, len;
- char c;
- SDL_Rect src, dest;
-
- len = strlen(text);
-
- /* For each letter in the string... */
-
- for (i = 0; i < len; ++i)
- {
- /* Set source rectangle: */
-
- c = text[i];
-
- if (c >= 'A' && c <= 'Z')
- {
- /* Capital letter - first row: */
-
- src.x = (c - 'A') * 16;
- src.y = 0;
- }
- else if (c >= 'a' && c <= 'z')
- {
- /* Lowercase letter - first row: */
-
- src.x = (c - 'a') * 16;
- src.y = 16;
- }
- else if (c >= '!' && c <= '9')
- {
- /* Punctuation (except '?') or number - third row: */
-
- src.x = (c - '!') * 16;
- src.y = 32;
- }
- else if (c == '?')
- {
- /* Question mark - third row, last character: */
-
- src.x = 400;
- src.y = 24;
- }
- else if (c == '\n') /* support for multi-lines */
- {
- j = i + 1;
- y += 18;
- continue;
- }
- else
- src.x = -1;
-
- src.w = 16;
- src.h = 16;
-
-
- /* Draw character: */
-
- if (src.x != -1)
- {
- /* Set destination rectangle for shadow: */
-
- dest.x = x + (i * 16) + shadowsize;
- dest.y = y + shadowsize;
- dest.w = src.w;
- dest.h = src.h;
-
-
- /* Shadow: */
-
- SDL_BlitSurface(letters_black, &src, screen, &dest);
-
-
- /* Set destination rectangle for text: */
-
- dest.x = x + (i * 16);
- dest.y = y;
- dest.w = src.w;
- dest.h = src.h;
-
-
- /* Shadow: */
-
- SDL_BlitSurface(surf, &src, screen, &dest);
-
-
-/* FIXME: Text doesn't work in OpenGL mode, below is experimental code */
-/*
-
- dest.x = 0;
- dest.y = 0;
- dest.w = src.w;
-
- dest.h = src.h;
-
- temp = SDL_CreateRGBSurface(SDL_SWSURFACE, dest.w, dest.h, 32,
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
-#else
- 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
-#endif
- SDL_BlitSurface(letters_black, &src, temp, NULL);
- texture_type xyz;
- texture_from_sdl_surface(&xyz,temp,IGNORE_ALPHA);
- texture_draw(&xyz,x + (i * 16) + shadowsize,y + shadowsize, update);
- texture_free(&xyz);
- / * Set destination rectangle for text: * /
-
- dest.x = x + (i * 16);
- dest.y = y;
- dest.w = src.w;
- dest.h = src.h;
-
- / * Text: * /
-
- SDL_BlitSurface(surf, &src, temp, NULL);
- texture_from_sdl_surface(&xyz,temp,IGNORE_ALPHA);
- SDL_FreeSurface(temp);
- texture_draw(&xyz,x + (i * 16) + shadowsize,y + shadowsize, update);
- texture_free(&xyz);*/
- }
- }
-
-
- /* Update */
-
- if (update == UPDATE)
- {
- dest.w = len * 16 + 1;
-
- if (dest.w > screen->w)
- dest.w = screen->w;
-
- update_rect(screen, x, y, dest.w, 17);
- }
-
-}
-
-
-/* --- DRAW HORIZONTALLY-CENTERED TEXT: --- */
-
-void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize)
-{
- drawtext(text, screen->w / 2 - (strlen(text) * 8), y, surf, update, shadowsize);
-}
/* --- ERASE TEXT: --- */
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/supertux/
- April 11, 2000 - April 21, 2000
+ April 11, 2000 - February 1, 2004
*/
+#ifndef SUPERTUX_SCREEN_H
+#define SUPERTUX_SCREEN_H
+
#include <SDL.h>
#ifndef NOOPENGL
#include <SDL_opengl.h>
void updatescreen(void);
void flipscreen(void);
SDL_Surface * load_image(char * file, int use_alpha);
-/*
-void drawimage(SDL_Surface * surf, float x, float y, int update);
-void drawpart(SDL_Surface * surf, float x, float y, float w, float h, int update);
-*/
-void drawtext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize);
-void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize);
void erasetext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize);
void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize);
void update_rect(SDL_Surface *scr, Sint32 x, Sint32 y, Sint32 w, Sint32 h);
+#endif /*SUPERTUX_SCREEN_H*/
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/supertux/
- April 11, 2000 - January 1st, 2004
+ April 11, 2000 - February 1st, 2004
*/
#include <stdio.h>
srand(SDL_GetTicks());
/* Load global images: */
-
- letters_black = load_image(DATA_PREFIX "/images/status/letters-black.png",
- USE_ALPHA);
-
- letters_gold = load_image(DATA_PREFIX "/images/status/letters-gold.png",
- USE_ALPHA);/*
- if (tux_x < 0)
- tux_x = 0;*/
-
- letters_blue = load_image(DATA_PREFIX "/images/status/letters-blue.png",
- USE_ALPHA);
-
- letters_red = load_image(DATA_PREFIX "/images/status/letters-red.png",
- USE_ALPHA);
-
-
+
+ text_load(&black_text,DATA_PREFIX "/images/status/letters-black.png");
+ text_load(&gold_text,DATA_PREFIX "/images/status/letters-gold.png");
+ text_load(&blue_text,DATA_PREFIX "/images/status/letters-blue.png");
+ text_load(&red_text,DATA_PREFIX "/images/status/letters-red.png");
+
/* Set icon image: */
seticon();
+ SDL_EnableUNICODE(1);
}
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
+
if (use_fullscreen == YES)
{
screen = SDL_SetVideoMode(640, 480, 32, SDL_FULLSCREEN | SDL_OPENGL ) ; /* | SDL_HWSURFACE); */
exit(1);
}
}
-
- /* Initialisierung von OpenGL * /
- glViewport(0, 0, screen->w, screen->h);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-*/
- /*
+
+ /*
* Set up OpenGL for 2D rendering.
*/
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, 0.0f);
-
+
#endif
}
if (audio_device == YES)
{
- if (open_audio(44100, AUDIO_S16, 2, 512) < 0)
+ if (open_audio(44100, AUDIO_S16, 2, 2048) < 0)
{
/* only print out message if sound or music
was not disabled at command-line
// Description:
//
//
-// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
+// Author: Tobias Glaesser <tobi.web@gmx.de> & Bill Kendrick, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
{
pbullet->base.width = 4;
pbullet->base.height = 4;
- pbullet->base.updated = SDL_GetTicks();
pbullet->base.alive = YES;
if (dir == RIGHT)
void bullet_action(bullet_type* pbullet)
{
-
- double frame_ratio = get_frame_ratio(&pbullet->base);
-
if (pbullet->base.alive)
{
pbullet->base.x = pbullet->base.x + pbullet->base.xm * frame_ratio;
pupgrade->base.xm = 2;
pupgrade->base.ym = -2;
pupgrade->base.height = 0;
- pupgrade->base.updated = SDL_GetTicks();
}
void upgrade_action(upgrade_type *pupgrade)
{
- double frame_ratio = get_frame_ratio(&pupgrade->base);
if (pupgrade->base.alive)
{
{
/* Rise up! */
- pupgrade->base.height++;
+ pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio;
+ if(pupgrade->base.height > 32)
+ pupgrade->base.height = 32;
}
else
{
}
else if (pupgrade->kind == UPGRADE_HERRING)
{
- pupgrade->base.ym = -24;
+ pupgrade->base.ym = -8;
}
pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
else if (pupgrade->kind == UPGRADE_HERRING)
{
play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
- timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
+ timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
timer_start(&super_bkgd_timer, 250);
/* play the herring song ^^ */
if (current_music != HURRYUP_MUSIC)
#include "type.h"
#include "texture.h"
#include "collision.h"
+#include "player.h"
typedef struct upgrade_type
{
//
// C Implementation: texture
//
-// Description:
+// Description:
//
//
// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
void texture_setup(void)
{
#ifdef NOOPENGL
-texture_load = texture_load_sdl;
-texture_free = texture_free_sdl;
-texture_draw = texture_draw_sdl;
-texture_draw_bg = texture_draw_bg_sdl;
-texture_draw_part = texture_draw_part_sdl;
+ texture_load = texture_load_sdl;
+ texture_load_part = texture_load_part_sdl;
+ texture_free = texture_free_sdl;
+ texture_draw = texture_draw_sdl;
+ texture_draw_bg = texture_draw_bg_sdl;
+ texture_draw_part = texture_draw_part_sdl;
#else
-if(use_gl)
-{
-texture_load = texture_load_gl;
-texture_free = texture_free_gl;
-texture_draw = texture_draw_gl;
-texture_draw_bg = texture_draw_bg_gl;
-texture_draw_part = texture_draw_part_gl;
-}
-else
-{
-texture_load = texture_load_sdl;
-texture_free = texture_free_sdl;
-texture_draw = texture_draw_sdl;
-texture_draw_bg = texture_draw_bg_sdl;
-texture_draw_part = texture_draw_part_sdl;
-}
+
+ if(use_gl)
+ {
+ texture_load = texture_load_gl;
+ texture_load_part = texture_load_part_gl;
+ texture_free = texture_free_gl;
+ texture_draw = texture_draw_gl;
+ texture_draw_bg = texture_draw_bg_gl;
+ texture_draw_part = texture_draw_part_gl;
+ }
+ else
+ {
+ texture_load = texture_load_sdl;
+ texture_load_part = texture_load_part_sdl;
+ texture_free = texture_free_sdl;
+ texture_draw = texture_draw_sdl;
+ texture_draw_bg = texture_draw_bg_sdl;
+ texture_draw_part = texture_draw_part_sdl;
+ }
#endif
}
#ifndef NOOPENGL
void texture_load_gl(texture_type* ptexture, char * file, int use_alpha)
{
-texture_load_sdl(ptexture,file,use_alpha);
-texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
+ texture_load_sdl(ptexture,file,use_alpha);
+ texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
}
-void texture_draw_gl(texture_type* ptexture, float x, float y, int update)
+void texture_load_part_gl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha)
{
- 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();
+ texture_load_part_sdl(ptexture,file,x,y,w,h,use_alpha);
+ texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
}
-void texture_draw_bg_gl(texture_type* ptexture, int update)
+void texture_draw_gl(texture_type* ptexture, float x, float y, int update)
{
- //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();
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glColor4ub(255, 255, 255,255);
+
+ 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();
+
+ glDisable(GL_BLEND);
+}
+
+void texture_draw_bg_gl(texture_type* ptexture, int update)
+{
+ 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();
}
-void texture_draw_part_gl(texture_type* ptexture, float x, float y, float w, float h, int update)
+void texture_draw_part_gl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, int update)
{
- 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();
+
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture);
+
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glColor4ub(255, 255, 255,255);
+
+ glEnable(GL_TEXTURE_RECTANGLE_NV);
+
+
+ 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();
+
+ glDisable(GL_BLEND);
+
}
void texture_create_gl(SDL_Surface * surf, GLint * tex)
{
-SDL_Surface *conv;
-conv = SDL_CreateRGBSurface(SDL_SWSURFACE , surf->w, surf->h, 32,
+ Uint32 saved_flags;
+ Uint8 saved_alpha;
+
+ SDL_Surface *conv;
+ conv = SDL_CreateRGBSurface(surf->flags, surf->w, surf->h, surf->format->BitsPerPixel,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
+ 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
#else
- 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+
+ 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
#endif
- SDL_BlitSurface(surf, 0, conv, 0);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
+
+ /* Save the alpha blending attributes */
+ saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
+ saved_alpha = surf->format->alpha;
+ if ( (saved_flags & SDL_SRCALPHA)
+ == SDL_SRCALPHA )
+ {
+ SDL_SetAlpha(surf, 0, 0);
+ }
+
+ SDL_BlitSurface(surf, 0, conv, 0);
+
+ /* Restore the alpha blending attributes */
+ if ( (saved_flags & SDL_SRCALPHA)
+ == SDL_SRCALPHA )
+ {
+ SDL_SetAlpha(surf, saved_flags, saved_alpha);
+ }
+
+
glGenTextures(1, &*tex);
- glBindTexture(GL_TEXTURE_RECTANGLE_NV , *tex);
- glEnable(GL_TEXTURE_RECTANGLE_NV);
- glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
- glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 3, conv->w, conv->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
- //glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, 0, 0, conv->w, conv->h);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
- SDL_FreeSurface(conv);
+ glBindTexture(GL_TEXTURE_RECTANGLE_NV , *tex);
+ glEnable(GL_TEXTURE_RECTANGLE_NV);
+ glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
+ glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB10_A2, conv->w, conv->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+ SDL_FreeSurface(conv);
}
void texture_free_gl(texture_type* ptexture)
}
-void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface* sdl_surf, int use_alpha)
+void texture_load_part_sdl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha)
{
- /* SDL_Surface * temp;
+ SDL_Rect src;
+ SDL_Surface * temp;
+ SDL_Surface * conv;
temp = IMG_Load(file);
if (temp == NULL)
- st_abort("Can't load", file);*/
+ st_abort("Can't load", file);
+
+ /* Set source rectangle for conv: */
+
+ src.x = x;
+ src.y = y;
+ src.w = w;
+ src.h = h;
+
+ conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel,
+ temp->format->Rmask,
+ temp->format->Gmask,
+ temp->format->Bmask,
+ temp->format->Amask);
+
+ /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
+ #else
+
+ 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+ #endif*/
+
+ SDL_SetAlpha(temp,0,0);
+
+ SDL_BlitSurface(temp, &src, conv, NULL);
+ ptexture->sdl_surface = SDL_DisplayFormatAlpha(conv);
+
+ 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);
+ SDL_FreeSurface(conv);
+
+ ptexture->w = ptexture->sdl_surface->w;
+ ptexture->h = ptexture->sdl_surface->h;
+}
+
+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);
ptexture->w = ptexture->sdl_surface->w;
ptexture->h = ptexture->sdl_surface->h;
- #ifndef NOOPENGL
+#ifndef NOOPENGL
+
if(use_gl)
{
texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture);
}
- #endif
+#endif
}
void texture_draw_sdl(texture_type* ptexture, float x, float y, int update)
{
- SDL_Rect dest;
+ SDL_Rect dest;
- dest.x = x;
- dest.y = y;
- dest.w = ptexture->w;
- dest.h = ptexture->h;
+ dest.x = x;
+ dest.y = y;
+ dest.w = ptexture->w;
+ dest.h = ptexture->h;
- SDL_BlitSurface(ptexture->sdl_surface, NULL, screen, &dest);
+ SDL_BlitSurface(ptexture->sdl_surface, NULL, screen, &dest);
- if (update == UPDATE)
- SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
+ if (update == UPDATE)
+ SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
}
void texture_draw_bg_sdl(texture_type* ptexture, int update)
{
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_sdl(texture_type* ptexture, float x, float y, float w, float h, int update)
+void texture_draw_part_sdl(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, int update)
{
- SDL_Rect src, dest;
+ SDL_Rect src, dest;
- src.x = x;
- src.y = y;
- src.w = w;
- src.h = h;
+ src.x = sx;
+ src.y = sy;
+ src.w = w;
+ src.h = h;
- dest.x = x;
- dest.y = y;
- dest.w = w;
- dest.h = h;
+ dest.x = x;
+ dest.y = y;
+ dest.w = w;
+ dest.h = h;
- SDL_BlitSurface(ptexture->sdl_surface, &src, screen, &dest);
+ SDL_BlitSurface(ptexture->sdl_surface, &src, screen, &dest);
- if (update == UPDATE)
- update_rect(screen, dest.x, dest.y, dest.w, dest.h);
+ if (update == UPDATE)
+ update_rect(screen, dest.x, dest.y, dest.w, dest.h);
}
void texture_free_sdl(texture_type* ptexture)
void texture_setup(void);
void (*texture_load) (texture_type* ptexture, char * file, int use_alpha);
+void (*texture_load_part) (texture_type* ptexture, char * file, int x, int y, int w, int h, 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);
+void (*texture_draw_part) (texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, int update);
void texture_load_sdl(texture_type* ptexture, char * file, int use_alpha);
+void texture_load_part_sdl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha);
void texture_free_sdl(texture_type* ptexture);
void texture_draw_sdl(texture_type* ptexture, float x, float y, int update);
void texture_draw_bg_sdl(texture_type* ptexture, int update);
-void texture_draw_part_sdl(texture_type* ptexture, float x, float y, float w, float h, int update);
+void texture_draw_part_sdl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, int update);
void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface * sdl_surf, int use_alpha);
#ifndef NOOPENGL
void texture_load_gl(texture_type* ptexture, char * file, int use_alpha);
+void texture_load_part_gl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha);
void texture_free_gl(texture_type* ptexture);
void texture_draw_gl(texture_type* ptexture, float x, float y, int update);
void texture_draw_bg_gl(texture_type* ptexture, int update);
-void texture_draw_part_gl(texture_type* ptexture, float x, float y, float w, float h, int update);
+void texture_draw_part_gl(texture_type* ptexture, float sx, float sy, float x, float y, float w, float h, int update);
void texture_create_gl(SDL_Surface * surf, GLint * tex);
#endif
#include "defines.h"
#include "timer.h"
+unsigned int st_get_ticks(void)
+{
+if(st_pause_count != 0)
+return SDL_GetTicks() - st_pause_ticks - SDL_GetTicks() + st_pause_count;
+else
+return SDL_GetTicks() - st_pause_ticks;
+}
+
+void st_pause_ticks_init(void)
+{
+st_pause_ticks = 0;
+st_pause_count = 0;
+}
+
+void st_pause_ticks_start(void)
+{
+st_pause_count = SDL_GetTicks();
+}
+
+void st_pause_ticks_stop(void)
+{
+st_pause_ticks += SDL_GetTicks() - st_pause_count;
+st_pause_count = 0;
+}
+
void timer_init(timer_type* ptimer)
{
ptimer->period = 0;
void timer_start(timer_type* ptimer, unsigned int period)
{
- ptimer->time = SDL_GetTicks();
+ ptimer->time = st_get_ticks();
ptimer->period = period;
}
int timer_check(timer_type* ptimer)
{
- if(ptimer->time != 0 && ptimer->time + ptimer->period > SDL_GetTicks())
+ if((ptimer->time != 0) && (ptimer->time + ptimer->period > st_get_ticks()))
return YES;
else
{
int timer_get_left(timer_type* ptimer)
{
- return (ptimer->period - (SDL_GetTicks() - ptimer->time));
+ return (ptimer->period - (st_get_ticks() - ptimer->time));
}
int timer_get_gone(timer_type* ptimer)
{
- return (SDL_GetTicks() - ptimer->time);
+ return (st_get_ticks() - ptimer->time);
}
}
timer_type;
+unsigned int st_pause_ticks;
+unsigned int st_pause_count;
+
+unsigned int st_get_ticks(void);
+void st_pause_ticks_init(void);
+void st_pause_ticks_start(void);
+void st_pause_ticks_stop(void);
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);
+
+ param : pointer to a timer which needs to be checked
+ return: NO = the timer is not started
+ or it is over
+ YES = otherwise
+======================================================================*/
int timer_check(timer_type* ptimer);
int timer_started(timer_type* ptimer);
+/*======================================================================
+ int timer_get_left(timer_type* ptimer);
+
+ param : pointer to a timer that you want to get the time left
+ return: the time left (in millisecond)
+ note : the returned value can be negative
+======================================================================*/
int timer_get_left(timer_type* ptimer);
int timer_get_gone(timer_type* ptimer);
texture_type title, anim1, anim2;
SDL_Event event;
SDLKey key;
- int done, quit, frame, pict, last_highscore;
+ int done, quit, frame, pict;
char str[80];
game_started = 0;
/* Draw the high score: */
- last_highscore = load_hs();
- sprintf(str, "High score: %d", last_highscore);
- drawcenteredtext(str, 460, letters_red, NO_UPDATE, 1);
+ load_hs();
+ sprintf(str, "High score: %d", hs_score);
+ text_drawf(&gold_text, str, 0, -40, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE);
+ sprintf(str, "by %s", hs_name);
+ text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE);
while (!done && !quit)
{
key = event.key.keysym.sym;
/* Check for menu events */
- menu_event(key);
+ menu_event(&event.key.keysym);
if (key == SDLK_ESCAPE)
{
texture_draw_bg(&title, NO_UPDATE);
/* Draw the high score: */
- sprintf(str, "High score: %d", last_highscore);
- drawcenteredtext(str, 460, letters_red, NO_UPDATE, 1);
+ sprintf(str, "High score: %d", hs_score);
+ text_drawf(&gold_text, str, 0, -40, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE);
+ sprintf(str, "by %s", hs_name);
+ text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE);
+
}
/* Don't draw menu, if quit is true */
pict = (frame / 5) % 3;
if (pict == 0)
- texture_draw_part(&title, 560, 270, 80, 75, NO_UPDATE);
+ texture_draw_part(&title, 560, 270, 560, 270, 80, 75, NO_UPDATE);
else if (pict == 1)
texture_draw(&anim1, 560, 270, NO_UPDATE);
else if (pict == 2)
texture_draw(&anim2, 560, 270, NO_UPDATE);
-
+
flipscreen();
/* Pause: */
#include "type.h"
#include "scene.h"
-double get_frame_ratio(base_type* pbase)
-{
- unsigned int cur_time = SDL_GetTicks();
- double frame_ratio = ((double)(cur_time-pbase->updated))/((double)FRAME_RATE);
- pbase->updated = cur_time;
- return (frame_ratio == 0 ? 1 : frame_ratio);
-}
+
float ym;
float width;
float height;
- int updated;
}
base_type;
-double get_frame_ratio(base_type* pbase);
+//double get_frame_ratio(base_type* pbase);
#endif /*SUPERTUX_TYPE_H*/
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 * frame_ratio;
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)
{
dest.w = 32;
dest.h = 32;
- SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format,
- current_level.bkgd_red,
- current_level.bkgd_green,
- current_level.bkgd_blue));
+ fillrect(pbouncy_brick->base.x - scroll_x,pbouncy_brick->base.y,32,32,current_level.bkgd_red,current_level.bkgd_green,
+ current_level.bkgd_blue);
drawshape(pbouncy_brick->base.x - scroll_x,
pbouncy_brick->base.y + pbouncy_brick->offset,
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 * frame_ratio;
{
char str[10];
sprintf(str, "%d", pfloating_score->value);
- drawtext(str,
- pfloating_score->base.x + 16 - strlen(str) * 8,
- pfloating_score->base.y,
- letters_gold, NO_UPDATE, 1);
+ text_draw(&gold_text, str, pfloating_score->base.x + 16 - strlen(str) * 8, pfloating_score->base.y, 1, NO_UPDATE);
}
}