[Super-tux-commit] supertux/src badguy.cpp,1.24,1.25 collision.cpp,1.14,1.15 gameloop.cpp,1.56,1.57
Brought to you by:
wkendrick
From: Ingo R. <gr...@us...> - 2004-04-11 14:58:00
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25520 Modified Files: badguy.cpp collision.cpp gameloop.cpp gameloop.h level.cpp level.h leveleditor.cpp particlesystem.cpp physic.cpp physic.h player.cpp player.h resources.cpp scene.cpp scene.h setup.cpp title.cpp world.cpp world.h worldmap.cpp Log Message: - made some more global variables, local - replaced a few char* with string Index: scene.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/scene.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- scene.cpp 11 Apr 2004 11:52:29 -0000 1.15 +++ scene.cpp 11 Apr 2004 14:44:19 -0000 1.16 @@ -17,16 +17,16 @@ int distros; int level; int next_level; -int game_pause; int score_multiplier; -int endpos; bool counting_distros; int distro_counter; timer_type super_bkgd_timer; + +// FIXME: Move this into a view class float scroll_x; + unsigned int global_frame_counter; -Player tux; texture_type img_box_full; texture_type img_box_empty; texture_type img_mints; Index: world.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- world.h 11 Apr 2004 13:20:43 -0000 1.18 +++ world.h 11 Apr 2004 14:44:19 -0000 1.19 @@ -25,15 +25,20 @@ #include "type.h" #include "scene.h" #include "special.h" +#include "badguy.h" #include "particlesystem.h" #include "gameobjs.h" +class Level; + /** The World class holds a level and all the game objects (badguys, bouncy distros, etc) that are needed to run a game. */ class World { public: Level* level; + + Player tux; std::vector<BouncyDistro> bouncy_distros; std::vector<BrokenBrick> broken_bricks; @@ -46,13 +51,16 @@ std::vector<ParticleSystem*> particle_systems; static World* current_; + public: static World* current() { return current_; } + static void set_current(World* w) { current_ = w; } World(); ~World(); - Level* get_level() { return level; } + Level* get_level() { return level; } + Player* get_tux() { return &tux; } void set_defaults(); @@ -68,7 +76,7 @@ /** Load data for this level: Returns -1, if the loading of the level failed. */ - int load(const char* subset, int level); + int load(const std::string& subset, int level); /** Load data for this level: Returns -1, if the loading of the level failed. */ Index: physic.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/physic.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- physic.cpp 10 Apr 2004 20:16:15 -0000 1.5 +++ physic.cpp 11 Apr 2004 14:44:19 -0000 1.6 @@ -15,8 +15,8 @@ #include "defines.h" #include "physic.h" #include "timer.h" - -float gravity; +#include "world.h" +#include "level.h" Physic::Physic() : ax(0), ay(0), vx(0), vy(0), gravity_enabled(true) @@ -81,14 +81,15 @@ void Physic::apply(float &x, float &y) { - float grav; - if(gravity_enabled) - grav = gravity / 100.0; - else - grav = 0; + float gravity = World::current()->get_level()->gravity; + float grav; + if(gravity_enabled) + grav = gravity / 100.0; + else + grav = 0; - x += vx * frame_ratio + ax * frame_ratio * frame_ratio; - y += vy * frame_ratio + (ay + grav) * frame_ratio * frame_ratio; - vx += ax * frame_ratio; - vy += (ay + grav) * frame_ratio; + x += vx * frame_ratio + ax * frame_ratio * frame_ratio; + y += vy * frame_ratio + (ay + grav) * frame_ratio * frame_ratio; + vx += ax * frame_ratio; + vy += (ay + grav) * frame_ratio; } Index: particlesystem.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/particlesystem.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- particlesystem.cpp 28 Mar 2004 14:07:59 -0000 1.3 +++ particlesystem.cpp 11 Apr 2004 14:44:19 -0000 1.4 @@ -21,6 +21,8 @@ #include <iostream> #include <math.h> #include "globals.h" +#include "world.h" +#include "level.h" #include "scene.h" ParticleSystem::ParticleSystem() @@ -85,7 +87,7 @@ do { particle->speed = snowsize/60.0 + (float(rand()%10)/300.0); } while(particle->speed < 0.01); - particle->speed *= gravity; + particle->speed *= World::current()->get_level()->gravity; particles.push_back(particle); } Index: player.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.h,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- player.h 9 Apr 2004 02:19:09 -0000 1.21 +++ player.h 11 Apr 2004 14:44:19 -0000 1.22 @@ -93,10 +93,12 @@ class Player { public: - player_input_type input; player_keymap_type keymap; + int lives; int score; int distros; + + player_input_type input; bool got_coffee; int size; bool duck; @@ -105,10 +107,10 @@ bool jumping; int frame_; int frame_main; - int lives; - base_type base; - base_type old_base; - base_type previous_base; + + base_type base; + base_type old_base; + base_type previous_base; timer_type invincible_timer; timer_type skidding_timer; timer_type safe_timer; @@ -131,6 +133,7 @@ void keep_in_bounds(); bool on_ground(); bool under_solid(); + private: void handle_horizontal_input(int dir); void handle_vertical_input(); Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- worldmap.cpp 11 Apr 2004 01:51:42 -0000 1.21 +++ worldmap.cpp 11 Apr 2004 14:44:19 -0000 1.22 @@ -419,7 +419,7 @@ { std::cout << "Enter the current level: " << i->name << std::endl;; halt_music(); - GameSession session(const_cast<char*>((datadir + "levels/default/" + i->name).c_str()), + GameSession session(datadir + "levels/default/" + i->name, 1, ST_GL_LOAD_LEVEL_FILE); session.run(); play_music(song, 1); Index: scene.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/scene.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- scene.h 11 Apr 2004 11:52:29 -0000 1.18 +++ scene.h 11 Apr 2004 14:44:19 -0000 1.19 @@ -13,30 +13,23 @@ #ifndef SUPERTUX_SCENE_H #define SUPERTUX_SCENE_H -#include "defines.h" -#include "player.h" -#include "badguy.h" -#include "special.h" -#include "level.h" -#include "particlesystem.h" +#include "texture.h" +#include "timer.h" #define FRAME_RATE 10 // 100 Frames per second (10ms) -extern int score; -extern int distros; -extern int level; -extern int next_level; -extern int game_pause; -extern int score_multiplier; -extern int endpos; +extern int score; +extern int distros; +extern int level; +extern int next_level; +extern int score_multiplier; extern bool counting_distros; -extern int distro_counter; +extern int distro_counter; extern timer_type super_bkgd_timer; extern float scroll_x; extern unsigned int global_frame_counter; -extern Player tux; extern texture_type img_box_full, img_box_empty, img_mints, img_coffee, img_super_bkgd, img_red_glow; extern timer_type time_left; extern double frame_ratio; Index: badguy.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- badguy.cpp 11 Apr 2004 12:37:40 -0000 1.24 +++ badguy.cpp 11 Apr 2004 14:44:19 -0000 1.25 @@ -231,6 +231,8 @@ void BadGuy::action_laptop() { + Player& tux = *World::current()->get_tux(); + fall(); /* Move left/right: */ @@ -244,7 +246,7 @@ else if (mode == HELD) { /* FIXME: The pbad object shouldn't know about pplayer objects. */ /* If we're holding the laptop */ - dir=tux.dir; + dir = tux.dir; if(dir==RIGHT) { base.x = tux.base.x + 16; @@ -386,6 +388,8 @@ void BadGuy::action_money() { + Player& tux = *World::current()->get_tux(); + static const float JUMPV = 6; fall(); @@ -459,6 +463,8 @@ void BadGuy::action_stalactite() { + Player& tux = *World::current()->get_tux(); + static const int SHAKETIME = 800; static const int RANGE = 40; Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- level.h 11 Apr 2004 11:52:29 -0000 1.24 +++ level.h 11 Apr 2004 14:44:19 -0000 1.25 @@ -68,6 +68,7 @@ int bkgd_green; int bkgd_blue; int width; + int endpos; float gravity; std::vector<BadGuyData> badguy_data; @@ -80,7 +81,7 @@ /** Load data for this level: Returns -1, if the loading of the level failed. */ - int load(const char* subset, int level); + int load(const std::string& subset, int level); /** Load data for this level: Returns -1, if the loading of the level failed. */ Index: gameloop.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.h,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- gameloop.h 11 Apr 2004 13:05:35 -0000 1.33 +++ gameloop.h 11 Apr 2004 14:44:19 -0000 1.34 @@ -36,18 +36,32 @@ { private: bool quit; - timer_type fps_timer, frame_timer; + timer_type fps_timer; + timer_type frame_timer; World* world; + int st_gl_mode; + + float fps_fps; + unsigned int last_update_time; + unsigned int update_time; + int pause_menu_frame; + int debug_fps; + bool game_pause; + + // FIXME: Hack for restarting the level + std::string subset; public: GameSession(); GameSession(const std::string& filename); GameSession(const std::string& subset, int levelnb, int mode); - + ~GameSession(); + + /** Enter the busy loop */ int run(); + void draw(); int action(); - void process_events(); Level* get_level() { return world->get_level(); } World* get_world() { return world; } @@ -59,8 +73,15 @@ private: static GameSession* current_; - void levelintro(); + void init(); + void start_timers(); + void process_events(); + + void levelintro(); + void drawstatus(); + void drawendscreen(); + void drawresultscreen(void); }; std::string slotinfo(int slot); Index: physic.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/physic.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- physic.h 4 Apr 2004 00:32:10 -0000 1.7 +++ physic.h 11 Apr 2004 14:44:19 -0000 1.8 @@ -54,7 +54,4 @@ bool gravity_enabled; }; -/* global variables. */ -extern float gravity; - #endif /*SUPERTUX_PHYSIC_H*/ Index: setup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/setup.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- setup.cpp 10 Apr 2004 22:01:26 -0000 1.28 +++ setup.cpp 11 Apr 2004 14:44:19 -0000 1.29 @@ -397,7 +397,7 @@ options_controls_menu->additem(MN_LABEL,"Controls",0,0); options_controls_menu->additem(MN_HL,"",0,0); - options_controls_menu->additem(MN_CONTROLFIELD,"Move Right",tux.keymap.right,0); + //FIXME:options_controls_menu->additem(MN_CONTROLFIELD,"Move Right", tux.keymap.right,0); options_controls_menu->additem(MN_HL,"",0,0); options_controls_menu->additem(MN_BACK,"Back",0,0); @@ -475,7 +475,10 @@ Menu::set_current(main_menu); } else - { // Slot contains a level, so load it + { + puts("Warning: Loading games isn't supported at the moment"); +#if 0 + // Slot contains a level, so load it if (game_started) { GameSession session("default",slot - 1,ST_GL_LOAD_GAME); @@ -487,8 +490,8 @@ else { //loadgame(slot - 1); - puts("Warning: Loading games isn't supported at the moment"); } +#endif } st_pause_ticks_stop(); return true; Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.56 retrieving revision 1.57 diff -u -d -r1.56 -r1.57 --- gameloop.cpp 11 Apr 2004 13:05:35 -0000 1.56 +++ gameloop.cpp 11 Apr 2004 14:44:19 -0000 1.57 @@ -42,31 +42,15 @@ #include "collision.h" #include "tile.h" #include "particlesystem.h" - -/* extern variables */ - -int game_started = false; - -/* Local variables: */ -static SDL_Event event; -static SDLKey key; -static char level_subset[100]; -static float fps_fps; -static int st_gl_mode; -static unsigned int last_update_time; -static unsigned int update_time; -static int pause_menu_frame; -static int debug_fps; +#include "resources.h" GameSession* GameSession::current_ = 0; -/* Local function prototypes: */ -void levelintro(void); -void loadshared(void); -void unloadshared(void); -void drawstatus(void); -void drawendscreen(void); -void drawresultscreen(void); +void +GameSession::init() +{ + game_pause = false; +} GameSession::GameSession() { @@ -76,9 +60,12 @@ GameSession::GameSession(const std::string& filename) { + init(); + + //assert(!"Don't call me"); current_ = this; - world = &::global_world; + world = new World; // &::global_world; timer_init(&fps_timer, true); timer_init(&frame_timer, true); @@ -86,34 +73,33 @@ world->load(filename); } -GameSession::GameSession(const std::string& subset, int levelnb, int mode) +GameSession::GameSession(const std::string& subset_, int levelnb, int mode) + : subset(subset_) { + init(); + current_ = this; - world = &::global_world; + world = new World; // &::global_world; timer_init(&fps_timer, true); timer_init(&frame_timer, true); - game_started = true; - st_gl_mode = mode; - level = levelnb; + level = levelnb; /* Init the game: */ world->arrays_free(); world->set_defaults(); - strcpy(level_subset, subset.c_str()); - if (st_gl_mode == ST_GL_LOAD_LEVEL_FILE) { - if (world->load(level_subset)) + if (world->load(subset)) exit(1); } else { - if(world->load(level_subset, level) != 0) + if(world->load(subset, level) != 0) exit(1); } @@ -124,8 +110,6 @@ world->activate_particle_systems(); world->get_level()->load_song(); - tux.init(); - if(st_gl_mode != ST_GL_TEST) load_hs(); @@ -139,9 +123,16 @@ loadgame(levelnb); } +GameSession::~GameSession() +{ + delete world; +} + void GameSession::levelintro(void) { + Player& tux = *world->get_tux(); + char str[60]; /* Level Intro: */ clearscreen(0, 0, 0); @@ -173,6 +164,9 @@ void GameSession::process_events() { + Player& tux = *world->get_tux(); + + SDL_Event event; while (SDL_PollEvent(&event)) { /* Check for menu-events, if the menu is shown */ @@ -185,103 +179,107 @@ quit = true; break; case SDL_KEYDOWN: /* A keypress! */ - key = event.key.keysym.sym; - - if(tux.key_event(key,DOWN)) - break; - - switch(key) - { - case SDLK_ESCAPE: /* Escape: Open/Close the menu: */ - if(!game_pause) - { - if(st_gl_mode == ST_GL_TEST) - quit = true; - else if(show_menu) - { - Menu::set_current(game_menu); - show_menu = 0; - st_pause_ticks_stop(); - } - else - { - Menu::set_current(game_menu); - show_menu = 1; - st_pause_ticks_start(); - } - } - break; - default: + { + SDLKey key = event.key.keysym.sym; + + if(tux.key_event(key,DOWN)) break; - } + + switch(key) + { + case SDLK_ESCAPE: /* Escape: Open/Close the menu: */ + if(!game_pause) + { + if(st_gl_mode == ST_GL_TEST) + quit = true; + else if(show_menu) + { + Menu::set_current(game_menu); + show_menu = 0; + st_pause_ticks_stop(); + } + else + { + Menu::set_current(game_menu); + show_menu = 1; + st_pause_ticks_start(); + } + } + break; + default: + break; + } + } break; case SDL_KEYUP: /* A keyrelease! */ - key = event.key.keysym.sym; - - if(tux.key_event(key, UP)) - break; + { + SDLKey key = event.key.keysym.sym; - 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) - { - tux.size = !tux.size; - if(tux.size == BIG) - { - tux.base.height = 64; - } - else - tux.base.height = 32; - } - break; - case SDLK_END: - if(debug_mode) - distros += 50; - break; - case SDLK_SPACE: - if(debug_mode) - next_level = 1; - break; - case SDLK_DELETE: - if(debug_mode) - tux.got_coffee = 1; - break; - case SDLK_INSERT: - if(debug_mode) - timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME); - break; - case SDLK_l: - if(debug_mode) - --tux.lives; - break; - case SDLK_s: - if(debug_mode) - score += 1000; - case SDLK_f: - if(debug_fps) - debug_fps = false; - else - debug_fps = true; - break; - default: + if(tux.key_event(key, UP)) break; - } + + switch(key) + { + case SDLK_p: + if(!show_menu) + { + if(game_pause) + { + game_pause = false; + st_pause_ticks_stop(); + } + else + { + game_pause = true; + st_pause_ticks_start(); + } + } + break; + case SDLK_TAB: + if(debug_mode) + { + tux.size = !tux.size; + if(tux.size == BIG) + { + tux.base.height = 64; + } + else + tux.base.height = 32; + } + break; + case SDLK_END: + if(debug_mode) + distros += 50; + break; + case SDLK_SPACE: + if(debug_mode) + next_level = 1; + break; + case SDLK_DELETE: + if(debug_mode) + tux.got_coffee = 1; + break; + case SDLK_INSERT: + if(debug_mode) + timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME); + break; + case SDLK_l: + if(debug_mode) + --tux.lives; + break; + case SDLK_s: + if(debug_mode) + score += 1000; + case SDLK_f: + if(debug_fps) + debug_fps = false; + else + debug_fps = true; + break; + default: + break; + } + } break; case SDL_JOYAXISMOTION: @@ -342,6 +340,8 @@ int GameSession::action() { + Player& tux = *world->get_tux(); + if (tux.is_dead() || next_level) { /* Tux either died, or reached the end of a level! */ @@ -403,12 +403,12 @@ if (st_gl_mode == ST_GL_LOAD_LEVEL_FILE) { - if(world->get_level()->load(level_subset) != 0) + if(world->get_level()->load(subset) != 0) return 0; } else { - if(world->get_level()->load(level_subset,level) != 0) + if(world->get_level()->load(subset, level) != 0) return 0; } @@ -465,13 +465,14 @@ int GameSession::run() { + Player& tux = *world->get_tux(); current_ = this; int fps_cnt; bool done; global_frame_counter = 0; - game_pause = 0; + game_pause = false; timer_init(&fps_timer,true); timer_init(&frame_timer,true); last_update_time = st_get_ticks(); @@ -484,8 +485,9 @@ /* Play music: */ play_current_music(); - while (SDL_PollEvent(&event)) - {} + // Eat unneeded events + SDL_Event event; + while (SDL_PollEvent(&event)) {} draw(); @@ -505,7 +507,6 @@ } /* Handle events: */ - tux.input.old_fire = tux.input.fire; process_events(); @@ -640,9 +641,7 @@ unloadshared(); world->arrays_free(); - game_started = false; - - return(quit); + return quit; } /* Bounce a brick: */ @@ -655,8 +654,10 @@ } /* (Status): */ -void drawstatus(void) +void +GameSession::drawstatus() { + Player& tux = *world->get_tux(); char str[60]; sprintf(str, "%d", score); @@ -694,14 +695,14 @@ text_draw(&gold_text, str, screen->h + 60, 40, 1); } - for(int i=0; i < tux.lives; ++i) + for(int i= 0; i < tux.lives; ++i) { texture_draw(&tux_life,565+(18*i),20); } } - -void drawendscreen(void) +void +GameSession::drawendscreen() { char str[80]; @@ -721,7 +722,8 @@ wait_for_event(event,2000,5000,true); } -void drawresultscreen(void) +void +GameSession::drawresultscreen(void) { char str[80]; @@ -742,8 +744,9 @@ } void -GameSession::savegame(int slot) +GameSession::savegame(int) { +#if 0 char savefile[1024]; FILE* fi; unsigned int ui; @@ -764,22 +767,23 @@ fwrite(&score,sizeof(int),1,fi); fwrite(&distros,sizeof(int),1,fi); fwrite(&scroll_x,sizeof(float),1,fi); - fwrite(&tux,sizeof(Player),1,fi); - timer_fwrite(&tux.invincible_timer,fi); - timer_fwrite(&tux.skidding_timer,fi); - timer_fwrite(&tux.safe_timer,fi); - timer_fwrite(&tux.frame_timer,fi); + //FIXME:fwrite(&tux,sizeof(Player),1,fi); + //FIXME:timer_fwrite(&tux.invincible_timer,fi); + //FIXME:timer_fwrite(&tux.skidding_timer,fi); + //FIXME:timer_fwrite(&tux.safe_timer,fi); + //FIXME:timer_fwrite(&tux.frame_timer,fi); timer_fwrite(&time_left,fi); ui = st_get_ticks(); fwrite(&ui,sizeof(int),1,fi); } fclose(fi); - +#endif } void -GameSession::loadgame(int slot) +GameSession::loadgame(int) { +#if 0 char savefile[1024]; char str[100]; FILE* fi; @@ -821,16 +825,16 @@ fread(&score, sizeof(int),1,fi); fread(&distros, sizeof(int),1,fi); fread(&scroll_x,sizeof(float),1,fi); - fread(&tux, sizeof(Player), 1, fi); - timer_fread(&tux.invincible_timer,fi); - timer_fread(&tux.skidding_timer,fi); - timer_fread(&tux.safe_timer,fi); - timer_fread(&tux.frame_timer,fi); + //FIXME:fread(&tux, sizeof(Player), 1, fi); + //FIXME:timer_fread(&tux.invincible_timer,fi); + //FIXME:timer_fread(&tux.skidding_timer,fi); + //FIXME:timer_fread(&tux.safe_timer,fi); + //FIXME:timer_fread(&tux.frame_timer,fi); timer_fread(&time_left,fi); fread(&ui,sizeof(int),1,fi); fclose(fi); } - +#endif } std::string slotinfo(int slot) Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- leveleditor.cpp 11 Apr 2004 13:05:35 -0000 1.36 +++ leveleditor.cpp 11 Apr 2004 14:44:19 -0000 1.37 @@ -36,6 +36,7 @@ #include "scene.h" #include "button.h" #include "tile.h" +#include "resources.h" /* definitions to aid development */ #define DONE_LEVELEDITOR 1 @@ -59,11 +60,6 @@ #define SELECT_W 2 // size of the selections lines #define SELECT_CLR 0, 255, 0, 255 // lines color (R, G, B, A) -/* gameloop funcs declerations */ - -void loadshared(void); -void unloadshared(void); - /* own declerations */ /* crutial ones (main loop) */ int le_init(); Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- player.cpp 11 Apr 2004 12:37:40 -0000 1.25 +++ player.cpp 11 Apr 2004 14:44:19 -0000 1.26 @@ -99,6 +99,7 @@ timer_init(&skidding_timer,true); timer_init(&safe_timer,true); timer_init(&frame_timer,true); + physic.reset(); } @@ -285,8 +286,8 @@ // timer_check(&skidding_timer); // disabled /* End of level? */ - - if (base.x >= endpos && endpos != 0) + if (base.x >= World::current()->get_level()->endpos + && World::current()->get_level()->endpos != 0) { next_level = 1; } @@ -914,7 +915,7 @@ void Player::keep_in_bounds() { - Level* plevel = GameSession::current()->get_level(); + Level* plevel = World::current()->get_level(); /* Keep tux in bounds: */ if (base.x< 0) @@ -931,7 +932,7 @@ } else if (base.x > screen->w / 2 + scroll_x - && scroll_x < ((GameSession::current()->get_level()->width * 32) - screen->w)) + && scroll_x < ((World::current()->get_level()->width * 32) - screen->w)) { // FIXME: Scrolling needs to be handled by a seperate View // class, doing it as a player huck is ugly Index: collision.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/collision.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- collision.cpp 11 Apr 2004 12:59:59 -0000 1.14 +++ collision.cpp 11 Apr 2004 14:44:19 -0000 1.15 @@ -15,6 +15,7 @@ #include "bitmask.h" #include "scene.h" #include "world.h" +#include "level.h" #include "tile.h" bool rectcollision(base_type* one, base_type* two) Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- title.cpp 11 Apr 2004 11:52:29 -0000 1.29 +++ title.cpp 11 Apr 2004 14:44:19 -0000 1.30 @@ -39,15 +39,13 @@ #include "player.h" #include "math.h" #include "tile.h" - -void loadshared(void); +#include "resources.h" static texture_type bkg_title; static texture_type logo; static texture_type img_choose_subset; static bool walking; -static Player titletux; static timer_type random_timer; static SDL_Event event; @@ -65,8 +63,13 @@ texture_draw_bg(&bkg_title); } -void draw_demo(Level* plevel) +void draw_demo(GameSession* session) { + World::set_current(session->get_world()); + //World* world = session->get_world(); + Level* plevel = session->get_level(); + Player* tux = session->get_world()->get_tux(); + /* FIXME: // update particle systems std::vector<ParticleSystem*>::iterator p; @@ -93,14 +96,14 @@ } global_frame_counter++; - titletux.key_event(SDLK_RIGHT,DOWN); + tux->key_event(SDLK_RIGHT,DOWN); if(timer_check(&random_timer)) { if(walking) - titletux.key_event(SDLK_UP,UP); + tux->key_event(SDLK_UP,UP); else - titletux.key_event(SDLK_UP,DOWN); + tux->key_event(SDLK_UP,DOWN); } else { @@ -109,27 +112,26 @@ } // Wrap around at the end of the level back to the beginnig - if(plevel->width * 32 - 320 < titletux.base.x) + if(plevel->width * 32 - 320 < tux->base.x) { - titletux.base.x = titletux.base.x - (plevel->width * 32 - 640); - scroll_x = titletux.base.x - 320; + tux->base.x = tux->base.x - (plevel->width * 32 - 640); + scroll_x = tux->base.x - 320; } - float last_tux_x_pos = titletux.base.x; - titletux.action(); + float last_tux_x_pos = tux->base.x; + tux->action(); // Jump if tux stays in the same position for one loop, ie. if he is // stuck behind a wall - if (last_tux_x_pos == titletux.base.x) + if (last_tux_x_pos == tux->base.x) walking = false; - titletux.draw(); + tux->draw(); /* DEMO end */ } /* --- TITLE SCREEN --- */ - bool title(void) { string_list_type level_subsets; @@ -138,15 +140,13 @@ timer_init(&random_timer, true); walking = true; - titletux.init(); st_pause_ticks_init(); GameSession session(datadir + "/levels/misc/menu.stl"); loadshared(); + //FIXME:activate_particle_systems(); - /* Lower the gravity that tux doesn't jump to hectically through the demo */ - //gravity = 5; /* Reset menu variables */ menu_reset(); @@ -209,7 +209,7 @@ /* Draw the background: */ draw_background(); - draw_demo(session.get_level()); + draw_demo(&session); if (current_menu == main_menu) texture_draw(&logo, 160, 30); @@ -344,9 +344,10 @@ { if (process_load_game_menu()) { + // FIXME: shouldn't be needed if GameSession doesn't relay on global variables // reset tux scroll_x = 0; - titletux.level_begin(); + //titletux.level_begin(); update_time = st_get_ticks(); } } Index: world.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- world.cpp 11 Apr 2004 13:20:43 -0000 1.16 +++ world.cpp 11 Apr 2004 14:44:19 -0000 1.17 @@ -41,6 +41,7 @@ current_ = this; level = new Level; + tux.init(); } World::~World() @@ -60,14 +61,12 @@ counting_distros = false; distro_counter = 0; - endpos = 0; - /* set current song/music */ set_current_music(LEVEL_MUSIC); } int -World::load(const char* subset, int level_nr) +World::load(const std::string& subset, int level_nr) { return level->load(subset, level_nr); } Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- level.cpp 11 Apr 2004 01:24:58 -0000 1.29 +++ level.cpp 11 Apr 2004 14:44:19 -0000 1.30 @@ -203,6 +203,7 @@ bkgd_red = 0; bkgd_green = 0; bkgd_blue = 0; + endpos = 0; for(int i = 0; i < 15; ++i) { @@ -227,14 +228,14 @@ } int -Level::load(const char *subset, int level) +Level::load(const std::string& subset, int level) { char filename[1024]; // Load data file: - snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset, level); + snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset.c_str(), level); if(!faccessible(filename)) - snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), subset, level); + snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), subset.c_str(), level); return load(filename); } @@ -423,9 +424,6 @@ } } - // FIXME: Set the global gravity to the latest loaded level's gravity - ::gravity = gravity; - // Mark the end position of this level! // FIXME: -10 is a rather random value, we still need some kind of // real levelend gola Index: resources.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/resources.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- resources.cpp 11 Apr 2004 12:37:40 -0000 1.3 +++ resources.cpp 11 Apr 2004 14:44:19 -0000 1.4 @@ -3,6 +3,7 @@ #include "player.h" #include "badguy.h" #include "gameobjs.h" +#include "special.h" #include "resources.h" texture_type img_waves[3]; |