library for SnekGame
Food.cpp@1:8d4639c9d1b0, 2017-05-05 (annotated)
- Committer:
- Nefos
- Date:
- Fri May 05 15:19:10 2017 +0000
- Revision:
- 1:8d4639c9d1b0
- Parent:
- 0:337503f9282c
Final code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nefos | 0:337503f9282c | 1 | #include "Food.h" |
Nefos | 0:337503f9282c | 2 | |
Nefos | 1:8d4639c9d1b0 | 3 | posXY food; |
Nefos | 0:337503f9282c | 4 | |
Nefos | 0:337503f9282c | 5 | |
Nefos | 0:337503f9282c | 6 | Food::Food(){ |
Nefos | 0:337503f9282c | 7 | |
Nefos | 1:8d4639c9d1b0 | 8 | } |
Nefos | 0:337503f9282c | 9 | |
Nefos | 0:337503f9282c | 10 | Food::~Food(){ |
Nefos | 0:337503f9282c | 11 | |
Nefos | 1:8d4639c9d1b0 | 12 | } |
Nefos | 0:337503f9282c | 13 | void Food::init(){ |
Nefos | 1:8d4639c9d1b0 | 14 | food.x=48;//set first food |
Nefos | 1:8d4639c9d1b0 | 15 | food.y=25; |
Nefos | 1:8d4639c9d1b0 | 16 | }//end of init |
Nefos | 0:337503f9282c | 17 | |
Nefos | 1:8d4639c9d1b0 | 18 | void Food::draw(N5110 &lcd){ |
Nefos | 0:337503f9282c | 19 | |
Nefos | 1:8d4639c9d1b0 | 20 | lcd.setPixel(food.x,food.y);//draw food |
Nefos | 1:8d4639c9d1b0 | 21 | |
Nefos | 1:8d4639c9d1b0 | 22 | }//end of draw |
Nefos | 0:337503f9282c | 23 | |
Nefos | 0:337503f9282c | 24 | void Food::respawn(){ |
Nefos | 1:8d4639c9d1b0 | 25 | |
Nefos | 1:8d4639c9d1b0 | 26 | srand(time(NULL));//randomly respawn food |
Nefos | 1:8d4639c9d1b0 | 27 | food.x=(rand()%81)+2; |
Nefos | 1:8d4639c9d1b0 | 28 | food.y=(rand()%27)+10; |
Nefos | 0:337503f9282c | 29 | |
Nefos | 1:8d4639c9d1b0 | 30 | }//end of respawn |
Nefos | 1:8d4639c9d1b0 | 31 | |
Nefos | 1:8d4639c9d1b0 | 32 | posXY Food::returnPos(){ |
Nefos | 0:337503f9282c | 33 | |
Nefos | 1:8d4639c9d1b0 | 34 | posXY p = { food.x, food.y}; |
Nefos | 1:8d4639c9d1b0 | 35 | return p; |
Nefos | 1:8d4639c9d1b0 | 36 | |
Nefos | 0:337503f9282c | 37 | } |