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.
Health_Kit/Health_Kit.cpp@3:aa82968b7a8e, 2019-04-25 (annotated)
- Committer:
- ll16o2l
- Date:
- Thu Apr 25 15:08:52 2019 +0000
- Revision:
- 3:aa82968b7a8e
- Child:
- 15:807eba7c7811
Completed Dodge game
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ll16o2l | 3:aa82968b7a8e | 1 | #include "Health_Kit.h" |
ll16o2l | 3:aa82968b7a8e | 2 | |
ll16o2l | 3:aa82968b7a8e | 3 | // nothing doing in the constructor and destructor |
ll16o2l | 3:aa82968b7a8e | 4 | Health_Kit::Health_Kit() |
ll16o2l | 3:aa82968b7a8e | 5 | { |
ll16o2l | 3:aa82968b7a8e | 6 | |
ll16o2l | 3:aa82968b7a8e | 7 | } |
ll16o2l | 3:aa82968b7a8e | 8 | |
ll16o2l | 3:aa82968b7a8e | 9 | Health_Kit::~Health_Kit() |
ll16o2l | 3:aa82968b7a8e | 10 | { |
ll16o2l | 3:aa82968b7a8e | 11 | |
ll16o2l | 3:aa82968b7a8e | 12 | } |
ll16o2l | 3:aa82968b7a8e | 13 | |
ll16o2l | 3:aa82968b7a8e | 14 | /** |
ll16o2l | 3:aa82968b7a8e | 15 | * This method will be used to initialise the health_kit variables. |
ll16o2l | 3:aa82968b7a8e | 16 | * Saves global variables to local variables. |
ll16o2l | 3:aa82968b7a8e | 17 | * @author Oliver Luong |
ll16o2l | 3:aa82968b7a8e | 18 | * @param kit_size |
ll16o2l | 3:aa82968b7a8e | 19 | * @date 22/04/2019 |
ll16o2l | 3:aa82968b7a8e | 20 | */ |
ll16o2l | 3:aa82968b7a8e | 21 | void Health_Kit::init(int kit_size){ |
ll16o2l | 3:aa82968b7a8e | 22 | _kit_size = kit_size; |
ll16o2l | 3:aa82968b7a8e | 23 | _x_edge = WIDTH - _kit_size/2; // Edge of horizontal |
ll16o2l | 3:aa82968b7a8e | 24 | _y_edge = HEIGHT - _kit_size/2; // Edge of vertical |
ll16o2l | 3:aa82968b7a8e | 25 | |
ll16o2l | 3:aa82968b7a8e | 26 | |
ll16o2l | 3:aa82968b7a8e | 27 | _x = rand() % _x_edge; // Generate random position on the screen - 0 to the edge |
ll16o2l | 3:aa82968b7a8e | 28 | _y = rand() % _y_edge; // Generate random position on the screen - 0 to the edge |
ll16o2l | 3:aa82968b7a8e | 29 | } |
ll16o2l | 3:aa82968b7a8e | 30 | |
ll16o2l | 3:aa82968b7a8e | 31 | /** |
ll16o2l | 3:aa82968b7a8e | 32 | * This method will be used to store the sprite for health_kit and draw it |
ll16o2l | 3:aa82968b7a8e | 33 | * onto the LCD. |
ll16o2l | 3:aa82968b7a8e | 34 | * @author Oliver Luong |
ll16o2l | 3:aa82968b7a8e | 35 | * @date 22/04/2019 |
ll16o2l | 3:aa82968b7a8e | 36 | */ |
ll16o2l | 3:aa82968b7a8e | 37 | void Health_Kit::draw(N5110 &lcd) |
ll16o2l | 3:aa82968b7a8e | 38 | { |
ll16o2l | 3:aa82968b7a8e | 39 | int Health_Kit_sprite[7][7] = { |
ll16o2l | 3:aa82968b7a8e | 40 | {1,1,1,1,1,1,1}, |
ll16o2l | 3:aa82968b7a8e | 41 | {1,0,0,0,0,0,1}, |
ll16o2l | 3:aa82968b7a8e | 42 | {1,0,0,1,0,0,1}, |
ll16o2l | 3:aa82968b7a8e | 43 | {1,0,1,1,1,0,1}, |
ll16o2l | 3:aa82968b7a8e | 44 | {1,0,0,1,0,0,1}, |
ll16o2l | 3:aa82968b7a8e | 45 | {1,0,0,0,0,0,1}, |
ll16o2l | 3:aa82968b7a8e | 46 | {1,1,1,1,1,1,1}, |
ll16o2l | 3:aa82968b7a8e | 47 | }; |
ll16o2l | 3:aa82968b7a8e | 48 | |
ll16o2l | 3:aa82968b7a8e | 49 | lcd.drawSprite(_x,_y,7,7,(int*)Health_Kit_sprite); // x,y,radius,black fill |
ll16o2l | 3:aa82968b7a8e | 50 | } |
ll16o2l | 3:aa82968b7a8e | 51 | |
ll16o2l | 3:aa82968b7a8e | 52 | /** |
ll16o2l | 3:aa82968b7a8e | 53 | * This method will be used to return the postion of the health_kit when called. |
ll16o2l | 3:aa82968b7a8e | 54 | * @author Oliver Luong |
ll16o2l | 3:aa82968b7a8e | 55 | * @date 22/04/2019 |
ll16o2l | 3:aa82968b7a8e | 56 | */ |
ll16o2l | 3:aa82968b7a8e | 57 | Vector2D Health_Kit::get_pos() |
ll16o2l | 3:aa82968b7a8e | 58 | { |
ll16o2l | 3:aa82968b7a8e | 59 | Vector2D p = {_x,_y}; |
ll16o2l | 3:aa82968b7a8e | 60 | return p; |
ll16o2l | 3:aa82968b7a8e | 61 | } |