SDL_Joystick * js;
/* Returns 1 for every button event, 2 for a quit event and 0 for no event. */
-int wait_for_event(SDL_Event& event,unsigned int min_delay, unsigned int max_delay, bool empty_events)
+int wait_for_event(SDL_Event& event, unsigned int min_delay,
+ unsigned int max_delay, bool empty_events)
{
int i;
Timer maxdelay;
#include <cstdio>
#include "math/physic.h"
-#include "special/timer.h"
using namespace SuperTux;
hit.normal.y = 0;
} else {
if(movement.y > -DELTA && movement.y < DELTA) {
- return false;
+ hit.time = 0;
+ hit.depth = 0;
+ hit.normal.x = 1;
+ hit.normal.y = 0;
+ return true;
}
hit.time = FLT_MAX;
}
return;
SpriteData::Action* newaction = data.get_action(name);
- if(!action) {
+ if(!newaction) {
#ifdef DEBUG
std::cerr << "Action '" << name << "' not found.\n";
#endif
bool
Sprite::check_animation()
{
- return animation_loops;
+ return animation_loops == 0;
}
void
frame += frame_inc;
- float lastframe = frame;
- frame = fmodf(frame+get_frames(), get_frames());
- if(frame != lastframe) {
- if(animation_loops > 0) {
- animation_loops--;
- if(animation_loops == 0)
- frame = 0;
- }
+ if(frame > get_frames()) {
+ frame = fmodf(frame+get_frames(), get_frames());
+
+ animation_loops--;
+ if(animation_loops == 0)
+ frame = 0;
}
}
}
-/* EOF */
Background::~Background()
{
+ printf("bgfree.\n");
delete image;
}
this->imagefile = name;
this->speed = speed;
+ printf("seti %p\n", this);
delete image;
image = new Surface(datadir + "/images/background/" + name, false);
}
Background::draw(DrawingContext& context)
{
if(type == GRADIENT) {
- /* In case we are using OpenGL just draw the gradient, else (software mode)
- use the cache. */
- if(use_gl)
- context.draw_gradient(gradient_top, gradient_bottom, layer);
- else
- {
- context.push_transform();
- context.set_translation(Vector(0, 0));
- context.draw_surface(image, Vector(0, 0), layer);
- context.pop_transform();
- }
+ context.push_transform();
+ context.set_translation(Vector(0, 0));
+ context.draw_surface(image, Vector(0, 0), layer);
+ context.pop_transform();
} else if(type == IMAGE) {
if(!image)
return;
}
void
-Camera::read(LispReader& reader)
+Camera::parse(LispReader& reader)
{
std::string modename;
virtual ~Camera();
/// parse camera mode from lisp file
- void read(LispReader& reader);
+ void parse(LispReader& reader);
/// write camera mode to a lisp file
virtual void write(LispWriter& writer);
+++ /dev/null
-// $Id$
-//
-// SuperTux
-// Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-
-#include <config.h>
-
-#include <cmath>
-#include "defines.h"
-#include "collision.h"
-#include "scene.h"
-#include "sector.h"
-#include "tilemap.h"
-#include "tile.h"
-
-#if 0
-bool rectcollision(const base_type& one, const base_type& two)
-{
- return (one.x >= two.x - one.width + 1 &&
- one.x <= two.x + two.width - 1 &&
- one.y >= two.y - one.height + 1 &&
- one.y <= two.y + two.height - 1);
-}
-
-bool rectcollision_offset(const base_type& one, const base_type& two, float off_x, float off_y)
-{
- return (one.x >= two.x - one.width + off_x + 1 &&
- one.x <= two.x + two.width + off_x - 1 &&
- one.y >= two.y - one.height + off_y + 1 &&
- one.y <= two.y + two.height + off_y - 1);
-}
-
-bool collision_object_map(const Rectangle& rect)
-{
- base_type base;
- base.x = rect.p1.x;
- base.y = rect.p1.y;
- base.width = rect.get_width();
- base.height = rect.get_height();
- return collision_object_map(base);
-}
-
-bool collision_object_map(const base_type& base)
-{
- const TileMap& tilemap = *Sector::current()->solids;
-
- // we make the collision rectangle 1 pixel smaller
- int starttilex = int(base.x+1) / 32;
- int starttiley = int(base.y+1) / 32;
- int max_x = int(base.x + base.width);
- int max_y = int(base.y + base.height);
-
- for(int x = starttilex; x*32 < max_x; ++x) {
- for(int y = starttiley; y*32 < max_y; ++y) {
- const Tile* tile = tilemap.get_tile(x, y);
- if(tile && tile->attributes & Tile::SOLID)
- return true;
- }
- }
-
- return false;
-}
-
-void* collision_func(const base_type& base, tiletestfunction function)
-{
- const TileMap& tilemap = *Sector::current()->solids;
-
- int starttilex = int(base.x) / 32;
- int starttiley = int(base.y) / 32;
- int max_x = int(base.x + base.width);
- int max_y = int(base.y + base.height);
-
- for(int x = starttilex; x*32 < max_x; ++x) {
- for(int y = starttiley; y*32 < max_y; ++y) {
- const Tile* tile = tilemap.get_tile(x, y);
- void* result = function(tile);
- if(result != 0)
- return result;
- }
- }
-
- return 0;
-}
-
-static void* test_goal_tile_function(const Tile* tile)
-{
- if(tile && (tile->attributes & Tile::GOAL))
- return const_cast<void*> ((const void*) tile); // evil cast...
- return 0;
-}
-
-const Tile* collision_goal(const Rectangle& rect)
-{
- // too lazy to rewrite for now, so we transform to base_type...
- base_type base;
- base.x = rect.p1.x;
- base.y = rect.p1.y;
- base.width = rect.get_width();
- base.height = rect.get_height();
- return (const Tile*) collision_func(base, test_goal_tile_function);
-}
-
-void collision_swept_object_map(base_type* old, base_type* current)
-{
- int steps; /* Used to speed up the collision tests, by stepping every 16pixels in the path. */
- int h;
- float lpath; /* Holds the longest path, which is either in X or Y direction. */
- float xd,yd; /* Hold the smallest steps in X and Y directions. */
- float temp, xt, yt; /* Temporary variable. */
-
- lpath = 0;
- xd = 0;
- yd = 0;
-
- if(old->x == current->x && old->y == current->y)
- {
- return;
- }
- else if(old->x == current->x && old->y != current->y)
- {
- lpath = current->y - old->y;
- if(lpath < 0)
- {
- yd = -1;
- lpath = -lpath;
- }
- else
- {
- yd = 1;
- }
-
- h = 1;
- xd = 0;
- }
- else if(old->x != current->x && old->y == current->y)
- {
- lpath = current->x - old->x;
- if(lpath < 0)
- {
- xd = -1;
- lpath = -lpath;
- }
- else
- {
- xd = 1;
- }
- h = 2;
- yd = 0;
- }
- else
- {
- lpath = current->x - old->x;
- if(lpath < 0)
- lpath = -lpath;
- if(current->y - old->y > lpath || old->y - current->y > lpath)
- lpath = current->y - old->y;
- if(lpath < 0)
- lpath = -lpath;
- h = 3;
- xd = (current->x - old->x) / lpath;
- yd = (current->y - old->y) / lpath;
- }
-
- steps = (int)(lpath / (float)16);
-
- float orig_x = old->x;
- float orig_y = old->y;
- old->x += xd;
- old->y += yd;
-
- for(float i = 0; i <= lpath; old->x += xd, old->y += yd, ++i)
- {
- if(steps > 0)
- {
- old->y += yd*16.;
- old->x += xd*16.;
- steps--;
- }
-
- if(collision_object_map(*old))
- {
- switch(h)
- {
- case 1:
- current->y = old->y - yd;
- while(collision_object_map(*current))
- current->y -= yd;
- break;
- case 2:
- current->x = old->x - xd;
- while(collision_object_map(*current))
- current->x -= xd;
- break;
- case 3:
- xt = current->x;
- yt = current->y;
- current->x = old->x - xd;
- current->y = old->y - yd;
- while(collision_object_map(*current))
- {
- current->x -= xd;
- current->y -= yd;
- }
-
- temp = current->x;
- current->x = xt;
- if(!collision_object_map(*current))
- break;
- current->x = temp;
- temp = current->y;
- current->y = yt;
-
- if(!collision_object_map(*current))
- {
- break;
- }
- else
- {
- current->y = temp;
- while(!collision_object_map(*current))
- current->y += yd;
- current->y -= yd;
- break;
- }
-
- break;
- default:
- break;
- }
- break;
- }
- }
-
- if((xd > 0 && current->x < orig_x) || (xd < 0 && current->x > orig_x))
- current->x = orig_x;
- if((yd > 0 && current->y < orig_y) || (yd < 0 && current->y > orig_y))
- current->y = orig_y;
-
- *old = *current;
-}
-
-const Tile* gettile(float x, float y)
-{
- const TileMap& tilemap = *Sector::current()->solids;
- return tilemap.get_tile_at(Vector(x, y));
-}
-
-bool issolid(float x, float y)
-{
- const Tile* tile = gettile(x,y);
- return tile && (tile->attributes & Tile::SOLID);
-}
-
-bool isbrick(float x, float y)
-{
- const Tile* tile = gettile(x,y);
- return tile && (tile->attributes & Tile::BRICK);
-}
-
-bool isice(float x, float y)
-{
- const Tile* tile = gettile(x,y);
- return tile && (tile->attributes & Tile::ICE);
-}
-
-bool isspike(float x, float y)
-{
- const Tile* tile = gettile(x,y);
- return tile && (tile->attributes & Tile::SPIKE);
-}
-
-bool isfullbox(float x, float y)
-{
- const Tile* tile = gettile(x,y);
- return tile && (tile->attributes & Tile::FULLBOX);
-}
-
-bool iscoin(float x, float y)
-{
- const Tile* tile = gettile(x,y);
- return tile && (tile->attributes & Tile::COIN);
-}
-
-#endif
-
+++ /dev/null
-// $Id$
-//
-// SuperTux
-// Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-
-#ifndef SUPERTUX_COLLISION_H
-#define SUPERTUX_COLLISION_H
-
-#include "math/rectangle.h"
-
-using namespace SuperTux;
-
-#if 0
-bool rectcollision(const base_type& one, const base_type& two);
-bool rectcollision_offset(const base_type& one, const base_type& two, float off_x, float off_y);
-
-void collision_swept_object_map(base_type* old, base_type* current);
-bool collision_object_map(const base_type& object);
-bool collision_object_map(const Rectangle& rect);
-
-/** Return a pointer to the tile at the given x/y coordinates */
-const Tile* gettile(float x, float y);
-
-// Some little helper function to check for tile properties
-bool issolid(float x, float y);
-bool isbrick(float x, float y);
-bool isice(float x, float y);
-bool isspike(float x, float y);
-bool isfullbox(float x, float y);
-
-typedef void* (*tiletestfunction)(const Tile* tile);
-/** invokes the function for each tile the baserectangle collides with. The
- * function aborts and returns true as soon as the tiletestfunction returns
- * != 0 then this value is returned. returns 0 if all tests failed.
- */
-void* collision_func(const base_type& base, tiletestfunction* function);
-const Tile* collision_goal(const Rectangle& rect);
-#endif
-
-#endif /*SUPERTUX_COLLISION_H*/
-
enum Direction { LEFT = 0, RIGHT = 1 };
-/* Direction (keyboard/joystick) states: */
-
+/* keyboard/joystick states: */
#define UP 0
#define DOWN 1
/* Dying types: */
-
-/* ---- NO 0 */
enum DyingType {
DYING_NOT = 0,
DYING_SQUISHED = 1,
};
/* Speed constraints: */
-#define MAX_WALK_XM 230
-#define MAX_RUN_XM 320
#define MAX_LIVES 99
-#define WALK_SPEED 100
-
/* gameplay related defines */
-
#define START_LIVES 4
#define MAX_FIRE_BULLETS 2
#define MAX_ICE_BULLETS 1
#define FROZEN_TIME 3.0
-#define WALK_ACCELERATION_X 300
-#define RUN_ACCELERATION_X 400
-
-#define SKID_XM 200
-#define SKID_TIME .3
-
#endif /*SUPERTUX_DEFINES_H*/
#include "player.h"
#include "level.h"
#include "scene.h"
-#include "collision.h"
#include "tile.h"
#include "particlesystem.h"
#include "resources.h"
#include "timer.h"
#include "scene.h"
#include "math/physic.h"
-#include "collision.h"
#include "special/game_object.h"
#include "special/moving_object.h"
#include "serializable.h"
void
Level::save(const std::string& filename)
{
- std::string filepath = "levels/" + filename;
- int last_slash = filepath.find_last_of('/');
- FileSystem::fcreatedir(filepath.substr(0,last_slash).c_str());
- filepath = st_dir + "/" + filepath;
- ofstream file(filepath.c_str(), ios::out);
- LispWriter* writer = new LispWriter(file);
+ std::string filepath = "levels/" + filename;
+ int last_slash = filepath.find_last_of('/');
+ FileSystem::fcreatedir(filepath.substr(0,last_slash).c_str());
+ filepath = st_dir + "/" + filepath;
+ ofstream file(filepath.c_str(), ios::out);
+ LispWriter* writer = new LispWriter(file);
- writer->write_comment("Level made using SuperTux's built-in Level Editor");
+ writer->write_comment("Level made using SuperTux's built-in Level Editor");
- writer->start_list("supertux-level");
+ writer->start_list("supertux-level");
- int version = 2;
- writer->write_int("version", version);
+ int version = 2;
+ writer->write_int("version", version);
- writer->write_string("name", name);
- writer->write_string("author", author);
- writer->write_int("time", timelimit);
- writer->write_string("end-sequence-animation",
- end_sequence_type == FIREWORKS_ENDSEQ_ANIM ? "fireworks" : "none");
+ writer->write_string("name", name);
+ writer->write_string("author", author);
+ writer->write_int("time", timelimit);
+ writer->write_string("end-sequence-animation",
+ end_sequence_type == FIREWORKS_ENDSEQ_ANIM ? "fireworks" : "none");
- for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) {
- writer->start_list("sector");
- i->second->write(*writer);
- writer->end_list("sector");
- }
+ for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) {
+ writer->start_list("sector");
+ i->second->write(*writer);
+ writer->end_list("sector");
+ }
- writer->end_list("supertux-level");
+ writer->end_list("supertux-level");
- delete writer;
- file.close();
+ delete writer;
+ file.close();
}
Level::~Level()
#include "gameloop.h"
#include "trigger/trigger_base.h"
-// behavior definitions:
-#define TILES_FOR_BUTTJUMP 3
-// animation times (in ms):
-#define SHOOTING_TIME .150
-
-// time before idle animation starts
-#define IDLE_TIME 2.500
+static const int TILES_FOR_BUTTJUMP = 3;
+static const float SHOOTING_TIME = .150;
+/// time before idle animation starts
+static const float IDLE_TIME = 2.5;
+
+static const float WALK_ACCELERATION_X = 300;
+static const float RUN_ACCELERATION_X = 400;
+static const float SKID_XM = 200;
+static const float SKID_TIME = .3;
+static const float MAX_WALK_XM = 230;
+static const float MAX_RUN_XM = 320;
+static const float WALK_SPEED = 100;
// growing animation
Surface* growingtux_left[GROWING_FRAMES];
#include "timer.h"
#include "video/surface.h"
-#include "collision.h"
#include "special/moving_object.h"
#include "special/sprite.h"
#include "math/physic.h"
song_title = "Mortimers_chipdisko.mod";
player = new Player();
add_object(player);
+
+ printf("seccreated: %p.\n", this);
}
Sector::~Sector()
{
+ printf("secdel: %p.\n", this);
for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end();
++i) {
delete *i;
background = new Background(reader);
return background;
} else if(name == "camera") {
- if(camera) {
- std::cerr << "Warning: More than 1 camera defined in sector.\n";
- return 0;
- }
- camera = new Camera(this);
- camera->read(reader);
+ Camera* camera = new Camera(this);
+ camera->parse(reader);
return camera;
} else if(name == "tilemap") {
- TileMap* tilemap = new TileMap(reader);
-
- if(tilemap->is_solid()) {
- if(solids) {
- std::cerr << "Warning multiple solid tilemaps in sector.\n";
- return 0;
- }
- solids = tilemap;
- fix_old_tiles();
- }
- return tilemap;
+ return new TileMap(reader);
} else if(name == "particles-snow") {
SnowParticleSystem* partsys = new SnowParticleSystem();
partsys->parse(reader);
std::remove(bullets.begin(), bullets.end(), bullet),
bullets.end());
}
-#if 0
- InteractiveObject* interactive_object =
- dynamic_cast<InteractiveObject*> (*i);
- if(interactive_object) {
- interactive_objects.erase(
- std::remove(interactive_objects.begin(), interactive_objects.end(),
- interactive_object), interactive_objects.end());
- }
-#endif
delete *i;
i = gameobjects.erase(i);
} else {
for(std::vector<GameObject*>::iterator i = gameobjects_new.begin();
i != gameobjects_new.end(); ++i)
{
- Bullet* bullet = dynamic_cast<Bullet*> (*i);
- if(bullet)
- bullets.push_back(bullet);
-#if 0
- InteractiveObject* interactive_object
- = dynamic_cast<InteractiveObject*> (*i);
- if(interactive_object)
- interactive_objects.push_back(interactive_object);
-#endif
+ Bullet* bullet = dynamic_cast<Bullet*> (*i);
+ if(bullet)
+ bullets.push_back(bullet);
+
+ TileMap* tilemap = dynamic_cast<TileMap*> (*i);
+ if(tilemap && tilemap->is_solid()) {
+ if(solids == 0) {
+ solids = tilemap;
+ fix_old_tiles();
+ } else {
+ std::cerr << "Another solid tilemaps added. Ignoring.";
+ }
+ }
+
+ Camera* camera = dynamic_cast<Camera*> (*i);
+ if(camera) {
+ if(this->camera != 0) {
+ std::cerr << "Warning: Multiple cameras added. Ignoring.";
+ continue;
+ }
+ this->camera = camera;
+ }
- gameobjects.push_back(*i);
+ gameobjects.push_back(*i);
}
gameobjects_new.clear();
}
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
-
#include <config.h>
#include <assert.h>
Door::action(float )
{
//Check if door animation is complete
- if (!sprite->check_animation()) {
+ if(sprite->check_animation()) {
GameSession::current()->respawn(target_sector, target_spawnpoint);
}
}
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
#ifndef SUPERTUX_WORLDMAP_H
#define SUPERTUX_WORLDMAP_H