Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Classes | Public Member Functions | Public Attributes | Private Attributes | List of all members
Player Class Reference

Player state and animations. More...

#include <Player.hpp>

Classes

struct  PathPoint
 A sample along the snake path. More...
 

Public Member Functions

 Player ()
 
void update ()
 
bool physics (double fullTime, double frameTime)
 
void updateModels ()
 
bool alive () const
 
int score () const
 

Public Attributes

glm::mat4 modelHead = glm::mat4(1.0f)
 The snake head model matrix.
 
std::vector< glm::mat4 > modelsBody
 The snake body elements model matrices.
 
std::vector< glm::mat4 > modelsItem
 The edible items model matrices.
 
std::vector< int > looksBody
 The snake body elements material IDs.
 
std::vector< int > looksItem
 The edible items material IDs.
 

Private Attributes

glm::vec3 _momentum = glm::vec3(0.0f, 1.0f, 0.0f)
 The snake momentum.
 
glm::vec3 _position = glm::vec3(0.0f)
 The snake position.
 
float _angle = 0.0f
 The snake head orientation.
 
std::vector< glm::vec2 > _positions
 The snake body elements positions.
 
std::vector< float > _angles
 The snake body elements orientations.
 
std::vector< glm::vec2 > _items
 The items positions.
 
std::vector< PathPoint_path
 Ring buffer containing samples along the snake path.
 
unsigned int _currentSample = 0
 The current sample in the ring buffer.
 
unsigned int _currentFrame = 0
 Current frame (modulo sampling period).
 
double _lastSpawn = 0.0
 Time since the last item spawn.
 
float _invicibility = 0.0f
 Invicibility time buffer after boucning off a wall.
 
int _score = 0
 Player score.
 
bool _alive = true
 Player status.
 
const glm::vec3 _maxPos = glm::vec3(8.6f, 5.0f, 0.0f)
 Terrain bounding box.
 
const double _spawnPeriod = 1.5
 Time betweeen two item spawns.
 
const size_t _numSamplesPath = 512
 Size of the samples ring buffer.
 
const size_t _samplingPeriod = 15
 Frame count between two samples.
 
const float _radius = 0.5f
 Items and elements radius.
 
const float _headAccel = 4.0f
 Head speed.
 
const float _angleSpeed = 6.0f
 Head angular speed.
 
const float _minSamplingDistance = 0.02f
 Minimum distance between two samples.
 
const float _invicibilityIncrease = 0.5f
 Amount of time added to invicibility at each bounce.
 
const float _eatingDistance = 1.5f
 Distance below which an item can be eaten.
 
const float _minSpawnDistance = 3.0f
 Minimum distance with the snake head when spawning a new item.
 
const float _collisionDistance = 1.5f
 Distance below which a collision is registered.
 
const int _spawnTentatives = 50
 Ho many spawn attempts should be made at each spawn event.
 
const int _maxItems = 20
 Max number of items on the terrain.
 
const int _itemValue = 1
 Score gained when eating an item.
 

Detailed Description

Player state and animations.

Constructor & Destructor Documentation

◆ Player()

Player::Player ( )

Constructor

Member Function Documentation

◆ alive()

bool Player::alive ( ) const
inline

Status of the player.

Returns
true if the player is alive.

◆ physics()

bool Player::physics ( double  fullTime,
double  frameTime 
)

Update the physic state of the player snake and items

Parameters
fullTimetime elapsed since the beginning of the game
frameTimedelta time since last physics update
Returns
a boolean denoting if any item has been eaten.

◆ score()

int Player::score ( ) const
inline

Score of the player.

Returns
the score.

◆ update()

void Player::update ( )

Update logical state, once per frame

◆ updateModels()

void Player::updateModels ( )

Update the model matrices of all items This is so that we avoid updating them at each physics step.


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