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
Food/Food.cpp@9:f3259d652208, 2020-06-04 (annotated)
- Committer:
- el18lg
- Date:
- Thu Jun 04 18:47:58 2020 +0000
- Revision:
- 9:f3259d652208
- Parent:
- 7:24a3f13ce36d
Game complete;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el18lg | 6:266fb8fc17f4 | 1 | #include "Food.h" |
| el18lg | 9:f3259d652208 | 2 | // Constructor |
| el18lg | 9:f3259d652208 | 3 | Food::Food() |
| el18lg | 9:f3259d652208 | 4 | { |
| el18lg | 9:f3259d652208 | 5 | // Desturctor |
| el18lg | 9:f3259d652208 | 6 | } |
| el18lg | 9:f3259d652208 | 7 | Food::~Food() |
| el18lg | 9:f3259d652208 | 8 | { |
| el18lg | 9:f3259d652208 | 9 | |
| el18lg | 9:f3259d652208 | 10 | } |
| el18lg | 6:266fb8fc17f4 | 11 | |
| el18lg | 6:266fb8fc17f4 | 12 | void Food::init(){ |
| el18lg | 6:266fb8fc17f4 | 13 | srand(time(NULL)); |
| el18lg | 9:f3259d652208 | 14 | // Spawns food in a random position, making sure it appears inside my map |
| el18lg | 9:f3259d652208 | 15 | _foodx = (rand() % (WIDTH-3)+1); |
| el18lg | 9:f3259d652208 | 16 | _foody = (rand() % (HEIGHT-3)+1); |
| el18lg | 9:f3259d652208 | 17 | /*printf("food(x)=%d",_foodx); |
| el18lg | 9:f3259d652208 | 18 | printf("food(y)=%d",_foody); |
| el18lg | 9:f3259d652208 | 19 | */ |
| el18lg | 6:266fb8fc17f4 | 20 | } |
| el18lg | 6:266fb8fc17f4 | 21 | |
| el18lg | 9:f3259d652208 | 22 | void Food::draw(N5110 &lcd) |
| el18lg | 9:f3259d652208 | 23 | { |
| el18lg | 9:f3259d652208 | 24 | lcd.drawRect(_foodx, _foody, 2, 2, FILL_BLACK); // Draws food as a rectangle |
| el18lg | 9:f3259d652208 | 25 | } |
| el18lg | 6:266fb8fc17f4 | 26 | |
| el18lg | 9:f3259d652208 | 27 | Vector2D Food::get_pos() |
| el18lg | 6:266fb8fc17f4 | 28 | { |
| el18lg | 9:f3259d652208 | 29 | Vector2D f = {_foodx,_foody}; // Getting the position of the food |
| el18lg | 7:24a3f13ce36d | 30 | return f;} |
| el18lg | 7:24a3f13ce36d | 31 | |
| el18lg | 9:f3259d652208 | 32 | void Food::set_pos(Vector2D fp){ |
| el18lg | 7:24a3f13ce36d | 33 | _foodx = fp.x; |
| el18lg | 7:24a3f13ce36d | 34 | _foody = fp.y; |
| el18lg | 7:24a3f13ce36d | 35 | } |