ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19tb

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
el19tb
Date:
Sat May 23 03:53:33 2020 +0000
Parent:
46:e39abe665271
Child:
48:8ccfc74b60a5
Commit message:
added frog animation, frog states, and sprites

Changed in this revision

Frogger/Frogger.cpp Show annotated file Show diff for this revision Revisions of this file
Frogger/Frogger.h Show annotated file Show diff for this revision Revisions of this file
GraphicEngine/GraphicEngine.cpp Show annotated file Show diff for this revision Revisions of this file
GraphicEngine/GraphicEngine.h Show annotated file Show diff for this revision Revisions of this file
Sprite/Vehicle.h Show annotated file Show diff for this revision Revisions of this file
--- a/Frogger/Frogger.cpp	Sat May 23 02:55:16 2020 +0000
+++ b/Frogger/Frogger.cpp	Sat May 23 03:53:33 2020 +0000
@@ -18,6 +18,7 @@
     // screen sizes
     lcd_w = w; // width
     lcd_h = h; // height
+    state_frog = 0 ;
     
     // grid values
     grid = 4; // size of game grid system
@@ -92,10 +93,10 @@
         runCurrentLevel(); // add velocity to level vehicles and logs
 
         graphics.drawSafetyLanes();
-        graphics.showFrog(frog->x, frog->y, frog->width, frog->height); // display current position of frog
+        
+        graphics.showFrog(frog->x, frog->y, frog->width, frog->height, state_frog); // display current position of frog
         process_input(); // user controls the frog object   
         
-        //checkCurrentLevelCollision(); // check if the frog is alive
         checkFrogOnWater(); // check if the frog is in the water level
             
         graphics.refresh(); // refresh the lcd screen
@@ -104,24 +105,36 @@
     } 
 }
 
-void Frogger::process_input() {
+void Frogger::process_input() 
+{
     //determine the input 
-    /* make this a switch statement */
     if(gamepad.A_pressed()){
+        state_frog = 1;
         moveFrog(1,0);
         frogOnLog = false;
     } else if(gamepad.X_pressed()){
+        state_frog = 0;
         moveFrog(0,-1);
         frogOnLog = false;
     } else if(gamepad.B_pressed()){
+        state_frog = 3;
         moveFrog(0,1);
         frogOnLog = false;
     } else if(gamepad.Y_pressed()){
+        state_frog = 2;
         moveFrog(-1,0);
         frogOnLog = false;
     } 
 }
 
+void Frogger::drawFrogStates()
+{
+    //graphics.showFrog(frog->x, frog->y, frog->width, frog->height, state_frog); // display current position of frog
+    state_frog++;
+    graphics.showFrog(frog->x, frog->y, frog->width, frog->height, state_frog); // display current position of frog
+    state_frog--;
+}
+
 //moves the frog around the grid
 void Frogger::moveFrog(int xWay, int yWay)
 {
--- a/Frogger/Frogger.h	Sat May 23 02:55:16 2020 +0000
+++ b/Frogger/Frogger.h	Sat May 23 03:53:33 2020 +0000
@@ -31,6 +31,7 @@
         
     public:
         int current_level;
+        int state_frog;
         bool frogWater; 
         bool frogOnLog; // attached
         
@@ -94,7 +95,7 @@
         void moveLogsLevelOne();
 
         void moveLogsLevelTwo();
-
+        void drawFrogStates();
 
         void speedSlow();
         void speedMedium();
--- a/GraphicEngine/GraphicEngine.cpp	Sat May 23 02:55:16 2020 +0000
+++ b/GraphicEngine/GraphicEngine.cpp	Sat May 23 03:53:33 2020 +0000
@@ -82,9 +82,23 @@
 }
 
 /* TO-DO: ADD SPRITES AND SPRITE STATE */
-void GraphicEngine::showFrog(float x, int y, int width, int height)
+void GraphicEngine::showFrog(float x, int y, int width, int height, int state)
 {
-    lcd.drawRect(x, y, width, height, FILL_BLACK);
+    switch(state)
+    {
+        case 0:
+            lcd.drawSprite(x, y, 4, 6, (int *)frog_state_up);
+            break;
+        case 1: 
+            lcd.drawSprite(x, y, 4, 6, (int *)frog_state_left);
+            break;
+        case 2: 
+            lcd.drawSprite(x, y, 4, 6, (int *)frog_state_right);
+            break;
+        case 3: 
+            lcd.drawSprite(x, y, 4, 6, (int *)frog_state_down);
+            break;
+    }
 }
 
 void GraphicEngine::drawGoal(int x, int row)
--- a/GraphicEngine/GraphicEngine.h	Sat May 23 02:55:16 2020 +0000
+++ b/GraphicEngine/GraphicEngine.h	Sat May 23 03:53:33 2020 +0000
@@ -55,7 +55,7 @@
         void drawGoalPost();
 
         //draws the chicken to the LCD screen
-        void showFrog(float x, int y, int width, int height);
+        void showFrog(float x, int y, int width, int height, int state);
     
         void drawGoal(int x, int row);
         
--- a/Sprite/Vehicle.h	Sat May 23 02:55:16 2020 +0000
+++ b/Sprite/Vehicle.h	Sat May 23 03:53:33 2020 +0000
@@ -4,37 +4,43 @@
 // size of grid of the game
 // three states of the frog
 // still, movement 1 , movement two
-/*
-int frog_state_one[4][6] = {
 
-    //final and initial state of frog
-    { 0, 1, 0, 0, 1, 0 },
-    { 0, 1, 1, 1, 1, 0 },
-    { 0, 1, 1, 1, 1, 0 },
-    { 0, 1, 0, 0, 1, 0 },
-
+const int frog_state_up[4][6] = {
+  //final and initial state of frog
+  { 1, 0, 1, 1, 0, 1 },
+  { 0, 1, 1, 1, 1, 0 },
+  { 0, 1, 1, 1, 1, 0 },
+  { 1, 0, 0, 0, 0, 1 },
+    
 };
 
-int frog_state_two[4][6] = {
-
-    // second state of frog
-    { 0, 0, 0, 0, 0, 0 },
-    { 1, 1, 1, 1, 1, 1 },
-    { 1, 1, 1, 1, 1, 1 },
-    { 0, 0, 0, 0, 0, 0 },
-
+const int frog_state_left[4][6] = {
+        
+    // middle state of frog 
+    { 1, 1, 0, 0, 1, 0 },
+    { 0, 1, 1, 1, 1, 1 },
+    { 0, 1, 1, 1, 1, 1 },
+    { 1, 1, 0, 0, 1, 0 },
 };
 
-int frog_state_three[4][6] = {
+const int frog_state_right[4][6] = {
+        
+    // middle state of frog 
+    { 0, 1, 0, 0, 1, 1 },
+    { 1, 1, 1, 1, 1, 0 },
+    { 1, 1, 1, 1, 1, 0 },
+    { 0, 1, 0, 0, 1, 1 },
+};
 
-    // third state of frog 
+const int frog_state_down[4][6] = {
+        
+    // middle state of frog 
     { 1, 0, 0, 0, 0, 1 },
     { 0, 1, 1, 1, 1, 0 },
     { 0, 1, 1, 1, 1, 0 },
-    { 1, 0, 0, 0, 0, 1 },
+    { 1, 0, 1, 1, 0, 1 },
+};
 
-};
-*/
 
 // B
 const int bus[4][16] = {