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.
Diff: SnakeFood/SnakeFood.cpp
- Revision:
- 36:dfdd619874ae
- Parent:
- 33:249cf423fb18
- Child:
- 38:30e4e6191762
--- a/SnakeFood/SnakeFood.cpp Wed Apr 17 09:15:43 2019 +0000
+++ b/SnakeFood/SnakeFood.cpp Thu Apr 18 06:19:33 2019 +0000
@@ -24,34 +24,26 @@
}
-void SnakeFood::draw(N5110 &lcd, int blockgap, int blockbuff)
+void SnakeFood::draw(N5110 &lcd, int blockbuff)
{
- //_velocity.x = 1;
+ _velocity.x = 0;
_velocity.y = 1;
//add sideways velocity incase I want to make it dodgy.
//Resets SnakeFood position if it reaches the bottom of the screen.
//Also prevents SnakeFood from going out of the side of the screen.
- if(_fx < 0){
- _fx = 0;
- }
- if(_fx > 81){
- _fx = 81;
- }
- if(_fy >= 48){
- n = 0;
+ if(_fx < 0) {_fx = 0;}
+ if(_fx > 81) {_fx = 81;}
+ if(_fy >= 48) {n = 0;}
+ if(n == 0){
+ _fx = (rand() % 82); //this makes the food pop up at a random, unspecified location in the x axis.
+ _fy = -3;
+ if(!((blockbuff >= 11)&&(blockbuff <= 2))) { //this makes sure that the snake food only appears when the block doesn't cover it.
+ n = n+1;
}
-
- if(n == 0){
- _fx = (rand() % 82); //change the number here so that there is always an unsurity(a little) if the food will come or not(change the limits for this)
- _fy = -2;
- if(blockbuff >= (blockgap - 5)) { //this makes sure that the snake food appears seperated from the block
- _fy = -15;
- }
- n = n+1;
- }
+ }
lcd.drawSprite(_fx,_fy,3,3,(int *)food_sprite); //Function to draw the sprite.
}
@@ -70,15 +62,8 @@
void SnakeFood::update()
{
- if(fooddrop == 0) {
- _fx += _velocity.x;
- _fy += _velocity.y;
- }
- fooddrop += 1;
-
- if(fooddrop == 1) { //make this a variable multiple of game speed
- fooddrop = 0;
- }
+ _fx += _velocity.x;
+ _fy += _velocity.y;
}