Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
51:387249f9b333
Parent:
41:4edac50f010d
Child:
56:142e9fdb77a8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GameObjects/SnakeFood/SnakeFood.cpp	Fri Apr 26 18:30:25 2019 +0000
@@ -0,0 +1,77 @@
+#include "SnakeFood.h"
+
+SnakeFood::SnakeFood()
+{
+
+}
+
+SnakeFood::~SnakeFood()
+{
+
+}
+
+//SnakeFood Sprite.
+int food_sprite[3][3] = {
+    {0,1,0},
+    {1,0,1},
+    {0,1,0},
+    };
+    
+void SnakeFood::init() //Delete Int
+{
+    n = 0;
+}
+
+
+void SnakeFood::draw(N5110 &lcd, int blockbuff)
+{   
+
+    velocity.x = 0;
+    velocity.y = 1;
+    _blockbuff = blockbuff;
+    
+    //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(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 >= -11)))  { //this makes sure that the snake food only appears when the block doesn't cover it.
+            n = n+1;  
+        }
+    }
+
+    lcd.drawSprite(_fx,_fy,3,3,(int *)food_sprite); //Function to draw the sprite.
+}
+
+
+
+Vector2D SnakeFood::get_pos() //Obtains the X and Y coordinate of the target.
+{
+    Vector2D snakefoodpos = {_fx,_fy};
+    //printf("snakefoodpos from food = %f %f \n", snakefoodpos.x, snakefoodpos.y);
+    return snakefoodpos;
+}
+
+
+
+
+void SnakeFood::update()
+{
+    _fx += velocity.x;
+    _fy += velocity.y;
+}
+
+
+void SnakeFood::set_pos(Vector2D p)
+{
+    _fx = p.x;
+    _fy = p.y;
+    if(((_blockbuff <= 11)&&(_blockbuff >= -11))&&_fy == -3)  { //this makes sure that the snake food only appears when the block doesn't cover it.
+        n = 0;  
+    }
+}