library for SnekGame

Dependents:   2645Game_el15bb

Files at this revision

API Documentation at this revision

Comitter:
Nefos
Date:
Fri May 05 15:19:10 2017 +0000
Parent:
0:337503f9282c
Commit message:
Final code

Changed in this revision

Food.cpp Show annotated file Show diff for this revision Revisions of this file
Food.h Show annotated file Show diff for this revision Revisions of this file
--- a/Food.cpp	Fri May 05 11:55:49 2017 +0000
+++ b/Food.cpp	Fri May 05 15:19:10 2017 +0000
@@ -1,40 +1,37 @@
 #include "Food.h"
 
-//posXY food;
+posXY food;
 
 
 Food::Food(){
     
-    
-    
-    
-    }
+}
     
 Food::~Food(){
     
-    
-    
-    
-    
-    }
+}
 void Food::init(){
-        
-        
-
-
-
-
-    }
+        food.x=48;//set first food
+        food.y=25;
+}//end of init
     
-void Food::draw(){
-    
+void Food::draw(N5110 &lcd){
     
-    
-    
-    }
+        lcd.setPixel(food.x,food.y);//draw food
+            
+}//end of draw
     
 void Food::respawn(){
-    
+        
+        srand(time(NULL));//randomly respawn food
+        food.x=(rand()%81)+2;
+        food.y=(rand()%27)+10;
     
+}//end of respawn
+
+posXY Food::returnPos(){
     
+        posXY p = { food.x, food.y};
+        return p;   
+        
 }
\ No newline at end of file
--- a/Food.h	Fri May 05 11:55:49 2017 +0000
+++ b/Food.h	Fri May 05 15:19:10 2017 +0000
@@ -6,36 +6,30 @@
 #include "N5110.h"
 #include "Gamepad.h"
 //#include "Snake.h"
+
+/************************Structs************************/
 struct posXY{
     int x;
     int y;
     
     };
-class Food
-{
+/************************Class Def************************/   
+class Food{
     
     
-    
+/************************Public Vars************************/  
     public:
     
-    Food();
-    ~Food();
-    void init();
-    void draw();
-    void respawn();
+            Food();
+            ~Food();
+            void init();
+            void draw(N5110 &lcd);
+            void respawn();
+            posXY returnPos();
     
-    
+/************************Private Vars************************/      
     private:    
     
     
-    
-    
 };
-
-
-
-
-
-
-
 #endif
\ No newline at end of file