ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Engine Class Reference

Engine Class Reference

Engine Class. More...

#include <Engine.h>

Public Member Functions

 Engine ()
 Constructor.
 ~Engine ()
 Destructor.
void init ()
 Initalises the Game Engine object.
void read_input (Gamepad &gamepad)
 Sets the input variables.
void set_level_condition ()
 Sets the level condition of the Skateboarder.
bool get_start_platform_flag ()
 Gets the start platform flag.
int get_player_score ()
 Gets the player score.
void process_y (Gamepad &gamepad)
 Processes y coordinate of the Skateboarder.
void process_x (int game_counter)
 Processes x coordinate of the Skateboarder.
void process_sprite ()
 Processes the Skateboarder sprite.
void update_lcd (N5110 &lcd, int game_counter)
 Updates the LCD display.
void generate_level (int game_counter)
 Generates components of the level: fire, platforms, coin and background.
void check_reset (N5110 &lcd, Gamepad &gamepad)
 Checks if the game needs to be reset and resets if it does.
void check_coin_collision (Gamepad &gamepad)
 Checks if the Skateboarder has collected a coin and increments player score if it has.
void check_fire_collision (Gamepad &gamepad, int game_counter)
 Checks if the Skateboarder has touched the fire and initiates reset if it has.

Detailed Description

Engine Class.

Handles the game mechanics in a game engine: reads inputs, updates game and LCD

Author:
Lewis Wooltorton
Date:
March 2019
#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
#include "Engine.h"

N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad gamepad;
Engine _game_engine;

int _game_counter;
bool _start_platform_flag;
int _speed_divider;
int _player_score;

int main() {
  _game_engine.init();
  while(1) {
    
    // Run all reset checks.
    _game_engine.check_reset(lcd, gamepad);  // Resets the game if skater has 
    // died.
    _start_platform_flag = _game_engine.get_start_platform_flag();
    if (_game_counter == 100) _game_counter = 0;  // Count from 0 to 99.
    
    // Run the engine.
    _game_engine.read_input(gamepad);
    _game_engine.set_level_condition();  // Determines if the skater is under 
    // upper platforms.
    _game_engine.process_y(gamepad);
    _game_engine.process_x(_game_counter);
    _game_engine.process_sprite();
    _game_engine.check_coin_collision(gamepad);
    _game_engine.check_fire_collision(gamepad, _game_counter);
    _game_engine.update_lcd(lcd, _game_counter);
    
    // Update the game counter and player score.
    if (_game_counter % _speed_divider == 0) 
    _game_engine.generate_level(_game_counter);  // Level speed is determined by 
    // speed divider.
    _game_counter++;
    _player_score = _game_engine.get_player_score();
    _speed_divider = int(-0.25*_player_score + 10);  // Speed divider is 
    // dependent on how many coins you have
  }
}

Definition at line 76 of file Engine.h.


Constructor & Destructor Documentation

Engine (  )

Constructor.

Non user specified.

Definition at line 11 of file Engine.cpp.

~Engine (  )

Destructor.

Non user specified.

Definition at line 13 of file Engine.cpp.


Member Function Documentation

void check_coin_collision ( Gamepad gamepad )

Checks if the Skateboarder has collected a coin and increments player score if it has.

Parameters:
&gamepadThe gamepad object from Gamepad class

Definition at line 263 of file Engine.cpp.

void check_fire_collision ( Gamepad gamepad,
int  game_counter 
)

Checks if the Skateboarder has touched the fire and initiates reset if it has.

Parameters:
&gamepadThe gamepad object from Gamepad class
game_counterA counter that increments every loop iteration from 0 to 99

Definition at line 278 of file Engine.cpp.

void check_reset ( N5110 lcd,
Gamepad gamepad 
)

Checks if the game needs to be reset and resets if it does.

Parameters:
&lcdThe lcd object from the N5110 class
&gamepadThe gamepad object from Gamepad class

Definition at line 22 of file Engine.cpp.

void generate_level ( int  game_counter )

Generates components of the level: fire, platforms, coin and background.

Parameters:
game_counterA counter that increments every loop iteration from 0 to 99

Definition at line 165 of file Engine.cpp.

int get_player_score (  )

Gets the player score.

Returns:
The amount of coins the player has collected

Definition at line 303 of file Engine.cpp.

bool get_start_platform_flag (  )

Gets the start platform flag.

Returns:
The start platform flag for printing the start platform sprites

Definition at line 257 of file Engine.cpp.

void init (  )

Initalises the Game Engine object.

Definition at line 15 of file Engine.cpp.

void process_sprite (  )

Processes the Skateboarder sprite.

Definition at line 137 of file Engine.cpp.

void process_x ( int  game_counter )

Processes x coordinate of the Skateboarder.

Parameters:
game_counterA counter that increments every loop iteration from 0 to 99

Definition at line 120 of file Engine.cpp.

void process_y ( Gamepad gamepad )

Processes y coordinate of the Skateboarder.

Parameters:
&gamepadThe gamepad object from Gamepad class

Definition at line 84 of file Engine.cpp.

void read_input ( Gamepad gamepad )

Sets the input variables.

Parameters:
&gamepad*

The gamepad object from Gamepad class

Definition at line 78 of file Engine.cpp.

void set_level_condition (  )

Sets the level condition of the Skateboarder.

Definition at line 144 of file Engine.cpp.

void update_lcd ( N5110 lcd,
int  game_counter 
)

Updates the LCD display.

Parameters:
&lcdThe lcd object from the N5110 class
game_counterA counter that increments every loop iteration from 0 to 99

Definition at line 232 of file Engine.cpp.