2011-07-19 20:39:32 -04:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2011 Joerg Henrichs
|
|
|
|
//
|
|
|
|
// 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 3
|
|
|
|
// 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 HEADER_RUBBER_BALL_HPP
|
|
|
|
#define HEADER_RUBBER_BALL_HPP
|
|
|
|
|
|
|
|
#include "items/flyable.hpp"
|
|
|
|
|
|
|
|
class Kart;
|
|
|
|
class QuadGraph;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \ingroup items
|
|
|
|
*/
|
|
|
|
class RubberBall: public Flyable
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
/** A pointer to the target kart. */
|
|
|
|
const Kart *m_target;
|
|
|
|
|
2011-07-20 18:21:44 -04:00
|
|
|
/** The current quad this ball is on. */
|
2011-07-19 20:39:32 -04:00
|
|
|
int m_current_graph_node;
|
|
|
|
|
2011-07-20 18:21:44 -04:00
|
|
|
/** The current quad this ball is aiming at. */
|
|
|
|
int m_aimed_graph_node;
|
|
|
|
|
2011-07-19 20:39:32 -04:00
|
|
|
/** The previous distance to the graph node we are aiming
|
|
|
|
* at atm. If the distance increases, we have passed the
|
|
|
|
* point we aimed at and have to aim at the next point. */
|
|
|
|
float m_distance_along_track;
|
|
|
|
|
2011-07-21 18:07:09 -04:00
|
|
|
/** A class variable to store the default interval size. */
|
|
|
|
static float m_st_interval;
|
2011-07-21 02:58:28 -04:00
|
|
|
|
2011-07-21 18:07:09 -04:00
|
|
|
/** How long it takes from one bounce of the ball to the next. */
|
|
|
|
float m_interval;
|
|
|
|
|
|
|
|
/** This timer is used to determine the height depending on the time.
|
|
|
|
* It is always between 0 and m_interval. */
|
2011-07-21 02:58:28 -04:00
|
|
|
float m_timer;
|
|
|
|
|
2011-07-22 02:26:28 -04:00
|
|
|
/** The maximum height of the ball. This value will be reduced if the
|
|
|
|
* ball gets closer to the target. */
|
|
|
|
float m_height;
|
|
|
|
|
2011-07-19 20:39:32 -04:00
|
|
|
/** True if the ball just crossed the start line, i.e. its
|
|
|
|
* distance changed from close to length of track in the
|
|
|
|
* previous time step to a bit over zero now. */
|
|
|
|
bool m_wrapped_around;
|
|
|
|
|
|
|
|
/** Once the ball is close enough, it will aim for the kart. If the
|
|
|
|
* kart should be able to then increase the distance to the ball,
|
|
|
|
* the ball will be removed and the kart escapes. This boolean is
|
|
|
|
* used to keep track of the state of this ball. */
|
|
|
|
bool m_aiming_at_target;
|
|
|
|
|
|
|
|
/** For convenience keep a pointer to the quad graph. */
|
|
|
|
QuadGraph *m_quad_graph;
|
|
|
|
|
|
|
|
void computeTarget();
|
|
|
|
void determineTargetCoordinates(float dt, Vec3 *aim_xyz);
|
|
|
|
public:
|
|
|
|
RubberBall (Kart* kart);
|
|
|
|
static void init(const XMLNode &node, scene::IMesh *bowling);
|
|
|
|
|
|
|
|
virtual void update (float dt);
|
|
|
|
}; // RubberBall
|
|
|
|
|
|
|
|
#endif
|