From bf769796df5b8899eadaff544409f0ee20882530 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Sat, 17 Sep 2005 17:46:13 +0000 Subject: [PATCH] use spike flag again and don't replace spikes with objects SVN-Revision: 2765 --- src/badguy/spike.cpp | 89 --------------------------------------------------- src/badguy/spike.hpp | 44 ------------------------- src/collision_hit.hpp | 9 ++++-- src/object/player.cpp | 14 +++++++- src/sector.cpp | 27 +++++++--------- 5 files changed, 31 insertions(+), 152 deletions(-) delete mode 100644 src/badguy/spike.cpp delete mode 100644 src/badguy/spike.hpp diff --git a/src/badguy/spike.cpp b/src/badguy/spike.cpp deleted file mode 100644 index eded3f9cf..000000000 --- a/src/badguy/spike.cpp +++ /dev/null @@ -1,89 +0,0 @@ -// $Id$ -// -// SuperTux -// Copyright (C) 2005 Matthias Braun -// -// 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 - -#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") diff --git a/src/badguy/spike.hpp b/src/badguy/spike.hpp deleted file mode 100644 index bdfea108e..000000000 --- a/src/badguy/spike.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// $Id$ -// -// SuperTux -// Copyright (C) 2005 Matthias Braun -// -// 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 - diff --git a/src/collision_hit.hpp b/src/collision_hit.hpp index 42c0aa62a..e3ae28087 100644 --- a/src/collision_hit.hpp +++ b/src/collision_hit.hpp @@ -27,8 +27,6 @@ */ 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 @@ -52,5 +50,12 @@ public: Vector normal; }; +class TilemapCollisionHit : public CollisionHit +{ +public: + /// the flags of all tiles tux collided with + int tileflags; +}; + #endif diff --git a/src/object/player.cpp b/src/object/player.cpp index b42c547b9..13121b511 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -271,7 +271,7 @@ Player::handle_horizontal_input() 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), @@ -763,6 +763,18 @@ Player::collision(GameObject& other, const CollisionHit& hit) } if(other.get_flags() & FLAG_SOLID) { + TileMap* tilemap = dynamic_cast (&other); + if(tilemap) { + const TilemapCollisionHit* thit = + static_cast (&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); diff --git a/src/sector.cpp b/src/sector.cpp index 51b8683d4..cb20718a8 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -325,18 +325,6 @@ Sector::fix_old_tiles() 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); @@ -613,9 +601,10 @@ Sector::collision_tilemap(MovingObject* object, int depth) 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) { @@ -623,7 +612,7 @@ Sector::collision_tilemap(MovingObject* object, int depth) 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 @@ -640,15 +629,21 @@ Sector::collision_tilemap(MovingObject* object, int depth) 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; + } } } } -- 2.11.0