From 168c326b585555e4ea6d444ad96a83d880d5c7e3 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sun, 11 Apr 2004 11:52:29 +0000 Subject: [PATCH] - moved gameobjects into there own file - moved drawshape to tile.h SVN-Revision: 468 --- src/Makefile.am | 2 +- src/badguy.cpp | 1 + src/collision.cpp | 3 +- src/gameloop.cpp | 37 ++-------- src/gameobjs.cpp | 158 ++++++++++++++++++++++++++++++++++++++++++ src/gameobjs.h | 74 ++++++++++++++++++++ src/level.h | 1 - src/leveleditor.cpp | 10 +-- src/resources.cpp | 2 +- src/scene.cpp | 17 ----- src/scene.h | 4 -- src/tile.cpp | 25 +++++++ src/tile.h | 5 +- src/title.cpp | 5 +- src/world.cpp | 195 +++++++++------------------------------------------- src/world.h | 68 +++--------------- 16 files changed, 323 insertions(+), 284 deletions(-) create mode 100644 src/gameobjs.cpp create mode 100644 src/gameobjs.h diff --git a/src/Makefile.am b/src/Makefile.am index bbf335a55..e0d711edf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ bin_PROGRAMS = supertux supertux_SOURCES = \ -badguy.cpp badguy.h bitmask.cpp bitmask.h button.cpp button.h collision.cpp collision.h configfile.cpp configfile.h defines.h gameloop.cpp gameloop.h globals.cpp globals.h high_scores.cpp high_scores.h intro.cpp intro.h level.cpp level.h leveleditor.cpp leveleditor.h lispreader.cpp lispreader.h menu.cpp menu.h particlesystem.cpp particlesystem.h physic.cpp physic.h player.cpp player.h scene.cpp scene.h screen.cpp screen.h setup.cpp setup.h sound.cpp sound.h special.cpp special.h supertux.cpp supertux.h text.cpp text.h texture.cpp texture.h timer.cpp timer.h title.cpp title.h type.cpp type.h world.cpp world.h worldmap.cpp worldmap.h tile.h tile.cpp mousecursor.cpp mousecursor.h resources.h resources.cpp +badguy.cpp badguy.h bitmask.cpp bitmask.h button.cpp button.h collision.cpp collision.h configfile.cpp configfile.h defines.h gameloop.cpp gameloop.h globals.cpp globals.h high_scores.cpp high_scores.h intro.cpp intro.h level.cpp level.h leveleditor.cpp leveleditor.h lispreader.cpp lispreader.h menu.cpp menu.h particlesystem.cpp particlesystem.h physic.cpp physic.h player.cpp player.h scene.cpp scene.h screen.cpp screen.h setup.cpp setup.h sound.cpp sound.h special.cpp special.h supertux.cpp supertux.h text.cpp text.h texture.cpp texture.h timer.cpp timer.h title.cpp title.h type.cpp type.h world.cpp world.h worldmap.cpp worldmap.h tile.h tile.cpp mousecursor.cpp mousecursor.h resources.h resources.cpp gameobjs.h gameobjs.cpp # EOF # noinst_HEADERS = diff --git a/src/badguy.cpp b/src/badguy.cpp index 4b2b7db73..723dd3042 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -16,6 +16,7 @@ #include "badguy.h" #include "scene.h" #include "screen.h" +#include "world.h" #include "tile.h" texture_type img_bsod_squished_left[1]; diff --git a/src/collision.cpp b/src/collision.cpp index 17164c548..de62b7a96 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -14,6 +14,7 @@ #include "collision.h" #include "bitmask.h" #include "scene.h" +#include "world.h" #include "tile.h" bool rectcollision(base_type* one, base_type* two) @@ -285,7 +286,7 @@ void collision_handler() Tile* gettile(float x, float y) { - return TileManager::instance()->get(GameSession::current()->get_level()->gettileid(x, y)); + return TileManager::instance()->get(World::current()->get_level()->gettileid(x, y)); } bool issolid(float x, float y) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 93c5aef96..e18a80bfb 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -102,7 +102,7 @@ GameSession::GameSession(const std::string& subset, int levelnb, int mode) /* Init the game: */ world->arrays_free(); - set_defaults(); + world->set_defaults(); strcpy(level_subset, subset.c_str()); @@ -397,7 +397,7 @@ GameSession::action() /* Either way, (re-)load the (next) level... */ tux.level_begin(); - set_defaults(); + world->set_defaults(); world->get_level()->cleanup(); @@ -655,31 +655,6 @@ GameSession::run() return(quit); } -/* Draw a tile on the screen: */ - -void drawshape(float x, float y, unsigned int c, Uint8 alpha) -{ - if (c != 0) - { - Tile* ptile = TileManager::instance()->get(c); - if(ptile) - { - if(ptile->images.size() > 1) - { - texture_draw(&ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))],x,y, alpha); - } - else if (ptile->images.size() == 1) - { - texture_draw(&ptile->images[0],x,y, alpha); - } - else - { - //printf("Tile not dravable %u\n", c); - } - } - } -} - /* Bounce a brick: */ void bumpbrick(float x, float y) { @@ -836,18 +811,18 @@ GameSession::loadgame(int slot) level_subset[strlen(level_subset)-1] = '\0'; fread(&level,sizeof(int),1,fi); - set_defaults(); + world->set_defaults(); world->get_level()->cleanup(); world->arrays_free(); + world->get_level()->free_gfx(); + world->get_level()->free_song(); if(world->get_level()->load(level_subset,level) != 0) exit(1); + world->activate_bad_guys(); world->activate_particle_systems(); - - world->get_level()->free_gfx(); world->get_level()->load_gfx(); - world->get_level()->free_song(); world->get_level()->load_song(); levelintro(); diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp new file mode 100644 index 000000000..f16630579 --- /dev/null +++ b/src/gameobjs.cpp @@ -0,0 +1,158 @@ +#include "world.h" +#include "tile.h" +#include "gameloop.h" +#include "gameobjs.h" + +void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y) +{ + pbouncy_distro->base.x = x; + pbouncy_distro->base.y = y; + pbouncy_distro->base.ym = -2; +} + +void bouncy_distro_action(bouncy_distro_type* pbouncy_distro) +{ + pbouncy_distro->base.y = pbouncy_distro->base.y + pbouncy_distro->base.ym * frame_ratio; + + pbouncy_distro->base.ym += 0.1 * frame_ratio; + + if (pbouncy_distro->base.ym >= 0) + world.bouncy_distros.erase(static_cast::iterator>(pbouncy_distro)); +} + +void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro) +{ + texture_draw(&img_distro[0], + pbouncy_distro->base.x - scroll_x, + pbouncy_distro->base.y); +} + +void broken_brick_init(broken_brick_type* pbroken_brick, Tile* tile, + float x, float y, float xm, float ym) +{ + pbroken_brick->tile = tile; + pbroken_brick->base.x = x; + pbroken_brick->base.y = y; + pbroken_brick->base.xm = xm; + pbroken_brick->base.ym = ym; + + timer_init(&pbroken_brick->timer, true); + timer_start(&pbroken_brick->timer,200); +} + +void broken_brick_action(broken_brick_type* pbroken_brick) +{ + pbroken_brick->base.x = pbroken_brick->base.x + pbroken_brick->base.xm * frame_ratio; + pbroken_brick->base.y = pbroken_brick->base.y + pbroken_brick->base.ym * frame_ratio; + + if (!timer_check(&pbroken_brick->timer)) + world.broken_bricks.erase(static_cast::iterator>(pbroken_brick)); +} + +void broken_brick_draw(broken_brick_type* pbroken_brick) +{ + SDL_Rect src, dest; + src.x = rand() % 16; + src.y = rand() % 16; + src.w = 16; + src.h = 16; + + dest.x = (int)(pbroken_brick->base.x - scroll_x); + dest.y = (int)pbroken_brick->base.y; + dest.w = 16; + dest.h = 16; + + if (pbroken_brick->tile->images.size() > 0) + texture_draw_part(&pbroken_brick->tile->images[0], + src.x,src.y,dest.x,dest.y,dest.w,dest.h); +} + +void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y) +{ + pbouncy_brick->base.x = x; + pbouncy_brick->base.y = y; + pbouncy_brick->offset = 0; + pbouncy_brick->offset_m = -BOUNCY_BRICK_SPEED; + pbouncy_brick->shape = GameSession::current()->get_level()->gettileid(x, y); +} + +void bouncy_brick_action(bouncy_brick_type* pbouncy_brick) +{ + + pbouncy_brick->offset = (pbouncy_brick->offset + + pbouncy_brick->offset_m * frame_ratio); + + /* Go back down? */ + + if (pbouncy_brick->offset < -BOUNCY_BRICK_MAX_OFFSET) + pbouncy_brick->offset_m = BOUNCY_BRICK_SPEED; + + + /* Stop bouncing? */ + + if (pbouncy_brick->offset >= 0) + world.bouncy_bricks.erase(static_cast::iterator>(pbouncy_brick)); +} + +void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick) +{ + int s; + SDL_Rect dest; + + if (pbouncy_brick->base.x >= scroll_x - 32 && + pbouncy_brick->base.x <= scroll_x + screen->w) + { + dest.x = (int)(pbouncy_brick->base.x - scroll_x); + dest.y = (int)pbouncy_brick->base.y; + dest.w = 32; + dest.h = 32; + + Level* plevel = GameSession::current()->get_level(); + + // FIXME: overdrawing hack to clean the tile from the screen to + // paint it later at on offseted position + if(plevel->bkgd_image[0] == '\0') + { + fillrect(pbouncy_brick->base.x - scroll_x, pbouncy_brick->base.y, + 32,32, + plevel->bkgd_red, plevel->bkgd_green, plevel->bkgd_blue, 0); + } + else + { + s = (int)scroll_x / 30; + texture_draw_part(&plevel->img_bkgd, dest.x + s, dest.y, + dest.x, dest.y,dest.w,dest.h); + } + + Tile::draw(pbouncy_brick->base.x - scroll_x, + pbouncy_brick->base.y + pbouncy_brick->offset, + pbouncy_brick->shape); + } +} + +void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s) +{ + pfloating_score->base.x = x; + pfloating_score->base.y = y - 16; + timer_init(&pfloating_score->timer,true); + timer_start(&pfloating_score->timer,1000); + pfloating_score->value = s; +} + +void floating_score_action(floating_score_type* pfloating_score) +{ + pfloating_score->base.y = pfloating_score->base.y - 2 * frame_ratio; + + if(!timer_check(&pfloating_score->timer)) + world.floating_scores.erase(static_cast::iterator>(pfloating_score)); +} + +void floating_score_draw(floating_score_type* pfloating_score) +{ + char str[10]; + sprintf(str, "%d", pfloating_score->value); + text_draw(&gold_text, str, (int)pfloating_score->base.x + 16 - strlen(str) * 8, (int)pfloating_score->base.y, 1); +} + +/* EOF */ + diff --git a/src/gameobjs.h b/src/gameobjs.h new file mode 100644 index 000000000..2e24a34bf --- /dev/null +++ b/src/gameobjs.h @@ -0,0 +1,74 @@ + +#ifndef SUPERTUX_GAMEOBJS_H +#define SUPERTUX_GAMEOBJS_H + +#include "type.h" +#include "texture.h" +#include "timer.h" +#include "scene.h" + +/* Bounciness of distros: */ +#define NO_BOUNCE 0 +#define BOUNCE 1 + +class bouncy_distro_type +{ + public: + base_type base; +}; + +extern texture_type img_distro[4]; + +void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y); +void bouncy_distro_action(bouncy_distro_type* pbouncy_distro); +void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro); +void bouncy_distro_collision(bouncy_distro_type* pbouncy_distro, int c_object); + +#define BOUNCY_BRICK_MAX_OFFSET 8 +#define BOUNCY_BRICK_SPEED 0.9 + +class Tile; + +class broken_brick_type +{ + public: + base_type base; + timer_type timer; + Tile* tile; +}; + +void broken_brick_init(broken_brick_type* pbroken_brick, Tile* tile, + float x, float y, float xm, float ym); +void broken_brick_action(broken_brick_type* pbroken_brick); +void broken_brick_draw(broken_brick_type* pbroken_brick); + +class bouncy_brick_type +{ + public: + float offset; + float offset_m; + int shape; + base_type base; +}; + +void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y); +void bouncy_brick_action(bouncy_brick_type* pbouncy_brick); +void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick); + +class floating_score_type +{ + public: + int value; + timer_type timer; + base_type base; +}; + +void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s); +void floating_score_action(floating_score_type* pfloating_score); +void floating_score_draw(floating_score_type* pfloating_score); + +#endif + +/* Local Variables: */ +/* mode:c++ */ +/* End */ diff --git a/src/level.h b/src/level.h index dfb1c1e09..5a8dd9c36 100644 --- a/src/level.h +++ b/src/level.h @@ -107,5 +107,4 @@ class Level void load_image(texture_type* ptexture, std::string theme, const char * file, int use_alpha); }; - #endif /*SUPERTUX_LEVEL_H*/ diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 6d1663261..2a4d648fa 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -24,12 +24,14 @@ #include #include "leveleditor.h" +#include "world.h" #include "screen.h" #include "defines.h" #include "globals.h" #include "setup.h" #include "menu.h" #include "level.h" +#include "gameloop.h" #include "badguy.h" #include "scene.h" #include "button.h" @@ -635,7 +637,7 @@ void le_drawinterface() /* draw button bar */ fillrect(screen->w - 64, 0, 64, screen->h, 50, 50, 50,255); - drawshape(19 * 32, 14 * 32, le_current_tile); + Tile::draw(19 * 32, 14 * 32, le_current_tile); if(TileManager::instance()->get(le_current_tile)->editor_images.size() > 0) texture_draw(&TileManager::instance()->get(le_current_tile)->editor_images[0], 19 * 32, 14 * 32); @@ -703,21 +705,21 @@ void le_drawlevel() else a = 128; - drawshape(32*x - fmodf(pos_x, 32), y * 32, le_current_level->bg_tiles[y][x + (int)(pos_x / 32)],a); + Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_current_level->bg_tiles[y][x + (int)(pos_x / 32)],a); if(active_tm == TM_IA) a = 255; else a = 128; - drawshape(32*x - fmodf(pos_x, 32), y * 32, le_current_level->ia_tiles[y][x + (int)(pos_x / 32)],a); + Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_current_level->ia_tiles[y][x + (int)(pos_x / 32)],a); if(active_tm == TM_FG) a = 255; else a = 128; - drawshape(32*x - fmodf(pos_x, 32), y * 32, le_current_level->fg_tiles[y][x + (int)(pos_x / 32)],a); + Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_current_level->fg_tiles[y][x + (int)(pos_x / 32)],a); /* draw whats inside stuff when cursor is selecting those */ /* (draw them all the time - is this the right behaviour?) */ diff --git a/src/resources.cpp b/src/resources.cpp index 829141d1b..7aee6bf83 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -2,6 +2,7 @@ #include "scene.h" #include "player.h" #include "badguy.h" +#include "gameobjs.h" #include "resources.h" texture_type img_waves[3]; @@ -251,7 +252,6 @@ void loadshared() /* Distros: */ - texture_load(&img_distro[0], datadir + "/images/shared/distro-0.png", USE_ALPHA); diff --git a/src/scene.cpp b/src/scene.cpp index c9c506a2b..4eef38ea7 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -36,22 +36,5 @@ texture_type img_red_glow; timer_type time_left; double frame_ratio; -void set_defaults(void) -{ - // Set defaults: - scroll_x = 0; - - score_multiplier = 1; - timer_init(&super_bkgd_timer, true); - - counting_distros = false; - distro_counter = 0; - - endpos = 0; - - /* set current song/music */ - set_current_music(LEVEL_MUSIC); -} - // EOF // diff --git a/src/scene.h b/src/scene.h index 6d0203a43..e877d3b4d 100644 --- a/src/scene.h +++ b/src/scene.h @@ -14,10 +14,8 @@ #define SUPERTUX_SCENE_H #include "defines.h" -#include "gameloop.h" #include "player.h" #include "badguy.h" -#include "world.h" #include "special.h" #include "level.h" #include "particlesystem.h" @@ -43,6 +41,4 @@ extern texture_type img_box_full, img_box_empty, img_mints, img_coffee, img_supe extern timer_type time_left; extern double frame_ratio; -void set_defaults(void); - #endif /*SUPERTUX_SCENE_H*/ diff --git a/src/tile.cpp b/src/tile.cpp index 3ced8ef9b..daa63f96d 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -10,6 +10,7 @@ // // #include "tile.h" +#include "scene.h" #include "assert.h" TileManager* TileManager::instance_ = 0; @@ -134,5 +135,29 @@ void TileManager::load_tileset(std::string filename) } } +void +Tile::draw(float x, float y, unsigned int c, Uint8 alpha) +{ + if (c != 0) + { + Tile* ptile = TileManager::instance()->get(c); + if(ptile) + { + if(ptile->images.size() > 1) + { + texture_draw(&ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))],x,y, alpha); + } + else if (ptile->images.size() == 1) + { + texture_draw(&ptile->images[0],x,y, alpha); + } + else + { + //printf("Tile not dravable %u\n", c); + } + } + } +} + // EOF // diff --git a/src/tile.h b/src/tile.h index 2175b2b1f..047bd7009 100644 --- a/src/tile.h +++ b/src/tile.h @@ -57,6 +57,9 @@ struct Tile int next_tile; int anim_speed; + + /** Draw a tile on the screen: */ + static void draw(float x, float y, unsigned int c, Uint8 alpha = 255); }; struct TileGroup @@ -92,6 +95,4 @@ class TileManager } }; - - #endif diff --git a/src/title.cpp b/src/title.cpp index 38812aebc..5761acd4e 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -38,6 +38,7 @@ #include "scene.h" #include "player.h" #include "math.h" +#include "tile.h" void loadshared(void); @@ -86,8 +87,8 @@ void draw_demo(Level* plevel) { for (int x = 0; x < 21; ++x) { - drawshape(32*x - fmodf(scroll_x, 32), y * 32, - plevel->ia_tiles[(int)y][(int)x + (int)(scroll_x / 32)]); + Tile::draw(32*x - fmodf(scroll_x, 32), y * 32, + plevel->ia_tiles[(int)y][(int)x + (int)(scroll_x / 32)]); } } diff --git a/src/world.cpp b/src/world.cpp index b129cd5f4..96780b9e7 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -23,10 +23,16 @@ texture_type img_distro[4]; +World* World::current_ = 0; + World world; World::World() { + // FIXME: Move this to action and draw and everywhere else where the + // world calls child functions + current_ = this; + level = new Level; } @@ -35,6 +41,24 @@ World::~World() delete level; } +void +World::set_defaults() +{ + // Set defaults: + scroll_x = 0; + + score_multiplier = 1; + timer_init(&super_bkgd_timer, true); + + 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) { @@ -127,8 +151,8 @@ World::draw() { for (x = 0; x < 21; ++x) { - drawshape(32*x - fmodf(scroll_x, 32), y * 32, - level->bg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]); + Tile::draw(32*x - fmodf(scroll_x, 32), y * 32, + level->bg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]); } } @@ -137,8 +161,8 @@ World::draw() { for (x = 0; x < 21; ++x) { - drawshape(32*x - fmodf(scroll_x, 32), y * 32, - level->ia_tiles[(int)y][(int)x + (int)(scroll_x / 32)]); + Tile::draw(32*x - fmodf(scroll_x, 32), y * 32, + level->ia_tiles[(int)y][(int)x + (int)(scroll_x / 32)]); } } @@ -171,8 +195,8 @@ World::draw() { for (x = 0; x < 21; ++x) { - drawshape(32*x - fmodf(scroll_x, 32), y * 32, - level->fg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]); + Tile::draw(32*x - fmodf(scroll_x, 32), y * 32, + level->fg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]); } } @@ -291,163 +315,10 @@ World::add_bullet(float x, float y, float xm, int dir) play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER); } - - -void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y) -{ - pbouncy_distro->base.x = x; - pbouncy_distro->base.y = y; - pbouncy_distro->base.ym = -2; -} - -void bouncy_distro_action(bouncy_distro_type* pbouncy_distro) -{ - pbouncy_distro->base.y = pbouncy_distro->base.y + pbouncy_distro->base.ym * frame_ratio; - - pbouncy_distro->base.ym += 0.1 * frame_ratio; - - if (pbouncy_distro->base.ym >= 0) - world.bouncy_distros.erase(static_cast::iterator>(pbouncy_distro)); -} - -void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro) -{ - texture_draw(&img_distro[0], - pbouncy_distro->base.x - scroll_x, - pbouncy_distro->base.y); -} - -void broken_brick_init(broken_brick_type* pbroken_brick, Tile* tile, - float x, float y, float xm, float ym) -{ - pbroken_brick->tile = tile; - pbroken_brick->base.x = x; - pbroken_brick->base.y = y; - pbroken_brick->base.xm = xm; - pbroken_brick->base.ym = ym; - - timer_init(&pbroken_brick->timer, true); - timer_start(&pbroken_brick->timer,200); -} - -void broken_brick_action(broken_brick_type* pbroken_brick) -{ - pbroken_brick->base.x = pbroken_brick->base.x + pbroken_brick->base.xm * frame_ratio; - pbroken_brick->base.y = pbroken_brick->base.y + pbroken_brick->base.ym * frame_ratio; - - if (!timer_check(&pbroken_brick->timer)) - world.broken_bricks.erase(static_cast::iterator>(pbroken_brick)); -} - -void broken_brick_draw(broken_brick_type* pbroken_brick) -{ - SDL_Rect src, dest; - src.x = rand() % 16; - src.y = rand() % 16; - src.w = 16; - src.h = 16; - - dest.x = (int)(pbroken_brick->base.x - scroll_x); - dest.y = (int)pbroken_brick->base.y; - dest.w = 16; - dest.h = 16; - - if (pbroken_brick->tile->images.size() > 0) - texture_draw_part(&pbroken_brick->tile->images[0], - src.x,src.y,dest.x,dest.y,dest.w,dest.h); -} - -void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y) -{ - pbouncy_brick->base.x = x; - pbouncy_brick->base.y = y; - pbouncy_brick->offset = 0; - pbouncy_brick->offset_m = -BOUNCY_BRICK_SPEED; - pbouncy_brick->shape = GameSession::current()->get_level()->gettileid(x, y); -} - -void bouncy_brick_action(bouncy_brick_type* pbouncy_brick) -{ - - pbouncy_brick->offset = (pbouncy_brick->offset + - pbouncy_brick->offset_m * frame_ratio); - - /* Go back down? */ - - if (pbouncy_brick->offset < -BOUNCY_BRICK_MAX_OFFSET) - pbouncy_brick->offset_m = BOUNCY_BRICK_SPEED; - - - /* Stop bouncing? */ - - if (pbouncy_brick->offset >= 0) - world.bouncy_bricks.erase(static_cast::iterator>(pbouncy_brick)); -} - -void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick) -{ - int s; - SDL_Rect dest; - - if (pbouncy_brick->base.x >= scroll_x - 32 && - pbouncy_brick->base.x <= scroll_x + screen->w) - { - dest.x = (int)(pbouncy_brick->base.x - scroll_x); - dest.y = (int)pbouncy_brick->base.y; - dest.w = 32; - dest.h = 32; - - Level* plevel = GameSession::current()->get_level(); - - // FIXME: overdrawing hack to clean the tile from the screen to - // paint it later at on offseted position - if(plevel->bkgd_image[0] == '\0') - { - fillrect(pbouncy_brick->base.x - scroll_x, pbouncy_brick->base.y, - 32,32, - plevel->bkgd_red, plevel->bkgd_green, plevel->bkgd_blue, 0); - } - else - { - s = (int)scroll_x / 30; - texture_draw_part(&plevel->img_bkgd, dest.x + s, dest.y, - dest.x, dest.y,dest.w,dest.h); - } - - drawshape(pbouncy_brick->base.x - scroll_x, - pbouncy_brick->base.y + pbouncy_brick->offset, - pbouncy_brick->shape); - } -} - -void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s) -{ - pfloating_score->base.x = x; - pfloating_score->base.y = y - 16; - timer_init(&pfloating_score->timer,true); - timer_start(&pfloating_score->timer,1000); - pfloating_score->value = s; -} - -void floating_score_action(floating_score_type* pfloating_score) -{ - pfloating_score->base.y = pfloating_score->base.y - 2 * frame_ratio; - - if(!timer_check(&pfloating_score->timer)) - world.floating_scores.erase(static_cast::iterator>(pfloating_score)); -} - -void floating_score_draw(floating_score_type* pfloating_score) -{ - char str[10]; - sprintf(str, "%d", pfloating_score->value); - text_draw(&gold_text, str, (int)pfloating_score->base.x + 16 - strlen(str) * 8, (int)pfloating_score->base.y, 1); -} - /* Break a brick: */ void trybreakbrick(float x, float y, bool small) { - Level* plevel = GameSession::current()->get_level(); + Level* plevel = World::current()->get_level(); Tile* tile = gettile(x, y); if (tile->brick) @@ -491,7 +362,7 @@ void trybreakbrick(float x, float y, bool small) /* Empty a box: */ void tryemptybox(float x, float y, int col_side) { - Level* plevel = GameSession::current()->get_level(); + Level* plevel = World::current()->get_level(); Tile* tile = gettile(x,y); if (!tile->fullbox) @@ -534,7 +405,7 @@ void tryemptybox(float x, float y, int col_side) /* Try to grab a distro: */ void trygrabdistro(float x, float y, int bounciness) { - Level* plevel = GameSession::current()->get_level(); + Level* plevel = World::current()->get_level(); Tile* tile = gettile(x, y); if (tile && tile->distro) { diff --git a/src/world.h b/src/world.h index 99ca51b3f..e0137b949 100644 --- a/src/world.h +++ b/src/world.h @@ -19,61 +19,7 @@ #include "scene.h" #include "special.h" #include "particlesystem.h" - -/* Bounciness of distros: */ - -#define NO_BOUNCE 0 -#define BOUNCE 1 - -struct bouncy_distro_type -{ - base_type base; -}; - -extern texture_type img_distro[4]; - -void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y); -void bouncy_distro_action(bouncy_distro_type* pbouncy_distro); -void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro); -void bouncy_distro_collision(bouncy_distro_type* pbouncy_distro, int c_object); - -#define BOUNCY_BRICK_MAX_OFFSET 8 -#define BOUNCY_BRICK_SPEED 0.9 - -struct broken_brick_type -{ - base_type base; - timer_type timer; - Tile* tile; -}; - -void broken_brick_init(broken_brick_type* pbroken_brick, Tile* tile, - float x, float y, float xm, float ym); -void broken_brick_action(broken_brick_type* pbroken_brick); -void broken_brick_draw(broken_brick_type* pbroken_brick); - -struct bouncy_brick_type -{ - float offset; - float offset_m; - int shape; - base_type base; -}; - -void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y); -void bouncy_brick_action(bouncy_brick_type* pbouncy_brick); -void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick); - -struct floating_score_type -{ - int value; - timer_type timer; - base_type base; -}; - -void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s); -void floating_score_action(floating_score_type* pfloating_score); -void floating_score_draw(floating_score_type* pfloating_score); +#include "gameobjs.h" /** Try to grab the coin at the given coordinates */ void trygrabdistro(float x, float y, int bounciness); @@ -97,20 +43,26 @@ class World Level* level; std::vector bouncy_distros; - std::vector broken_bricks; - std::vector bouncy_bricks; - std::vector bad_guys; + std::vector broken_bricks; + std::vector bouncy_bricks; std::vector floating_scores; + + std::vector bad_guys; std::vector upgrades; std::vector bullets; std::vector particle_systems; + static World* current_; public: + static World* current() { return current_; } + World(); ~World(); Level* get_level() { return level; } + void set_defaults(); + void draw(); void action(); void arrays_free(); -- 2.11.0