From 1d63ad0dfe0eedf89191627be00b2b3b1215c311 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Fri, 31 Mar 2006 01:28:07 +0000 Subject: [PATCH] forgot to add some files, fix invisible tiles SVN-Revision: 3140 --- src/collision_hit.hpp | 3 +- src/object/invisible_block.cpp | 2 + src/object/path_walker.cpp | 130 +++++++++++++++++++++++++++++++++++++++++ src/object/path_walker.hpp | 62 ++++++++++++++++++++ src/object/platform.cpp | 2 +- src/sector.cpp | 2 +- 6 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 src/object/path_walker.cpp create mode 100644 src/object/path_walker.hpp diff --git a/src/collision_hit.hpp b/src/collision_hit.hpp index 81547d8c6..c6c3dd824 100644 --- a/src/collision_hit.hpp +++ b/src/collision_hit.hpp @@ -34,7 +34,8 @@ enum HitResponse CONTINUE, /// do the move ignoring the collision FORCE_MOVE, - TEST + /// passes movement to collided object + PASS_MOVEMENT }; /** diff --git a/src/object/invisible_block.cpp b/src/object/invisible_block.cpp index 38e294769..db3408a07 100644 --- a/src/object/invisible_block.cpp +++ b/src/object/invisible_block.cpp @@ -33,6 +33,7 @@ InvisibleBlock::InvisibleBlock(const Vector& pos) { bbox.set_pos(pos); flags &= ~FLAG_SOLID; + set_group(COLGROUP_MOVING); } void @@ -52,6 +53,7 @@ InvisibleBlock::hit(Player& ) sound_manager->play("sounds/brick.wav"); start_bounce(); flags |= FLAG_SOLID; + set_group(COLGROUP_STATIC); visible = true; } diff --git a/src/object/path_walker.cpp b/src/object/path_walker.cpp new file mode 100644 index 000000000..1eca37023 --- /dev/null +++ b/src/object/path_walker.cpp @@ -0,0 +1,130 @@ +// $Id: path.hpp 3114 2006-03-23 23:47:04Z sommer $ +// +// SuperTux Path +// Copyright (C) 2005 Philipp +// Copyright (C) 2006 Christoph Sommer +// Copyright (C) 2006 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 +#include "path_walker.hpp" + +PathWalker::PathWalker(const Path* path) + : path(path), current_node_nr(0), next_node_nr(0), node_time(0), + walking_speed(1.0) +{ + last_pos = path->nodes[0].position; + node_time = path->nodes[0].time; +} + +PathWalker::~PathWalker() +{ +} + +Vector +PathWalker::advance(float elapsed_time) +{ + assert(elapsed_time >= 0); + + elapsed_time *= fabsf(walking_speed); + + const Path::Node* current_node = & (path->nodes[current_node_nr]); + while(node_time - elapsed_time < 0) { + elapsed_time -= current_node->time - node_time; + + if(walking_speed > 0) { + advance_node(); + } else if(walking_speed < 0) { + goback_node(); + } + + current_node = & (path->nodes[current_node_nr]); + if(walking_speed > 0) { + node_time = current_node->time; + } else { + node_time = path->nodes[next_node_nr].time; + } + } + + const Path::Node* next_node = & (path->nodes[next_node_nr]); + node_time -= elapsed_time; + + Vector new_pos = current_node->position + + (next_node->position - current_node->position) + * (1 - (node_time / current_node->time)); + + Vector result = new_pos - last_pos; + last_pos = new_pos; + + return result; +} + +void +PathWalker::advance_node() +{ + current_node_nr = next_node_nr; + + if(next_node_nr + 1 < path->nodes.size()) { + next_node_nr++; + return; + } + + switch(path->mode) { + case Path::ONE_SHOT: + next_node_nr = path->nodes.size() - 1; + walking_speed = 0; + return; + + case Path::PING_PONG: + walking_speed = -walking_speed; + next_node_nr = path->nodes.size() > 1 ? path->nodes.size() - 2 : 0; + return; + + case Path::CIRCULAR: + next_node_nr = 0; + return; + } + + // we shouldn't get here + assert(false); + next_node_nr = path->nodes.size() - 1; + walking_speed = 0; +} + +void +PathWalker::goback_node() +{ + current_node_nr = next_node_nr; + + if(next_node_nr > 0) { + next_node_nr--; + return; + } + + switch(path->mode) { + case Path::PING_PONG: + walking_speed = -walking_speed; + return; + default: + break; + } + + assert(false); + next_node_nr = 0; + walking_speed = 0; +} diff --git a/src/object/path_walker.hpp b/src/object/path_walker.hpp new file mode 100644 index 000000000..016de8a3f --- /dev/null +++ b/src/object/path_walker.hpp @@ -0,0 +1,62 @@ +// $Id: path.hpp 3114 2006-03-23 23:47:04Z sommer $ +// +// SuperTux Path +// Copyright (C) 2005 Philipp +// Copyright (C) 2006 Christoph Sommer +// +// 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 __PATH_WALKER_HPP__ +#define __PATH_WALKER_HPP__ + +#include "path.hpp" +#include "math/vector.hpp" +#include "game_object.hpp" +#include "lisp/lisp.hpp" +#include "serializable.hpp" + +/** + * A walker that travels along a path + */ +class PathWalker +{ +public: + PathWalker(const Path* path); + virtual ~PathWalker(); + + /** + * advanves the path walker on the path and returns the position delta + * to the last position + */ + virtual Vector advance(float elapsed_time); + +private: + void advance_node(); + void goback_node(); + + const Path* path; + + size_t current_node_nr; + size_t next_node_nr; + + Vector last_pos; + + /** the time we already spend in the current node */ + float node_time; + + float walking_speed; +}; + +#endif diff --git a/src/object/platform.cpp b/src/object/platform.cpp index cbe01888a..fb38398c6 100644 --- a/src/object/platform.cpp +++ b/src/object/platform.cpp @@ -69,7 +69,7 @@ Platform::collision(GameObject& other, const CollisionHit& hit) //Tux is standing on the platform //Player* player = (Player*) &other; //player->add_velocity(speed * 1.5); - return TEST; + return PASS_MOVEMENT; } } if(other.get_flags() & FLAG_SOLID) { diff --git a/src/sector.cpp b/src/sector.cpp index 071e059c2..9e33ce7c0 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -760,7 +760,7 @@ Sector::collision_static(MovingObject* object, const Vector& movement) // the static object "wins" move tux out of the collision object->dest.move(-hit.normal * (hit.depth + DELTA)); return false; - } else if(other_response == TEST) { + } else if(other_response == PASS_MOVEMENT) { object->dest.move(moving_object->get_movement()); //object->movement += moving_object->get_movement(); } -- 2.11.0