--- /dev/null
+(supertux-sprite
+ (action
+ (x-offset 0)
+ (y-offset 0)
+ (images "stomp.png")
+ )
+)
(images "objects/bonus_block/empty.png"))
)
- ; Stomp
- (sprite (name "stomp")
- (action
- (x-offset 0)
- (y-offset 0)
- (images "objects/particles/stomp.png")
- ))
-
(sprite (name "unstable_tile")
(action
(images "objects/unstable_tile/unstable_tile.png"))
void
GameSession::draw_pause()
{
- int x = SCREEN_HEIGHT / 20;
- for(int i = 0; i < x; ++i) {
- context->draw_filled_rect(
- Vector(i % 2 ? (pause_menu_frame * i)%SCREEN_WIDTH :
- -((pause_menu_frame * i)%SCREEN_WIDTH)
- ,(i*20+pause_menu_frame)%SCREEN_HEIGHT),
- Vector(SCREEN_WIDTH,10),
- Color(0.1, 0.1, 0.1, static_cast<float>(rand() % 20 + 1) / 255.0),
- LAYER_FOREGROUND1+1);
- }
-
context->draw_filled_rect(
Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
- Color(
- static_cast<float>(rand() % 50) / 255.0,
- static_cast<float>(rand() % 50) / 255.0,
- static_cast<float>(rand() % 50) / 255.0,
- 0.5), LAYER_FOREGROUND1);
-#if 0
- context->draw_text(blue_text, _("PAUSE - Press 'P' To Play"),
- Vector(SCREEN_WIDTH/2, 230), CENTER_ALLIGN, LAYER_FOREGROUND1+2);
-
- const char* str1 = _("Playing: ");
- const char* str2 = level->get_name().c_str();
-
- context->draw_text(blue_text, str1,
- Vector((SCREEN_WIDTH - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2, 340),
- LEFT_ALLIGN, LAYER_FOREGROUND1+2);
- context->draw_text(white_text, str2,
- Vector(((SCREEN_WIDTH - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2)+blue_text->get_text_width(str1), 340),
- LEFT_ALLIGN, LAYER_FOREGROUND1+2);
-#endif
+ Color(.2, .2, .2, .5), LAYER_FOREGROUND1);
}
void
active_item = -1;
}
-void Menu::set_pos(int x, int y, float rw, float rh)
+void Menu::set_pos(float x, float y, float rw, float rh)
{
- pos_x = x + (int)((float)get_width() * rw);
- pos_y = y + (int)((float)get_height() * rh);
+ pos_x = x + get_width() * rw;
+ pos_y = y + get_height() * rh;
}
/* Add an item to a menu */
}
Font* text_font = default_font;
- int x_pos = pos_x;
- int y_pos = pos_y + 24*index - menu_height/2 + 12 + effect_offset;
+ float x_pos = pos_x;
+ float y_pos = pos_y + 24*index - menu_height/2 + 12 + effect_offset;
int shadow_size = 2;
int text_width = int(text_font->get_text_width(pitem.text));
int input_width = int(text_font->get_text_width(pitem.input) + 10);
case MN_HL:
{
// TODO
- int x = pos_x - menu_width/2;
- int y = y_pos - 12 - effect_offset;
+ float x = pos_x - menu_width/2;
+ float y = y_pos - 12 - effect_offset;
/* Draw a horizontal line with a little 3d effect */
context.draw_filled_rect(Vector(x, y + 6),
Vector(menu_width, 4),
case MN_NUMFIELD:
case MN_CONTROLFIELD:
{
- int width = text_width + input_width + 5;
- int text_pos = SCREEN_WIDTH/2 - width/2;
- int input_pos = text_pos + text_width + 10;
+ float width = text_width + input_width + 5;
+ float text_pos = SCREEN_WIDTH/2 - width/2;
+ float input_pos = text_pos + text_width + 10;
context.draw_filled_rect(
Vector(input_pos - 5, y_pos - 10),
case SDL_MOUSEMOTION:
{
- int x = int(event.motion.x * float(SCREEN_WIDTH)/screen->w);
- int y = int(event.motion.y * float(SCREEN_HEIGHT)/screen->h);
+ float x = event.motion.x * SCREEN_WIDTH/screen->w;
+ float y = event.motion.y * SCREEN_HEIGHT/screen->h;
if(x > pos_x - get_width()/2 &&
x < pos_x + get_width()/2 &&
y > pos_y - get_height()/2 &&
y < pos_y + get_height()/2)
{
- int new_active_item = (y - (pos_y - get_height()/2)) / 24;
+ int new_active_item
+ = static_cast<int> ((y - (pos_y - get_height()/2)) / 24);
/* only change the mouse focus to a selectable item */
if ((items[new_active_item]->kind != MN_HL)
int hit_item;
// position of the menu (ie. center of the menu, not top/left)
- int pos_x;
- int pos_y;
+ float pos_x;
+ float pos_y;
/** input event for the menu (up, down, left, right, etc.) */
MenuAction menuaction;
void set_active_item(int id);
void draw(DrawingContext& context);
- void set_pos(int x, int y, float rw = 0, float rh = 0);
+ void set_pos(float x, float y, float rw = 0, float rh = 0);
void event(const SDL_Event& event);
}
}
+#ifdef DEBUG
+static Uint32 last_timelog_ticks = 0;
+static const char* last_timelog_component = 0;
+
+static inline void timelog(const char* component)
+{
+ Uint32 current_ticks = SDL_GetTicks();
+
+ if(last_timelog_component != 0) {
+ printf("Component '%s' finished after %f seconds\n",
+ last_timelog_component, (current_ticks - last_timelog_ticks) / 1000.0);
+ }
+
+ last_timelog_ticks = current_ticks;
+ last_timelog_component = component;
+}
+#else
+static inline void timelog(const char* )
+{
+}
+#endif
+
int main(int argc, char** argv)
{
try {
srand(time(0));
init_physfs(argv[0]);
init_sdl();
+ timelog("controller");
main_controller = new JoystickKeyboardController();
+ timelog("config");
init_config();
+ timelog("tinygettext");
init_tinygettext();
+ timelog("commandline");
parse_commandline(argc, argv);
+ timelog("audio");
init_audio();
+ timelog("video");
init_video();
+ timelog("menu");
setup_menu();
+ timelog("resources");
load_shared();
+ timelog(0);
if(config->start_level != "") {
// we have a normal path specified at commandline not physfs paths.
// So we simply mount that path here...
void init_video();
void wait_for_event(float min_delay, float max_delay);
-static const int SCREEN_WIDTH = 800;
-static const int SCREEN_HEIGHT = 600;
+static const float SCREEN_WIDTH = 800;
+static const float SCREEN_HEIGHT = 600;
// global variables
class JoystickKeyboardController;
#include "resources.hpp"
#include "sector.hpp"
#include "camera.hpp"
-#include "gameobjs.hpp"
+#include "particles.hpp"
#include "main.hpp"
#include "video/drawing_context.hpp"
#include "audio/sound_manager.hpp"
: position(pos)
{
timer.start(.3);
+ sprite = sprite_manager->create("images/objects/particles/stomp.sprite");
+}
+
+SmokeCloud::~SmokeCloud()
+{
+ delete sprite;
}
void
void
SmokeCloud::draw(DrawingContext& context)
{
- img_smoke_cloud->draw(context, position, LAYER_OBJECTS+1);
-}
-
-Particles::Particles(const Vector& epicenter, int min_angle, int max_angle,
- const Vector& initial_velocity, const Vector& acceleration, int number,
- Color color_, int size_, float life_time, int drawing_layer_)
- : accel(acceleration), color(color_), size(size_), drawing_layer(drawing_layer_)
-{
- if(life_time == 0) {
- live_forever = true;
- } else {
- live_forever = false;
- timer.start(life_time);
- }
-
- // create particles
- for(int p = 0; p < number; p++)
- {
- Particle* particle = new Particle;
- particle->pos = epicenter;
-
- float angle = ((rand() % (max_angle-min_angle))+min_angle)
- * (M_PI / 180); // convert to radius
- particle->vel.x = /*fabs*/(sin(angle)) * initial_velocity.x;
-// if(angle >= M_PI && angle < M_PI*2)
-// particle->vel.x *= -1; // work around to fix signal
- particle->vel.y = /*fabs*/(cos(angle)) * initial_velocity.y;
-// if(angle >= M_PI_2 && angle < 3*M_PI_2)
-// particle->vel.y *= -1;
-
- particles.push_back(particle);
- }
-}
-
-Particles::~Particles()
-{
- // free particles
- for(std::vector<Particle*>::iterator i = particles.begin();
- i < particles.end(); i++)
- delete (*i);
-}
-
-void
-Particles::update(float elapsed_time)
-{
- Vector camera = Sector::current()->camera->get_translation();
-
- // update particles
- for(std::vector<Particle*>::iterator i = particles.begin();
- i != particles.end(); ) {
- (*i)->pos.x += (*i)->vel.x * elapsed_time;
- (*i)->pos.y += (*i)->vel.y * elapsed_time;
-
- (*i)->vel.x += accel.x * elapsed_time;
- (*i)->vel.y += accel.y * elapsed_time;
-
- if((*i)->pos.x < camera.x || (*i)->pos.x > SCREEN_WIDTH + camera.x ||
- (*i)->pos.y < camera.y || (*i)->pos.y > SCREEN_HEIGHT + camera.y) {
- delete (*i);
- i = particles.erase(i);
- } else {
- ++i;
- }
- }
-
- if((timer.check() && !live_forever) || particles.size() == 0)
- remove_me();
-}
-
-void
-Particles::draw(DrawingContext& context)
-{
- // draw particles
- for(std::vector<Particle*>::iterator i = particles.begin();
- i != particles.end(); i++) {
- context.draw_filled_rect((*i)->pos, Vector(size,size), color,drawing_layer);
- }
-}
-
-void load_object_gfx()
-{
- img_smoke_cloud = sprite_manager->create("stomp");
-}
-
-void free_object_gfx()
-{
- delete img_smoke_cloud;
+ sprite->draw(context, position, LAYER_OBJECTS+1);
}
Timer timer;
};
-extern Sprite *img_smoke_cloud;
-
class SmokeCloud : public GameObject
{
public:
SmokeCloud(const Vector& pos);
+ ~SmokeCloud();
virtual void update(float elapsed_time);
virtual void draw(DrawingContext& context);
private:
+ Sprite* sprite;
Timer timer;
Vector position;
};
-class Particles : public GameObject
-{
-public:
- Particles(const Vector& epicenter, int min_angle, int max_angle,
- const Vector& initial_velocity, const Vector& acceleration,
- int number, Color color, int size, float life_time, int drawing_layer);
- ~Particles();
-
- virtual void update(float elapsed_time);
- virtual void draw(DrawingContext& context);
-
-private:
- Vector accel;
- Timer timer;
- bool live_forever;
-
- Color color;
- float size;
- int drawing_layer;
-
- struct Particle {
- Vector pos, vel;
-// float angle;
- };
- std::vector <Particle*> particles;
-};
-
-void load_object_gfx();
-void free_object_gfx();
-
#endif
/* Local Variables: */
size_t snowflakecount = size_t(virtual_width/10.0);
for(size_t i=0; i<snowflakecount; ++i) {
SnowParticle* particle = new SnowParticle;
- particle->pos.x = rand() % int(virtual_width);
- particle->pos.y = rand() % SCREEN_HEIGHT;
+ particle->pos.x = fmodf(rand(), virtual_width);
+ particle->pos.y = fmodf(rand(), SCREEN_HEIGHT);
int snowsize = rand() % 3;
particle->texture = snowimages[snowsize];
do {
size_t ghostcount = 2;
for(size_t i=0; i<ghostcount; ++i) {
GhostParticle* particle = new GhostParticle;
- particle->pos.x = rand() % int(virtual_width);
- particle->pos.y = rand() % SCREEN_HEIGHT;
+ particle->pos.x = fmodf(rand(), virtual_width);
+ particle->pos.y = fmodf(rand(), SCREEN_HEIGHT);
int size = rand() % 2;
particle->texture = ghosts[size];
do {
#include "game_session.hpp"
#include "object/tilemap.hpp"
#include "object/camera.hpp"
-#include "object/gameobjs.hpp"
+#include "object/particles.hpp"
#include "object/portable.hpp"
#include "object/bullet.hpp"
#include "trigger/trigger_base.hpp"
// dust some particles
Sector::current()->add_object(
new Particles(
- Vector(bbox.p1.x + (dir == RIGHT ? bbox.get_width() : 0),
- bbox.p2.y),
+ Vector(dir == RIGHT ? bbox.p2.x : bbox.p1.x, bbox.p2.y),
dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20,
- Vector(280,-260), Vector(0,0.030), 3, Color(100,100,100), 3, .8,
+ Vector(280, -260), Vector(0, 300), 3, Color(.4, .4, .4), 3, .8,
LAYER_OBJECTS+1));
ax *= 2.5;
ice_tux->arms = sprite_manager->create("big-tux-arms");
ice_tux->feet = sprite_manager->create("big-tux-feet");
- /* Objects */
- load_object_gfx();
-
/* Tux life: */
tux_life = new Surface("images/creatures/tux_small/tux-life.png");
delete white_small_text;
delete white_big_text;
- free_object_gfx();
-
delete tux_life;
delete small_tux;
SpriteManager::SpriteManager(const std::string& filename)
{
+#ifdef DEBUG
+ Uint32 ticks = SDL_GetTicks();
+#endif
load_resfile(filename);
+#ifdef DEBUG
+ printf("Loaded sprites in %f seconds\n", (SDL_GetTicks() - ticks) / 1000.0f);
+#endif
}
SpriteManager::~SpriteManager()
#include <sstream>
#include <iostream>
#include <assert.h>
+#include <SDL.h>
#include "video/drawing_context.hpp"
#include "lisp/lisp.hpp"
#include "lisp/parser.hpp"
TileManager::TileManager(const std::string& filename)
{
+#ifdef DEBUG
+ Uint32 ticks = SDL_GetTicks();
+#endif
load_tileset(filename);
+#ifdef DEBUG
+ printf("Tiles loaded in %f seconds\n", (SDL_GetTicks() - ticks) / 1000.0);
+#endif
}
TileManager::~TileManager()
{ }
Color(float red, float green, float blue, float alpha = 1.0)
: red(red), green(green), blue(blue), alpha(alpha)
- { }
+ {
+#ifdef DEBUG
+ check_color_ranges();
+#endif
+ }
Color(const std::vector<float>& vals)
{
red = vals[0];
alpha = vals[3];
else
alpha = 1.0;
+#ifdef DEBUG
+ check_color_ranges();
+#endif
+ }
+
+ void check_color_ranges()
+ {
+ if(red < 0 || red > 1.0 || green < 0 || green > 1.0
+ || blue < 0 || blue > 1.0
+ || alpha < 0 || alpha > 1.0)
+ printf("Warning: color value out of range: %f %f %f %f\n",
+ red, green, blue, alpha);
}
float red, green, blue, alpha;