+++ /dev/null
-// $Id$
-//
-// SuperTux
-// Copyright (C) 2005 Matthias Braun <matze@braunis.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 "spike.hpp"
-
-Spike::Spike(const Vector& pos, Direction dir)
-{
- sprite = sprite_manager->create("spike");
- start_position = pos;
- bbox.set_pos(Vector(0, 0));
- bbox.set_size(32, 32);
- set_direction(dir);
- countMe = false;
-}
-
-Spike::Spike(const lisp::Lisp& reader)
-{
- sprite = sprite_manager->create("spike");
- reader.get("x", start_position.x);
- reader.get("y", start_position.y);
- bbox.set_size(32, 32);
- int idir = 0;
- reader.get("direction", idir);
- set_direction((Direction) idir);
- countMe = false;
-}
-
-void
-Spike::set_direction(Direction dir)
-{
- spikedir = dir;
- switch(spikedir) {
- case NORTH:
- sprite->set_action("north");
- break;
- case SOUTH:
- sprite->set_action("south");
- break;
- case WEST:
- sprite->set_action("west");
- break;
- case EAST:
- sprite->set_action("east");
- break;
- default:
- break;
- }
-}
-
-void
-Spike::write(lisp::Writer& writer)
-{
- writer.start_list("spike");
- writer.write_float("x", start_position.x);
- writer.write_float("y", start_position.y);
- writer.write_int("direction", spikedir);
- writer.end_list("spike");
-}
-
-void
-Spike::kill_fall()
-{
- // you can't kill a spike
-}
-
-void
-Spike::active_update(float )
-{
-}
-
-IMPLEMENT_FACTORY(Spike, "spike")
+++ /dev/null
-// $Id$
-//
-// SuperTux
-// Copyright (C) 2005 Matthias Braun <matze@braunis.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 __SPIKE_H__
-#define __SPIKE_H__
-
-#include "badguy.hpp"
-
-class Spike : public BadGuy
-{
-public:
- enum Direction {
- NORTH=0, SOUTH, WEST, EAST
- };
- Spike(const Vector& pos, Direction dir);
- Spike(const lisp::Lisp& reader);
-
- void active_update(float elapsed_time);
- void write(lisp::Writer& writer);
- void kill_fall();
-private:
- void set_direction(Direction dir);
- Direction spikedir;
-};
-
-#endif
-
*/
enum HitResponse
{
- // note: keep the elements in this order
-
/// don't move the object
ABORT_MOVE = 0,
/// move object out of collision and check for collisions again
Vector normal;
};
+class TilemapCollisionHit : public CollisionHit
+{
+public:
+ /// the flags of all tiles tux collided with
+ int tileflags;
+};
+
#endif
if(fabs(vx)>SKID_XM && !skidding_timer.started()) {
skidding_timer.start(SKID_TIME);
sound_manager->play("sounds/skid.wav");
- // dust some partcles
+ // dust some particles
Sector::current()->add_object(
new Particles(
Vector(bbox.p1.x + (dir == RIGHT ? bbox.get_width() : 0),
}
if(other.get_flags() & FLAG_SOLID) {
+ TileMap* tilemap = dynamic_cast<TileMap*> (&other);
+ if(tilemap) {
+ const TilemapCollisionHit* thit =
+ static_cast<const TilemapCollisionHit*> (&hit);
+ printf("Tileattrs. %d\n", thit->tileflags);
+ if(thit->tileflags & Tile::SPIKE)
+ kill(SHRINK);
+
+ if(! (thit->tileflags & Tile::SOLID))
+ return CONTINUE;
+ }
+
if(hit.normal.y < 0) { // landed on floor?
if (physic.get_velocity_y() < 0)
physic.set_velocity_y(0);
if(tile->getID() == 112) {
add_object(new InvisibleBlock(pos));
solids->change(x, y, 0);
- } else if(tile->getID() == 295) {
- add_object(new Spike(pos, Spike::NORTH));
- solids->change(x, y, 0);
- } else if(tile->getID() == 296) {
- add_object(new Spike(pos, Spike::EAST));
- solids->change(x, y, 0);
- } else if(tile->getID() == 297) {
- add_object(new Spike(pos, Spike::SOUTH));
- solids->change(x, y, 0);
- } else if(tile->getID() == 298) {
- add_object(new Spike(pos, Spike::WEST));
- solids->change(x, y, 0);
} else if(tile->getAttributes() & Tile::COIN) {
add_object(new Coin(pos));
solids->change(x, y, 0);
int max_x = int(x2+1);
int max_y = int(y2+1);
- CollisionHit temphit, hit;
+ TilemapCollisionHit temphit, hit;
Rect dest = object->get_bbox();
dest.move(object->movement);
+ hit.tileflags = 0;
hit.time = -1; // represents an invalid value
for(int x = starttilex; x*32 < max_x; ++x) {
for(int y = starttiley; y*32 < max_y; ++y) {
if(!tile)
continue;
// skip non-solid tiles
- if(!(tile->getAttributes() & Tile::SOLID))
+ if(tile->getAttributes() == 0)
continue;
// only handle unisolid when the player is falling down and when he was
// above the tile before
if(Collision::rectangle_aatriangle(temphit, dest, object->movement,
triangle)) {
- if(temphit.time > hit.time)
+ hit.tileflags |= tile->getAttributes();
+ if(temphit.time > hit.time) {
+ temphit.tileflags = hit.tileflags;
hit = temphit;
+ }
}
} else { // normal rectangular tile
Rect rect(x*32, y*32, (x+1)*32, (y+1)*32);
if(Collision::rectangle_rectangle(temphit, dest,
object->movement, rect)) {
- if(temphit.time > hit.time)
+ hit.tileflags |= tile->getAttributes();
+ if(temphit.time > hit.time) {
+ temphit.tileflags = hit.tileflags;
hit = temphit;
+ }
}
}
}