#include "gameloop.h"
#include "display_manager.h"
#include "lispwriter.h"
+#include "viewport.h"
Sprite* img_mriceblock_flat_left;
Sprite* img_mriceblock_flat_right;
check_horizontal_bump();
if(mode == KICK && changed != dir)
{
+ float scroll_x = World::current()->displaymanager
+ .get_viewport().get_translation().x;
+
/* handle stereo sound (number 10 should be tweaked...)*/
if (base.x < scroll_x + screen->w/2 - 10)
play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
dying = DYING_NOT; // now the bomb hurts
timer.start(EXPLODETIME);
+ float scroll_x = World::current()->displaymanager
+ .get_viewport().get_translation().x;
+
/* play explosion sound */ // FIXME: is the stereo all right? maybe we should use player cordinates...
if (base.x < scroll_x + screen->w/2 - 10)
play_sound(sounds[SND_EXPLODE], SOUND_LEFT_SPEAKER);
void
BadGuy::action(float elapsed_time)
{
+ float scroll_x = World::current()->displaymanager
+ .get_viewport().get_translation().x;
+
// Remove if it's far off the screen:
if (base.x < scroll_x - OFFSCREEN_DISTANCE)
{
#include "tile.h"
#include "particlesystem.h"
#include "resources.h"
+#include "background.h"
#include "music_manager.h"
GameSession* GameSession::current_ = 0;
music_manager->halt_music();
char str[60];
-
- get_level()->draw_bg();
+
+ ViewPort dummy;
+ world->background->draw(dummy, LAYER_BACKGROUND0);
sprintf(str, "%s", world->get_level()->name.c_str());
gold_text->drawf(str, 0, 220, A_HMIDDLE, A_TOP, 1);
{
char str[80];
- get_level()->draw_bg();
+ ViewPort dummy;
+ world->background->draw(dummy, LAYER_BACKGROUND0);
blue_text->drawf("Result:", 0, 200, A_HMIDDLE, A_TOP, 1);
}
}
-void Level::draw_bg()
-{
- if(img_bkgd)
- {
- // Tile background horizontally
- int sx = (int)((float)scroll_x * ((float)bkgd_speed/100.0f)) % img_bkgd->w;
- int sy = (int)((float)scroll_y * ((float)bkgd_speed/100.0f)) % img_bkgd->h;
- for (int x = 0; (x-1)*img_bkgd->w <= screen->w; x++)
- for (int y = 0; (y-1)*img_bkgd->h <= screen->h; y++)
- img_bkgd->draw_part(x == 0 ? sx : 0, y == 0 ? sy : 0,
- x == 0 ? 0 : (img_bkgd->w * x) - sx, y == 0 ? 0 : (img_bkgd->h * y) - sy,
- x == 0 ? img_bkgd->w - sx : img_bkgd->w, y == 0 ? img_bkgd->h - sy : img_bkgd->h);
- }
- else
- {
- drawgradient(bkgd_top, bkgd_bottom);
- }
-}
-
void
Level::load_song()
{
/** Resize the level to a new width/height */
void resize(int new_width, int new_height);
- /* Draw background */
- void draw_bg();
-
/** Return the id of the tile at position x/y */
unsigned int gettileid(float x, float y) const;
/** returns the id of the tile at position x,y
#include "tile.h"
#include "resources.h"
#include "music_manager.h"
+#include "background.h"
#include "display_manager.h"
/* definitions to aid development */
int le_init()
{
-
-
level_subsets = dsubdirs("/levels", "level1.stl");
le_level_subset = new LevelSubset;
active_tm = TM_IA;
le_show_grid = true;
show_selections = true;
- scroll_x = 0;
done = 0;
le_frame = 0; /* support for frames in some tiles, like waves and bad guys */
Uint8 a;
/* Draw the real background */
- le_world->get_level()->draw_bg();
+ le_world->background->draw(le_world->displaymanager.get_viewport(),
+ LAYER_BACKGROUND0);
if(le_current.IsTile())
{
}
if (debug_mode)
- fillrect(base.x - scroll_x, base.y - scroll_y,
+ fillrect(base.x - viewport.get_translation().x,
+ base.y - viewport.get_translation().y,
base.width, base.height, 75,75,75, 150);
}
bool Player::is_dead()
{
+ float scroll_x =
+ World::current()->displaymanager.get_viewport().get_translation().x;
+ float scroll_y =
+ World::current()->displaymanager.get_viewport().get_translation().y;
if(base.y > screen->h + scroll_y || base.y > World::current()->get_level()->height*32 ||
base.x < scroll_x - AUTOSCROLL_DEAD_INTERVAL) // can happen in auto-scrolling
return true;
}
void
-Player::check_bounds(bool back_scrolling, bool hor_autoscroll)
+Player::check_bounds(ViewPort& viewport,
+ bool back_scrolling, bool hor_autoscroll)
{
/* Keep tux in bounds: */
if (base.x < 0)
kill(KILL);
}
- if(base.x < scroll_x && (!back_scrolling || hor_autoscroll)) // can happen if back scrolling is disabled
- base.x = scroll_x;
+ if(base.x < viewport.get_translation().x && (!back_scrolling || hor_autoscroll)) // can happen if back scrolling is disabled
+ base.x = viewport.get_translation().x;
if(hor_autoscroll)
{
- if(base.x == scroll_x)
+ if(base.x == viewport.get_translation().x)
if(issolid(base.x+32, base.y) || (size != SMALL && issolid(base.x+32, base.y+32)))
kill(KILL);
- if(base.x + base.width > scroll_x + screen->w)
- base.x = scroll_x + screen->w - base.width;
+ if(base.x + base.width > viewport.get_translation().x + screen->w)
+ base.x = viewport.get_translation().x + screen->w - base.width;
}
}
void is_dying();
bool is_dead();
void player_remove_powerups();
- void check_bounds(bool back_scrolling, bool hor_autoscroll);
+ void check_bounds(ViewPort& viewport, bool back_scrolling, bool hor_autoscroll);
bool on_ground();
bool under_solid();
void grow();
return PlayerStatus::NO_BONUS;
}
-// FIXME: Move this into a view class
-float scroll_x, scroll_y;
-
unsigned int global_frame_counter;
// EOF //
extern PlayerStatus player_status;
-extern float scroll_x, scroll_y;
extern unsigned int global_frame_counter;
#endif /*SUPERTUX_SCENE_H*/
else if(physic.get_velocity_y() < -9)
physic.set_velocity_y(-9);
+ float scroll_x =
+ World::current()->displaymanager.get_viewport().get_translation().x;
+ float scroll_y =
+ World::current()->displaymanager.get_viewport().get_translation().y;
if (base.x < scroll_x ||
base.x > scroll_x + screen->w ||
- base.y > screen->h ||
+ base.y < scroll_y ||
+ base.y > scroll_y + screen->h ||
issolid(base.x + 4, base.y + 2) ||
issolid(base.x, base.y + 2) ||
life_count <= 0)
}
/* Away from the screen? Kill it! */
- if(base.x < scroll_x - OFFSCREEN_DISTANCE) {
+ float scroll_x =
+ World::current()->displaymanager.get_viewport().get_translation().x;
+ float scroll_y =
+ World::current()->displaymanager.get_viewport().get_translation().y;
+ if(base.x < scroll_x - OFFSCREEN_DISTANCE
+ || base.y < scroll_y - OFFSCREEN_DISTANCE) {
remove_me();
return;
}
- if(base.y > screen->h) {
+ if(base.y > scroll_y + screen->h) {
remove_me();
return;
}
if(plevel->width * 32 - 320 < tux->base.x)
{
tux->level_begin();
- scroll_x = 0;
}
tux->can_jump = true;
else 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();
update_time = st_get_ticks();
}
get_level()->load_gfx();
// add background
activate_particle_systems();
- Background* bg = new Background(displaymanager);
+ background = new Background(displaymanager);
if(level->img_bkgd) {
- bg->set_image(level->img_bkgd, level->bkgd_speed);
+ background->set_image(level->img_bkgd, level->bkgd_speed);
} else {
- bg->set_gradient(level->bkgd_top, level->bkgd_bottom);
+ background->set_gradient(level->bkgd_top, level->bkgd_bottom);
}
- gameobjects.push_back(bg);
+ gameobjects.push_back(background);
// add tilemap
gameobjects.push_back(new TileMap(displaymanager, get_level()));
get_level()->load_gfx();
activate_particle_systems();
- Background* bg = new Background(displaymanager);
+ background = new Background(displaymanager);
if(level->img_bkgd) {
- bg->set_image(level->img_bkgd, level->bkgd_speed);
+ background->set_image(level->img_bkgd, level->bkgd_speed);
} else {
- bg->set_gradient(level->bkgd_top, level->bkgd_bottom);
+ background->set_gradient(level->bkgd_top, level->bkgd_bottom);
}
- gameobjects.push_back(bg);
+ gameobjects.push_back(background);
// add tilemap
gameobjects.push_back(new TileMap(displaymanager, get_level()));
get_level()->load_song();
void
World::set_defaults()
{
- // Set defaults:
- scroll_x = 0;
-
player_status.score_multiplier = 1;
counting_distros = false;
World::draw()
{
/* Draw objects */
- displaymanager.get_viewport().set_translation(Vector(scroll_x, scroll_y));
displaymanager.draw();
}
for(size_t i = 0; i < gameobjects.size(); ++i)
gameobjects[i]->action(elapsed_time);
- tux->check_bounds(level->back_scrolling, (bool)level->hor_autoscroll_speed);
+ tux->check_bounds(displaymanager.get_viewport(),
+ level->back_scrolling, (bool)level->hor_autoscroll_speed);
scrolling(elapsed_time);
/* Handle all possible collisions. */
/* This functions takes cares of the scrolling */
void World::scrolling(float elapsed_time)
{
+ float scroll_x = displaymanager.get_viewport().get_translation().x;
+ float scroll_y = displaymanager.get_viewport().get_translation().y;
+
/* Y-axis scrolling */
float tux_pos_y = tux->base.y + (tux->base.height/2);
if(level->hor_autoscroll_speed)
{
scroll_x += level->hor_autoscroll_speed * elapsed_time;
+ displaymanager.get_viewport().set_translation(Vector(scroll_x, scroll_y));
return;
}
scroll_x = level->width * 32 - screen->w;
if(scroll_x < 0)
scroll_x = 0;
+
+ displaymanager.get_viewport().set_translation(Vector(scroll_x, scroll_y));
}
void
#include "display_manager.h"
class Level;
+class Background;
/** The World class holds a level and all the game objects (badguys,
bouncy distros, etc) that are needed to run a game. */
static World* current_;
public:
+ Background* background;
BadGuys bad_guys;
std::vector<Upgrade*> upgrades;
void set_defaults();
void draw();
- void action(double frame_ratio);
- void scrolling(double frame_ratio); // camera scrolling
+ void action(float elapsed_time);
+ void scrolling(float elapsed_time); // camera scrolling
void play_music(int musictype);
int get_music_type();