ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Fire Class Reference

Fire Class Reference

Fire Class. More...

#include <Fire.h>

Public Member Functions

 Fire ()
 Constructor, non user specified.
 ~Fire ()
 Destructor, non user specified.
void init ()
 Initialises Fire object.
int * get_fire_sprite ()
 Gets the sprite.
int get_fire_x ()
 Gets the x coordinate.
void generate_fire ()
 Generates Fire parameters.

Detailed Description

Fire Class.

Generates a fire ball that will end the game if the skateboarder touches it

Author:
Lewis Wooltorton
Date:
April 2019
#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
#include "Fire.h"
#include <cstdlib>
#include <ctime>

N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad gamepad;
Fire _fire;

int _skater_y;
int _fire_y;

int main() {
  _fire.init();
  _fire_y = 20;
  while(1) {
    
    // Generates the x coordinate of the fire.
    _fire.generate_fire(); // Generates X coord of fire.
    // Y is calculated from parabolic relation to game counter.
    
    // Check for a collision.
    if (_skater_x == _fire.get_fire_x() 
      && _skater_y > _fire_y - 10 
      && _skater_y < _fire_y + 10
      ) {  // A range of Y coords to make collision 
    // more frequent.
    
    // Print fire.
    lcd.drawSprite(_fire.get_fire_x(),_fire_y,5,8,
                   (int*)_fire.get_fire_sprite());
    }
  }                 
} 

Definition at line 53 of file Fire.h.


Constructor & Destructor Documentation

Fire (  )

Constructor, non user specified.

Definition at line 21 of file Fire.cpp.

~Fire (  )

Destructor, non user specified.

Definition at line 23 of file Fire.cpp.


Member Function Documentation

void generate_fire (  )

Generates Fire parameters.

Increments Fire x coordinate and toggles fire sprite.

Definition at line 31 of file Fire.cpp.

int * get_fire_sprite (  )

Gets the sprite.

Returns:
The Fire sprite (an integer array)

Definition at line 40 of file Fire.cpp.

int get_fire_x (  )

Gets the x coordinate.

Returns:
The x coordinate of the Fire

Definition at line 49 of file Fire.cpp.

void init (  )

Initialises Fire object.

Definition at line 25 of file Fire.cpp.