#include "level.h"
#include "tile.h"
#include "resources.h"
+#include "gameobjs.h"
Surface* img_distro[4];
get_level()->load_gfx();
activate_bad_guys();
+ activate_objects();
activate_particle_systems();
get_level()->load_song();
get_level()->load_gfx();
activate_bad_guys();
+ activate_objects();
activate_particle_systems();
get_level()->load_song();
for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
delete *i;
+ for (Trampolines::iterator i = trampolines.begin(); i != trampolines.end(); ++i)
+ delete *i;
+
for (ParticleSystems::iterator i = particle_systems.begin();
i != particle_systems.end(); ++i)
delete *i;
}
void
+World::activate_objects()
+{
+ for (std::vector< ObjectData<TrampolineData> >::iterator i = level->trampoline_data.begin();
+ i != level->trampoline_data.end();
+ ++i)
+ {
+ add_object<Trampoline, ObjectData<TrampolineData> >(*i);
+ }
+}
+
+void
World::activate_particle_systems()
{
if (level->particle_system == "clouds")
for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
(*i)->draw();
+ for (Trampolines::iterator i = trampolines.begin(); i != trampolines.end(); ++i)
+ (*i)->draw();
+
tux.draw();
for (unsigned int i = 0; i < bullets.size(); ++i)
for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
(*i)->action(frame_ratio);
+ for (Trampolines::iterator i = trampolines.begin(); i != trampolines.end(); ++i)
+ (*i)->action(frame_ratio);
+
/* update particle systems */
std::vector<ParticleSystem*>::iterator p;
for(p = particle_systems.begin(); p != particle_systems.end(); ++p)
float tux_pos_y = tux.base.y + (tux.base.height/2);
- if (scroll_y < tux_pos_y - (screen->h - Y_SPACE))
- scroll_y = tux_pos_y - (screen->h - Y_SPACE);
- else if (scroll_y > tux_pos_y - Y_SPACE)
- scroll_y = tux_pos_y - Y_SPACE;
+ if(level->height > VISIBLE_TILES_Y-1 && !tux.dying)
+ {
+ if (scroll_y < tux_pos_y - (screen->h - Y_SPACE))
+ scroll_y = tux_pos_y - (screen->h - Y_SPACE);
+ else if (scroll_y > tux_pos_y - Y_SPACE)
+ scroll_y = tux_pos_y - Y_SPACE;
+ }
// this code prevent the screen to scroll before the start or after the level's end
if(scroll_y > level->height * 32 - screen->h)
upgrades[i].collision(&tux, CO_PLAYER, COLLISION_NORMAL);
}
}
+
+ // CO_TRAMPOLINE & (CO_PLAYER or CO_BADGUY)
+ for (Trampolines::iterator i = trampolines.begin(); i != trampolines.end(); ++i)
+ {
+ if (rectcollision((*i)->base, tux.base))
+ {
+ if (tux.previous_base.y < tux.base.y &&
+ tux.previous_base.y + tux.previous_base.height
+ < (*i)->base.y + (*i)->base.height/2)
+ {
+ (*i)->collision(&tux, CO_PLAYER, COLLISION_SQUISH);
+ }
+ else if (tux.previous_base.y <= tux.base.y)
+ {
+ tux.collision(*i, CO_TRAMPOLINE);
+ (*i)->collision(&tux, CO_PLAYER, COLLISION_NORMAL);
+ }
+ }
+ }
}
void
return badguy;
}
+template<class T, class U>
+T*
+World::add_object(U data)
+{
+ T* tobject = new T(data);
+
+ if (data.type == OBJ_TRAMPOLINE)
+ trampolines.push_back(tobject);
+
+ return tobject;
+}
+
void
World::add_upgrade(float x, float y, Direction dir, UpgradeKind kind)
{
}
/* Break a brick: */
-void
+bool
World::trybreakbrick(float x, float y, bool small)
{
Level* plevel = get_level();
play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
player_status.score = player_status.score + SCORE_DISTRO;
player_status.distros++;
+ return true;
}
else if (!small)
{
/* Get some score: */
play_sound(sounds[SND_BRICK], SOUND_CENTER_SPEAKER);
player_status.score = player_status.score + SCORE_BRICK;
+
+ return true;
}
}
+
+ return false;
}
/* Empty a box: */