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"
|
2011-08-04 19:33:41 -04:00
|
|
|
#include "tracks/track_sector.hpp"
|
2011-07-19 20:39:32 -04:00
|
|
|
|
|
|
|
class Kart;
|
|
|
|
class QuadGraph;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \ingroup items
|
|
|
|
*/
|
2011-08-04 19:33:41 -04:00
|
|
|
class RubberBall: public Flyable, public TrackSector
|
2011-07-19 20:39:32 -04:00
|
|
|
{
|
|
|
|
private:
|
2011-08-03 02:56:49 -04:00
|
|
|
/** A class variable to store the default interval size. */
|
|
|
|
static float m_st_interval;
|
|
|
|
|
|
|
|
/** A class variable to store the default squash duration. */
|
|
|
|
static float m_st_squash_duration;
|
|
|
|
|
2011-08-14 20:25:30 -04:00
|
|
|
/** A class variable to store the default squash slowdown. */
|
|
|
|
static float m_st_squash_slowdown;
|
|
|
|
|
2011-08-17 23:31:52 -04:00
|
|
|
/** If the ball is closer than this distance to the target, it will
|
|
|
|
* start to aim directly at the target (and not interpolate anymore). */
|
|
|
|
static float m_st_target_distance;
|
|
|
|
|
|
|
|
/** Each control point chosen must be at least this far away from
|
|
|
|
* the previous one. This gives smooth 'overall' interpolation
|
|
|
|
* even if the quads should be close to each other. */
|
|
|
|
static float m_st_min_interpolation_distance;
|
|
|
|
|
2011-07-19 20:39:32 -04:00
|
|
|
/** A pointer to the target kart. */
|
|
|
|
const Kart *m_target;
|
|
|
|
|
2011-08-14 20:25:30 -04:00
|
|
|
/** The last graph node who's coordinates are stored in
|
|
|
|
* m_control_points[3]. */
|
|
|
|
int m_last_aimed_graph_node;
|
2011-07-20 18:21:44 -04:00
|
|
|
|
2011-08-03 02:56:49 -04:00
|
|
|
/** Keep the last two, current, and next aiming points
|
2011-08-17 19:06:48 -04:00
|
|
|
* for interpolation. */
|
2011-08-14 20:25:30 -04:00
|
|
|
Vec3 m_control_points[4];
|
|
|
|
|
2011-08-17 19:06:48 -04:00
|
|
|
/** Saves the previous location of the ball. This is needed if a ball
|
|
|
|
* should lose it target, and has to reinitialise the control points
|
|
|
|
* for the interpolation. */
|
|
|
|
Vec3 m_previous_xyz;
|
|
|
|
|
2011-08-14 20:25:30 -04:00
|
|
|
/** Estimated length of the spline between the control points
|
|
|
|
* 1 and 2. */
|
|
|
|
float m_length_cp_1_2;
|
|
|
|
|
|
|
|
/** Estimated length of the spline between the control points
|
|
|
|
* 2 and 3. */
|
|
|
|
float m_length_cp_2_3;
|
|
|
|
|
|
|
|
/** The parameter for the spline, m_t in [0,1]. This is not directly
|
|
|
|
* related to the time, since depending on the distance between
|
|
|
|
* the two control points different increments must be used for m_t.
|
|
|
|
* For example, if the distance is 10 m, and assuming a speed of
|
|
|
|
* 10 m/s for the ball, then each second must add '1' to m_t. If
|
|
|
|
* the distance on the other hand is 200 m, then 10/200 = 1/20 per
|
|
|
|
* second must be added (so that it takes 20 seconds to move from 0
|
|
|
|
* to 1). */
|
2011-08-03 02:56:49 -04:00
|
|
|
float m_t;
|
|
|
|
|
|
|
|
/** How much m_tt must increase per second in order to maintain a
|
2011-08-14 20:25:30 -04:00
|
|
|
* constant speed, i.e. the speed of the ball divided by the
|
|
|
|
* distance between the control points. See m_t for more details. */
|
2011-08-03 02:56:49 -04:00
|
|
|
float m_t_increase;
|
|
|
|
|
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-08-14 20:25:30 -04:00
|
|
|
/** The current maximum height of the ball. This value will be
|
|
|
|
* reduced if the ball gets closer to the target. */
|
|
|
|
float m_current_max_height;
|
2011-07-22 02:26:28 -04:00
|
|
|
|
2011-07-19 20:39:32 -04:00
|
|
|
/** 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;
|
|
|
|
|
|
|
|
void computeTarget();
|
2011-08-17 19:06:48 -04:00
|
|
|
void checkDistanceToTarget();
|
2011-08-14 20:25:30 -04:00
|
|
|
unsigned int getSuccessorToHitTarget(unsigned int node_index,
|
|
|
|
float *f=NULL);
|
|
|
|
void getNextControlPoint();
|
|
|
|
float updateHeight();
|
2011-08-17 19:06:48 -04:00
|
|
|
void interpolate(Vec3 *next_xyz, float dt);
|
|
|
|
void initializeControlPoints(const Vec3 &xyz);
|
2011-07-19 20:39:32 -04:00
|
|
|
public:
|
|
|
|
RubberBall (Kart* kart);
|
|
|
|
static void init(const XMLNode &node, scene::IMesh *bowling);
|
|
|
|
virtual void update (float dt);
|
2011-07-26 02:58:11 -04:00
|
|
|
virtual void hit (Kart* kart, PhysicalObject* obj=NULL);
|
2011-08-03 02:56:49 -04:00
|
|
|
/** This object does not create an explosion, all affects on
|
|
|
|
* karts are handled by this hit() function. */
|
2011-07-26 02:58:11 -04:00
|
|
|
virtual bool needsExplosion() const {return false;}
|
|
|
|
|
2011-07-19 20:39:32 -04:00
|
|
|
}; // RubberBall
|
|
|
|
|
|
|
|
#endif
|