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
Diff: Sprites/Sprites.h
- Revision:
- 53:082c22ac2f9a
- Parent:
- 52:715791fc08a1
- Child:
- 54:7fa8c07fdea4
diff -r 715791fc08a1 -r 082c22ac2f9a Sprites/Sprites.h --- a/Sprites/Sprites.h Wed Apr 24 18:05:56 2019 +0000 +++ b/Sprites/Sprites.h Wed Apr 24 19:33:39 2019 +0000 @@ -154,49 +154,115 @@ { public: - /** constructor + /** Constructor */ Sprites(); - /** deconstructor - */ + /** Deconstructor + */ ~Sprites(); - /** gets x and y position of player - */ + /** Gets x and y position of player. + */ Vector2D get_pos(); - /** States starting position of player - @param miner x position - @param miner y position - */ + /** States starting position of player. + @param miner x position. + @param miner y position. + */ void miner_init(int x, int y); + /** Updates player x position. + @details 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. + @param Direction enum from Gamepad library. + */ void miner_move(Direction d, N5110 &lcd); + /** Draws sprite facing direction moving. + @details _direction states if player left or right facing, function draws + * left or right facing sprite according. + */ void miner_draw(N5110 &lcd); + /** States when player is on a platform. + @details 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. + */ + void miner_land(N5110 &lcd); + /** Contains jump conditions and updates player position while jumping. + @details 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. + */ + void miner_jump(N5110 &lcd, Gamepad &pad); + /** Player falls if not on platform. + */ void miner_gravity(N5110 &lcd); - void miner_jump(N5110 &lcd, Gamepad &pad); - void miner_land(N5110 &lcd); - + /** initialises enemies + @param enemy index, these will always be 0, 1, 2 so each enemy is treated individually. + @param enemy x position. + @param enemy y position. + @param distance in pixels enemy to travel. + */ void enemy_init(int i, int x, int y, int d); + /** Updates enemy movement. + @param enemy index, these will always be 0, 1, 2 so each enemy is treated individually. + @param stets how many pixels enemies will move each loop. + */ void enemy_move(int i, double v, N5110 &lcd); + /** States conditions for collision between enemy and player. + @details uses get_pos() and detects if any overlap between player and enemies. + @param enemy index, these will always be 0, 1, 2 so each enemy is treated individually. + @return will return true if collision detected. + */ bool enemy_collision(int i); - + /** States conditions for drawing and collection of keys. + @details Each key is displayed while key flag is false, once collected, key is deleted + * and flag is changed to true. + @param each key indexed so they are treated independently. + @param keys x position. + @param keys y position. + */ void key_collect(int k, int x, int y, N5110 &lcd, Gamepad &pad); + /** Counts keys collected. + @return number of keys collected. + */ int keys_collected(); - + /** Draws level exit and detects player collision + @details takes player position from get_pos() and detects if overlap between + player and the exit sprite. + @param Exit x position. + @param Exit y position. + */ + bool exit_level(int x, int y, N5110 &lcd); + /** Draws traps and detects player collision + @details takes player position from get_pos() and detects if overlap between + player and the trap sprite. + @param Trap x position. + @param Trap y position. + */ bool trap(int x, int y, N5110 &lcd); + /** Draws blocks and detects player collision. + @param Direction needed so player can turn around if collision with block. + @Param each block indexed so collision rules between blocks dont clash. + @param Block x position. + @param Block y position. + */ void blocks(Direction d, int i, int x, int y, N5110 &lcd); + /** Checks if player has collided with any blocks. + @return If player is contact with any block returns true. + */ bool block_collision(); + /** Draws sinking blocks and detects player contact. + @param Sinking block x starting position. + @param Block y position. + @param Sinking block x finish position. + */ void soft_blocks(int x, int y, int z, N5110 &lcd); - bool exit_level(int x, int y, N5110 &lcd); - Key_init _k; - Enemies_init _enem; - - private: int _direction; - int _gravity; + bool _gravity; bool _jump; int _y; int _x; @@ -210,7 +276,7 @@ bool _collision; int _keys; - + Enemies_init _enem; Solid_blocks_init _b; };