git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/christmas@12312 178a84e3-b1eb-0310-8ba1-8eac791a3b58

This commit is contained in:
funto66
2012-12-27 17:10:02 +00:00
parent 4f54d52469
commit bd70940af9
7 changed files with 66 additions and 15 deletions

View File

@@ -18,9 +18,9 @@
#include "tracks/check_goal.hpp"
#include "animations/animation_base.hpp"
#include "io/xml_node.hpp"
#include "karts/abstract_kart.hpp"
#include "tracks/track.hpp"
#include "tracks/track_object_manager.hpp"
#include "modes/world.hpp"
#include <stdio.h>
@@ -31,8 +31,42 @@
CheckGoal::CheckGoal(const XMLNode &node, unsigned int index)
: CheckLine(node, index)
{
m_first_goal = false;
node.get("first_goal", &m_first_goal);
} // CheckGoal
// ----------------------------------------------------------------------------
/**
* Checks the soccer balls to see if they crossed the line and trigger the goal accordingly.
*/
void CheckGoal::update(float dt) OVERRIDE
{
World *world = World::getWorld();
assert(world);
Track* track = world->getTrack();
assert(track);
TrackObjectManager* tom = track->getTrackObjectManager();
assert(tom);
PtrVector<TrackObject>& objects = tom->getObjects();
for(unsigned int i=0; i<objects.size(); i++)
{
TrackObject* obj = objects.get(i);
if(!obj->isSoccerBall())
continue;
const Vec3 &xyz = obj->getNode()->getPosition();
// Only check active goal lines.
if(m_is_active[i] && isTriggered(m_previous_position[i], xyz, i))
{
if(UserConfigParams::m_check_debug)
printf("CHECK: Goal check structure %d triggered for object %s.\n",
m_index, obj->getDebugName());
trigger(i);
}
m_previous_position[i] = xyz;
}
}
// ----------------------------------------------------------------------------
/** Called when the check line is triggered. This function creates a cannon
* animation object and attaches it to the kart.
@@ -40,5 +74,5 @@ CheckGoal::CheckGoal(const XMLNode &node, unsigned int index)
*/
void CheckGoal::trigger(unsigned int kart_index)
{
printf("*** DEBUG TEST ***\n");
printf("*** TODO: GOOOOOOOOOAAAAAAALLLLLL!!!! ***\n");
} // CheckGoal

View File

@@ -21,6 +21,7 @@
#include "animations/animation_base.hpp"
#include "tracks/check_line.hpp"
#include "utils/cpp2011.h"
class CheckManager;
class XMLNode;
@@ -33,9 +34,12 @@ class XMLNode;
*/
class CheckGoal : public CheckLine
{
private:
bool m_first_goal;
public:
CheckGoal(const XMLNode &node, unsigned int index);
virtual ~CheckGoal() {}
virtual void update(float dt) OVERRIDE;
virtual void trigger(unsigned int kart_index);
}; // CheckLine

View File

@@ -24,6 +24,7 @@
#include "io/xml_node.hpp"
#include "tracks/ambient_light_sphere.hpp"
#include "tracks/check_cannon.hpp"
#include "tracks/check_goal.hpp"
#include "tracks/check_lap.hpp"
#include "tracks/check_line.hpp"
#include "tracks/check_structure.hpp"
@@ -48,10 +49,14 @@ void CheckManager::load(const XMLNode &node)
{
m_all_checks.push_back(new CheckLap(*check_node, i));
}
else if(type=="cannon")
{
m_all_checks.push_back(new CheckCannon(*check_node, i));
}
else if(type=="cannon")
{
m_all_checks.push_back(new CheckCannon(*check_node, i));
}
else if(type=="goal")
{
m_all_checks.push_back(new CheckGoal(*check_node, i));
}
else if(type=="check-sphere")
{
AmbientLightSphere *cs = new AmbientLightSphere(*check_node,

View File

@@ -65,8 +65,8 @@ CheckStructure::CheckStructure(const XMLNode &node, unsigned int index)
== m_same_group.end())
m_same_group.push_back(m_index);
// As a default, only lap lines and cannons are activated
m_active_at_reset= m_check_type==CT_NEW_LAP || m_check_type==CT_CANNON;
// As a default, only lap lines, cannons and goals are activated
m_active_at_reset= m_check_type==CT_NEW_LAP || m_check_type==CT_CANNON || m_check_type==CT_GOAL;
node.get("active", &m_active_at_reset);
} // CheckStructure

View File

@@ -54,7 +54,8 @@ public:
* the state that check structure is in)
* TOGGLE: Switches (inverts) the state of another check structure.
* NEW_LAP: On crossing a new lap is counted.
* CANNON: Causes the kart to be shot to a specified point.
* CANNON: Causes the kart to be shot to a specified point.
* GOAL: Causes a point to be scored when a soccer ball crosses its line
* AMBIENT_SPHERE: Modifies the ambient color.
* A combination of an activate and new_lap line are used to
* avoid shortcuts: a new_lap line is deactivated after crossing it, and
@@ -62,7 +63,7 @@ public:
* enabling you to count the lap again.
*/
enum CheckType {CT_NEW_LAP, CT_ACTIVATE, CT_TOGGLE, CT_CANNON,
CT_AMBIENT_SPHERE};
CT_GOAL, CT_AMBIENT_SPHERE};
protected:
/** Stores the previous position of all karts. This is needed to detect
@@ -75,13 +76,13 @@ protected:
/** True if this check structure should be activated at a reset. */
bool m_active_at_reset;
private:
/** The type of this checkline. */
CheckType m_check_type;
/** Stores the index of this check structure. This is only used for
* debugging (use --check-debug option). */
unsigned int m_index;
private:
/** The type of this checkline. */
CheckType m_check_type;
/** Contains the indices of the corresponding check structures that
* get their state changed (activated or switched). */

View File

@@ -72,6 +72,9 @@ TrackObject::TrackObject(const XMLNode &xml_node)
xml_node.get("interaction", &m_interaction);
xml_node.get("lod_group", &m_lod_group);
m_soccer_ball = false;
xml_node.get("soccer_ball", &m_soccer_ball);
std::string type;
xml_node.get("type", &type );

View File

@@ -104,6 +104,8 @@ protected:
LODNode* m_lod_emitter_node;
bool m_soccer_ball;
public:
TrackObject(const XMLNode &xml_node);
TrackObject();
@@ -151,6 +153,8 @@ public:
const std::string& getType() const { return m_type; }
bool isSoccerBall() const { return m_soccer_ball; }
/** Currently used for sound effects only, in cutscenes only atm */
const std::string& getTriggerCondition() const { return m_trigger_condition; }