ArnieBoids  1.0.0
JOINT AI PROJECT
Asteroid Class Reference

Asteroid class. Asteroids are technically ships but do things a little differently. Constantly move forward at fixed speed, collisions impart some velocity change. More...

#include <Asteroid.hpp>

Inheritance diagram for Asteroid:
Collaboration diagram for Asteroid:

Public Member Functions

 Asteroid (thor::ParticleSystem &particleSystem, sf::Vector2f const &position, sf::Vector2f const &direction, float spinSpeed=(rand()%50-25)*0.1f)
 
 Asteroid (thor::ParticleSystem &particleSystem, sf::Vector2f const &position, float spinSpeed=(rand()%50-25)*0.1f)
 
 ~Asteroid ()
 
void update () override
 Moves us forward and keps us spinning. More...
 
void onCollide (Ship *other) override
 Colliding with ships will impart some of that ship's velocity on us. More...
 
- Public Member Functions inherited from Ship
 Ship (thor::ParticleSystem &particleSystem, sf::Vector2f const &position, float maxSpeed, unsigned int health=1u)
 
 ~Ship ()
 
void takeDamage (unsigned int amount=1u)
 Reduces health by the specified amount. More...
 
bool isDead () const
 Returns true if health is zero. More...
 
void thrust ()
 Apply acceleration in direction of forward vector. More...
 
void brake ()
 Apply deceleration if thrust is present. More...
 
void turnLeft ()
 Turn ship left. More...
 
void turnRight ()
 Turn ship right. More...
 
bool trigger ()
 Attempt to fire, returns success. More...
 
void turnToward (sf::Vector2f const &direction)
 
sf::Vector2f getForward () const
 Returns forward direction of ship. More...
 
sf::Vector2f getVelocity () const
 Returns velocity. More...
 
void setRadarRange (float range)
 Radar radius accessors. More...
 
float getRadarRange () const
 
int getHealth () const
 Health accessors. More...
 
void addHealth (unsigned int health)
 
unsigned int getMaxHealth () const
 

Private Member Functions

void generateGeometry ()
 

Private Attributes

float rotationSpeed_
 How fast we rotate per tick (in degrees) More...
 

Additional Inherited Members

- Public Attributes inherited from Ship
sf::RectangleShape debug_rect_
 
- Protected Member Functions inherited from Ship
void clampToMaxSpeed ()
 Clamps the length of the velocity_ vector to MAX_SPEED_. More...
 
float tickToSec (unsigned int ticks) const
 Ticks to seconds. More...
 
virtual void updateParticleEmitter ()
 
- Protected Attributes inherited from Ship
const float MAX_SPEED_
 Maximum length of velocity vector. More...
 
const unsigned int MAX_HEALTH_
 
float refireTime_
 
float coolDown_
 
unsigned int ticks_
 
sf::Vector2f velocity_
 Delta position per update. More...
 
sf::Vector2f accel_
 Delta velocity after update !velocity_ += accel_ in update! More...
 
int health_
 Current health. More...
 
sf::Vector2f forward_
 Unit vector for ship's heading. More...
 
float thrust_
 How fast the ship accelerates. More...
 
float turnSpeed_
 How fast (in degrees) the ship can turn. More...
 
float radarRange_
 Ship's radar radius. More...
 
thor::UniversalEmitter particleEmitter_
 Does nothing on it's own. Derived classes should play with this. More...
 
float particleAngleVariance_
 

Detailed Description

Asteroid class. Asteroids are technically ships but do things a little differently. Constantly move forward at fixed speed, collisions impart some velocity change.

Constructor & Destructor Documentation

Asteroid::Asteroid ( thor::ParticleSystem &  particleSystem,
sf::Vector2f const &  position,
sf::Vector2f const &  direction,
float  spinSpeed = (rand() % 50 - 25) * 0.1f 
)
Parameters
positionInitial position of the Asteroid.
directionThe heading that the Asteroid will travel on
spinSpeedHow fast (in degrees per tick) that the asteroid will rotate

Here is the call graph for this function:

Asteroid::Asteroid ( thor::ParticleSystem &  particleSystem,
sf::Vector2f const &  position,
float  spinSpeed = (rand() % 50 - 25) * 0.1f 
)

Here is the call graph for this function:

Asteroid::~Asteroid ( )

Member Function Documentation

void Asteroid::generateGeometry ( )
private

Generates a convex shape with a randomly generated number of sides and variations on the x and y position of each vertex.

Remarks
Uses Rcos(theta) to place points along a circle and then uses rand() vary the positions.
Generates a random shade of brown as fill color.
Though shape outline is thick, it is drawn inside the shape bounds (because it's negative).

Here is the call graph for this function:

Here is the caller graph for this function:

void Asteroid::onCollide ( Ship other)
overridevirtual

Colliding with ships will impart some of that ship's velocity on us.

Remarks
Asteroids do not "collide", with each other; they grind against and damage each other

Implements Ship.

Here is the call graph for this function:

void Asteroid::update ( )
overridevirtual

Moves us forward and keps us spinning.

Reimplemented from Ship.

Member Data Documentation

float Asteroid::rotationSpeed_
private

How fast we rotate per tick (in degrees)


The documentation for this class was generated from the following files: