ComputerGraphik TU WIEN
Classes | Public Member Functions | Private Attributes | List of all members
GameLogic Class Reference

Implements the game logic of SteelWorms. More...

#include <gameLogic.hpp>

Inheritance diagram for GameLogic:
SceneObject

Classes

class  Bullet
 Implements the bullet movement on CPU. More...
 
class  Terrain
 Implements terrain height query. More...
 

Public Member Functions

 GameLogic (Scene *scene)
 
 ~GameLogic ()
 
void update (double deltaT)
 
void addTank (std::shared_ptr< SceneObject > tank)
 
bool isGameFinished () const
 
size_t getWinner () const
 
std::shared_ptr< TerraingetTerrain () const
 
- Public Member Functions inherited from SceneObject
 SceneObject (std::shared_ptr< SceneObject > &effectParent, const glm::mat4 &modelMatrix=glm::mat4(1))
 
 SceneObject (const std::string &name, Scene *scene=0, Model *model=0, const glm::mat4 &modelMatrix=glm::mat4(1))
 
virtual ~SceneObject ()
 
ModelgetModel () const
 
ShadergetShader () const
 
glm::mat4 getModelMatrix () const
 
glm::mat4 getGlobalModelMatrix () const
 
std::string getName () const
 
std::shared_ptr< SceneObjectgetParent () const
 
void setAnimationTime (double time)
 
bool setAnimation (const Animation &anim)
 
bool delChild (size_t idx)
 
bool getChild (size_t idx, std::shared_ptr< SceneObject > &child) const
 
bool addChild (std::shared_ptr< SceneObject > &child)
 
bool remEffect (const std::string &name)
 
SceneObjectgetEffect (const std::string &name) const
 
bool addEffect (const std::string &name, std::unique_ptr< SceneObject > &effect)
 
bool doNotRender ()
 
bool getIsVolSun ()
 
virtual void reset ()
 
virtual void draw () const
 
virtual bool animate (double time)
 
virtual void setShader (Shader *val)
 

Private Attributes

double turnTime
 
size_t activeTank
 
bool gameFinished
 
std::unique_ptr< ModelwaterModel
 
std::unique_ptr< ModelterrainModel
 
std::unique_ptr< TexturewaterTexture
 
std::shared_ptr< Bulletbullet
 
std::shared_ptr< Terrainwater
 
std::shared_ptr< Terrainterrain
 
std::vector< std::shared_ptr< Tank > > tanks
 

Additional Inherited Members

- Public Types inherited from SceneObject
typedef std::vector< std::pair< double, glm::mat4 > > Animation
 
- Protected Attributes inherited from SceneObject
GLuint vao
 
Scenescene
 
Modelmodel
 
Shadershader
 
glm::mat4 modelMatrix
 
std::string name
 
std::weak_ptr< SceneObjectparent
 
std::vector< std::shared_ptr< SceneObject > > childs
 
std::map< std::string, std::unique_ptr< SceneObject > > effectChilds
 
size_t animIDX
 
Animation animation
 
bool norender
 
bool isVolSun
 

Detailed Description

Implements the game logic of SteelWorms.

The GameLogic class

Author
Adam
Terrain
A triangle is built up from 3 pixels, so 4 neighboring pixel represents two triangles. The pixel values(scaled to 0..1) are stored in a lookup table. With the function getHeight() it is possible to get the height value for any x and y coordinate. The idea of the algorithm which computes the heights is from the "Introduction to 3D game programming with DirectX 9.0" book page 228-231 written by "Rod Lopez, Frank D. Luna". The algorithm computes the position of the 4 pixel values surrounded by the given x and y coordinate and then interpolates the height value from the corresponding coordinates.
Bullet

The trajectory of a bullet is computed by the following equation:

$z = z_0 + d - {gd^2}{2(v)^2}$

This equation computes the height of the bullet. The value v in the equation is the velocity. The longer the SPACE key is held to shoot, the higher this value will be. The value d is the distance from the shoot point. Theta is the angle, which is currently 45 degrees. Value g is the gravity, set to 9.81. The collision is detected by comparing the height of the bullet with the height of the terrain at the x and y coordinate of the bullet. If the difference is negative, then the bullet has reached the ground. Then the distance of the impact point and all the tanks are compared. If the distance is under a threshold, then the health of the actual tank is decreased according to the distance.

See also
Wikipedia (Ballistic_trajectory)
Tank
Each player controls one tank. The color of the tank shows the health of a tank. By controlling the turret and the gun the shooting direction and angle can be modified. Holding the space longer will make the bullet to fly further. The closer the bullet reaches the center of an other tank the more damage it does. The health of the tanks will decrease if they are in standing in water in they current turn. The deeper the water the more they loose health.
Transparency
To achieve transparency, a water surface is constructed. The Terrain class is used to display the water. It is textured with 0.5 transparency. The tank trail is rendered using ParticleSystemCPU, which is sorting the particles based on the camera distance. It is rendered before the water to see it under the water. The track's transparency is decreased with time until it reaches zero.

Constructor & Destructor Documentation

GameLogic::GameLogic ( Scene scene)
GameLogic::~GameLogic ( )

Member Function Documentation

void GameLogic::addTank ( std::shared_ptr< SceneObject tank)
std::shared_ptr<Terrain> GameLogic::getTerrain ( ) const
inline
size_t GameLogic::getWinner ( ) const
inline
bool GameLogic::isGameFinished ( ) const
inline
void GameLogic::update ( double  deltaT)
virtual
Todo:
Set model for bullet

Reimplemented from SceneObject.

Member Data Documentation

size_t GameLogic::activeTank
private
std::shared_ptr<Bullet> GameLogic::bullet
private
bool GameLogic::gameFinished
private
std::vector<std::shared_ptr<Tank> > GameLogic::tanks
private
std::shared_ptr<Terrain> GameLogic::terrain
private
std::unique_ptr<Model> GameLogic::terrainModel
private
double GameLogic::turnTime
private
std::shared_ptr<Terrain> GameLogic::water
private
std::unique_ptr<Model> GameLogic::waterModel
private
std::unique_ptr<Texture> GameLogic::waterTexture
private

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