ELEC2645 (2018/19) / Mbed 2 deprecated el17arm

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Sprites Class Reference

Sprites Class Reference

Sprites Class. More...

#include <Sprites.h>

Public Member Functions

 Sprites ()
 Constructor.
 ~Sprites ()
 Deconstructor.
Vector2D get_pos ()
 Gets x and y position of player.
void miner_init (int x, int y)
 States starting position of player.
void miner_move (Direction d, N5110 &lcd)
 Updates player x position.
void miner_draw (N5110 &lcd)
 Draws sprite facing direction moving.
void miner_land (N5110 &lcd)
 States when player is on a platform.
void miner_jump (N5110 &lcd, Gamepad &pad)
 Contains jump conditions and updates player position while jumping.
void miner_gravity (N5110 &lcd)
 Player falls if not on platform.
void enemy_init (int i, int x, int y, int d)
 initialises enemies
void enemy_move (int i, double v, N5110 &lcd)
 Updates enemy movement.
bool enemy_collision (int i)
 States conditions for collision between enemy and player.
void key_collect (int k, int x, int y, N5110 &lcd, Gamepad &pad)
 States conditions for drawing and collection of keys.
int keys_collected ()
 Counts keys collected.
void zero_keys ()
 makes _keys zero
bool exit_level (int x, int y, N5110 &lcd)
 Draws level exit and detects player collision.
bool trap (int x, int y, N5110 &lcd)
 Draws traps and detects player collision.
void blocks (Direction d, int i, int x, int y, N5110 &lcd)
 Draws blocks and detects player collision.
bool block_collision ()
 Checks if player has collided with any blocks.
void soft_blocks (int x1, int y, int x2, N5110 &lcd)
 Draws sinking blocks and detects player contact.

Detailed Description

Sprites Class.

Draws sprites and sets all collision rules

Author:
Andrew Milner University of Leeds
Date:
April 2019

Definition at line 92 of file Sprites.h.


Constructor & Destructor Documentation

Sprites (  )

Constructor.

Definition at line 3 of file Sprites.cpp.

~Sprites (  )

Deconstructor.

Definition at line 8 of file Sprites.cpp.


Member Function Documentation

bool block_collision (  )

Checks if player has collided with any blocks.

Returns:
if player is contact with any block returns true.

Definition at line 232 of file Sprites.cpp.

void blocks ( Direction  d,
int  i,
int  x,
int  y,
N5110 lcd 
)

Draws blocks and detects player collision.

Parameters:
ddirection so player can turn around if collision with block. i index so collision rules between blocks dont clash, will always be numbered 0 - 4.
xblock position.
yblock position.

Definition at line 205 of file Sprites.cpp.

bool enemy_collision ( int  i )

States conditions for collision between enemy and player.

uses get_pos() and detects if any overlap between player and enemies.

Parameters:
iindex these will always be 0, 1, 2 so each enemy is treated individually.
Returns:
will return true if collision detected.

Definition at line 130 of file Sprites.cpp.

void enemy_init ( int  i,
int  x,
int  y,
int  d 
)

initialises enemies

Parameters:
iindex these will always be 0, 1, 2 so each enemy is treated individually.
xposition.
yposition.
distancein pixels enemy to travel.

Definition at line 100 of file Sprites.cpp.

void enemy_move ( int  i,
double  v,
N5110 lcd 
)

Updates enemy movement.

Parameters:
iindex these will always be 0 - 2 so each enemy is treated individually.
velocityhow many pixels enemies will move each loop.

Definition at line 110 of file Sprites.cpp.

bool exit_level ( int  x,
int  y,
N5110 lcd 
)

Draws level exit and detects player collision.

takes player position from get_pos() and detects if overlap between player and the exit sprite.

Parameters:
xexit position.
yexit position.

Definition at line 179 of file Sprites.cpp.

Vector2D get_pos (  )

Gets x and y position of player.

Definition at line 20 of file Sprites.cpp.

void key_collect ( int  k,
int  x,
int  y,
N5110 lcd,
Gamepad pad 
)

States conditions for drawing and collection of keys.

Each key is displayed while key flag is false, once collected, key is deleted and flag is changed to true.

Parameters:
kindex so each key is treated independently
xkey position.
ykey position.

Definition at line 146 of file Sprites.cpp.

int keys_collected (  )

Counts keys collected.

Returns:
number of keys collected.

Definition at line 167 of file Sprites.cpp.

void miner_draw ( N5110 lcd )

Draws sprite facing direction moving.

_direction states if player left or right facing, function draws left or right facing sprite according.

Definition at line 49 of file Sprites.cpp.

void miner_gravity ( N5110 lcd )

Player falls if not on platform.

Definition at line 91 of file Sprites.cpp.

void miner_init ( int  x,
int  y 
)

States starting position of player.

Parameters:
xminer position.
yminer position.

Definition at line 12 of file Sprites.cpp.

void miner_jump ( N5110 lcd,
Gamepad pad 
)

Contains jump conditions and updates player position while jumping.

When A button pressed players y position increases until preset value is reached. Jump flag is true while player y is increasing and false all other times, this prevents double jumping.

Definition at line 69 of file Sprites.cpp.

void miner_land ( N5110 lcd )

States when player is on a platform.

if _jump true then player can jump, this prevents mid-air jumping. Also states conditions for gravity so player will fall unless on top of a platform.

Definition at line 60 of file Sprites.cpp.

void miner_move ( Direction  d,
N5110 lcd 
)

Updates player x position.

Updates x positon depending on direction of joystick. Will only update position if no collision detected. Function also stops player leaving screen at the left and right sides of screen.

Parameters:
dDirection enum from Gamepad library.

Definition at line 29 of file Sprites.cpp.

void soft_blocks ( int  x1,
int  y,
int  x2,
N5110 lcd 
)

Draws sinking blocks and detects player contact.

Parameters:
x1sinking block starting position.
ysinking block position.
x2Sinking block finish position.

Definition at line 241 of file Sprites.cpp.

bool trap ( int  x,
int  y,
N5110 lcd 
)

Draws traps and detects player collision.

takes player position from get_pos() and detects if overlap between player and the trap sprite.

Parameters:
xtrap position.
ytrap position.

Definition at line 192 of file Sprites.cpp.

void zero_keys (  )

makes _keys zero

When game over occurs keys need to be reset to zero

Definition at line 174 of file Sprites.cpp.