Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Sprites Class Reference
#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
- 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:
-
d direction so player can turn around if collision with block. i index so collision rules between blocks dont clash, will always be numbered 0 - 4. x block position. y block 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:
-
i index 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:
-
i index these will always be 0, 1, 2 so each enemy is treated individually. x position. y position. distance in 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:
-
i index these will always be 0 - 2 so each enemy is treated individually. velocity how 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:
-
x exit position. y exit 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.
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:
-
k index so each key is treated independently x key position. y key 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:
-
x miner position. y miner position.
Definition at line 12 of file Sprites.cpp.
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:
-
d Direction 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:
-
x1 sinking block starting position. y sinking block position. x2 Sinking 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:
-
x trap position. y trap 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.
Generated on Wed Jul 13 2022 01:25:32 by
1.7.2