[Super-tux-commit] supertux/src/trigger door.cpp,NONE,1.1 door.h,NONE,1.1 sequence_trigger.cpp,NONE,
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-11-20 22:14:51
|
Update of /cvsroot/super-tux/supertux/src/trigger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5941/src/trigger Added Files: door.cpp door.h sequence_trigger.cpp sequence_trigger.h trigger_base.cpp trigger_base.h Log Message: The BIG COMMIT(tm) This is it, expect a broken supertux I only fixed the most annoying issues so far, lots more are still waiting in the TODO list, but I had to bring this stuff to cvs sometime. Changes: - Completely new collision detection scheme, which collides all objects with each other once per frame, instead of single objects manually testing for collisions - New collision detection routines which support slopes and provide additional info on collisions: penetration depth, hit normal vector - Lots of general cleanup/refactoring - Splitted the monolithic badguy class and reimplemented most of them as single classes with a badguy base class. - Splitted the monolithic Special class into several classes - Rewrote the timer and all timing related stuff to work on float and seconds (not like the mixup before where you had frame_ratio, msecs and secs in different parts of the app) - Support for unisolid tiles - Created a flying platform prototype (doesn't work completely yet) - rename InteractiveObjects to triggers and implemented a new sequence trigger, (only supported sequence is endsequence at the moment) - transformed the bonusblocks and bricks into objects --- NEW FILE: door.h --- // $Id: door.h,v 1.1 2004/11/20 22:14:40 matzebraun Exp $ // // SuperTux - A Jump'n Run // Copyright (C) 2004 Matthias Braun <ma...@br... // // 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_DOOR_H #define SUPERTUX_DOOR_H #include <string> #include "video/surface.h" #include "special/sprite.h" #include "trigger_base.h" #include "serializable.h" #include "timer.h" class Door : public TriggerBase, public Serializable { public: Door(LispReader& reader); Door(int x, int y); virtual ~Door(); virtual void write(LispWriter& writer); virtual void action(float elapsed_time); virtual void draw(DrawingContext& context); virtual void event(Player& player, EventType type); private: std::string target_sector; std::string target_spawnpoint; Sprite* sprite; }; #endif --- NEW FILE: trigger_base.cpp --- // $Id: trigger_base.cpp,v 1.1 2004/11/20 22:14:40 matzebraun Exp $ // // SuperTux - A Jump'n Run // Copyright (C) 2004 Matthias Braun <ma...@br... // // 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 "trigger_base.h" #include "player.h" #include "video/drawing_context.h" TriggerBase::TriggerBase() : sprite(0) { } TriggerBase::~TriggerBase() { } void TriggerBase::action(float ) { lasthit = hit; hit = false; } void TriggerBase::draw(DrawingContext& context) { if(!sprite) return; sprite->draw(context, get_pos(), LAYER_TILES+1); } HitResponse TriggerBase::collision(GameObject& other, const CollisionHit& collhit) { Player* player = dynamic_cast<Player*> (&other); if(player) { hit = true; if(!lasthit) event(*player, EVENT_TOUCH); } return ABORT_MOVE; } --- NEW FILE: trigger_base.h --- // $Id: trigger_base.h,v 1.1 2004/11/20 22:14:40 matzebraun Exp $ // // SuperTux - A Jump'n Run // Copyright (C) 2004 Matthias Braun <ma...@br... // // 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_TRIGGER_BASE_H #define SUPERTUX_TRIGGER_BASE_H #include "special/moving_object.h" #include "math/rectangle.h" #include "special/sprite.h" class Player; using namespace SuperTux; /** This class is the base class for all objects you can interact with in some * way. There are several interaction types defined like touch and activate */ class TriggerBase : public MovingObject { public: enum EventType { EVENT_TOUCH, EVENT_ACTIVATE }; TriggerBase(); ~TriggerBase(); void action(float elapsed_time); void draw(DrawingContext& context); HitResponse collision(GameObject& other, const CollisionHit& hit); /** * Receive trigger events */ virtual void event(Player& player, EventType type) = 0; private: Sprite* sprite; bool lasthit; bool hit; }; #endif /*SUPERTUX_INTERACTIVE_OBJECT_H*/ --- NEW FILE: door.cpp --- // $Id: door.cpp,v 1.1 2004/11/20 22:14:40 matzebraun Exp $ // // SuperTux - A Jump'n Run // Copyright (C) 2004 Matthias Braun <ma...@br... // // 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 "door.h" #include "utils/lispreader.h" #include "utils/lispwriter.h" #include "gameloop.h" #include "resources.h" #include "special/sprite.h" #include "special/sprite_manager.h" #include "video/drawing_context.h" #include "app/globals.h" using namespace SuperTux; Door::Door(LispReader& reader) { reader.read_float("x", bbox.p1.x); reader.read_float("y", bbox.p1.y); bbox.set_size(32, 64); reader.read_string("sector", target_sector); reader.read_string("spawnpoint", target_spawnpoint); sprite = sprite_manager->create("door"); } Door::Door(int x, int y) { bbox.set_pos(Vector(x, y)); bbox.set_size(32, 64); sprite = sprite_manager->create("door"); } Door::~Door() { delete sprite; } void Door::write(LispWriter& writer) { writer.start_list("door"); writer.write_float("x", bbox.p1.x); writer.write_float("y", bbox.p1.y); writer.write_float("width", bbox.get_width()); writer.write_float("height", bbox.get_height()); writer.write_string("sector", target_sector); writer.write_string("spawnpoint", target_spawnpoint); writer.end_list("door"); } void Door::action(float ) { //Check if door animation is complete if (!sprite->check_animation()) { GameSession::current()->respawn(target_sector, target_spawnpoint); } } void Door::draw(DrawingContext& context) { sprite->draw(context, bbox.p1, LAYER_TILES); } void Door::event(Player& player, EventType type) { if(type == EVENT_ACTIVATE) { sprite->set_action("open"); sprite->start_animation(1); } } --- NEW FILE: sequence_trigger.h --- #ifndef __SEQUENCE_TRIGGER_H__ #define __SEQUENCE_TRIGGER_H__ #include "trigger_base.h" #include "serializable.h" class SequenceTrigger : public TriggerBase, public Serializable { public: SequenceTrigger(LispReader& reader, const std::string& sequence); SequenceTrigger(const Vector& pos, const std::string& sequence); ~SequenceTrigger(); void write(LispWriter& writer); void event(Player& player, EventType type); private: EventType triggerevent; std::string sequence_name; }; #endif --- NEW FILE: sequence_trigger.cpp --- #include <config.h> #include "sequence_trigger.h" #include "utils/lispwriter.h" #include "gameloop.h" SequenceTrigger::SequenceTrigger(LispReader& reader, const std::string& sequence) { // TODO } SequenceTrigger::SequenceTrigger(const Vector& pos, const std::string& sequence) { bbox.set_pos(pos); bbox.set_size(32, 32); sequence_name = sequence; triggerevent = EVENT_TOUCH; } SequenceTrigger::~SequenceTrigger() { } void SequenceTrigger::write(LispWriter& writer) { writer.start_list("sequencetrigger"); writer.write_float("x", bbox.p1.x); writer.write_float("y", bbox.p1.y); writer.write_float("width", bbox.get_width()); writer.write_float("height", bbox.get_height()); writer.write_string("sequence", sequence_name); writer.end_list("sequencetrigger"); } void SequenceTrigger::event(Player& player, EventType type) { if(type == triggerevent) { GameSession::current()->start_sequence(sequence_name); } } |