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.
RandomMovement/RandomMovement.h@35:577c65bf914e, 2020-05-15 (annotated)
- Committer:
- evanso
- Date:
- Fri May 15 14:19:54 2020 +0000
- Revision:
- 35:577c65bf914e
- Parent:
- 34:85ccc16f24d2
Moved check_alien_collision and check_collision into sperate parent classes as code was being written twice.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| evanso | 28:a5958497d5ce | 1 | #ifndef RANDOMMOVEMENT_H |
| evanso | 28:a5958497d5ce | 2 | #define RANDOMMOVEMENT_H |
| evanso | 28:a5958497d5ce | 3 | |
| evanso | 28:a5958497d5ce | 4 | // Included libraries ---------------------------------------------------------- |
| evanso | 28:a5958497d5ce | 5 | #include "mbed.h" |
| evanso | 28:a5958497d5ce | 6 | #include "Position.h" |
| evanso | 28:a5958497d5ce | 7 | |
| evanso | 28:a5958497d5ce | 8 | /** Random Movement class |
| evanso | 28:a5958497d5ce | 9 | * @brief Random Movement perant class |
| evanso | 28:a5958497d5ce | 10 | * @author Benjamin Evans, University of Leeds |
| evanso | 28:a5958497d5ce | 11 | * @date May 2020 |
| evanso | 28:a5958497d5ce | 12 | */ |
| evanso | 35:577c65bf914e | 13 | class RandomMovement: virtual public Position{ |
| evanso | 28:a5958497d5ce | 14 | protected: |
| evanso | 28:a5958497d5ce | 15 | // Function prototypes ----------------------------------------------------- |
| evanso | 28:a5958497d5ce | 16 | |
| evanso | 28:a5958497d5ce | 17 | /** Changes the x and y positions of the sprite bject depeding on the |
| evanso | 28:a5958497d5ce | 18 | * movement direction |
| evanso | 28:a5958497d5ce | 19 | * @param x_change @details number to change sprite x position by |
| evanso | 28:a5958497d5ce | 20 | * @param y_change @detials number to change sprite y position by |
| evanso | 28:a5958497d5ce | 21 | */ |
| evanso | 28:a5958497d5ce | 22 | void set_sprite_direction(int x_change,int y_change); |
| evanso | 28:a5958497d5ce | 23 | |
| evanso | 28:a5958497d5ce | 24 | /** Generates the random move dirction and length for the sprite */ |
| evanso | 28:a5958497d5ce | 25 | void set_random_move(); |
| evanso | 28:a5958497d5ce | 26 | |
| evanso | 28:a5958497d5ce | 27 | /** Gets the movement direction of the sprite */ |
| evanso | 28:a5958497d5ce | 28 | void move_direction(); |
| evanso | 28:a5958497d5ce | 29 | |
| evanso | 34:85ccc16f24d2 | 30 | /** Calulates the sprite movement depeding on spaceship positions and |
| evanso | 34:85ccc16f24d2 | 31 | * joystick input |
| evanso | 34:85ccc16f24d2 | 32 | * @param d_ @details : Direction object of joystick |
| evanso | 34:85ccc16f24d2 | 33 | * @retrun integer @details move alien value for alien draw function |
| evanso | 34:85ccc16f24d2 | 34 | */ |
| evanso | 34:85ccc16f24d2 | 35 | int calc_sprite_movement(Direction d_); |
| evanso | 34:85ccc16f24d2 | 36 | |
| evanso | 28:a5958497d5ce | 37 | // Variables --------------------------------------------------------------- |
| evanso | 28:a5958497d5ce | 38 | |
| evanso | 28:a5958497d5ce | 39 | /** Sprite random move counter */ |
| evanso | 28:a5958497d5ce | 40 | int random_move_counter_; |
| evanso | 28:a5958497d5ce | 41 | |
| evanso | 28:a5958497d5ce | 42 | /** Random direction variable */ |
| evanso | 28:a5958497d5ce | 43 | int random_direction_; |
| evanso | 28:a5958497d5ce | 44 | }; |
| evanso | 28:a5958497d5ce | 45 | |
| evanso | 28:a5958497d5ce | 46 | #endif |