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.
Dependencies: mbed
Diff: CrossyChicken/CrossyChicken.cpp
- Revision:
- 18:6be4c3c94a3d
- Parent:
- 17:67dbdfcdcec2
- Child:
- 19:6d9721ffc078
--- a/CrossyChicken/CrossyChicken.cpp Thu May 14 01:07:27 2020 +0000
+++ b/CrossyChicken/CrossyChicken.cpp Thu May 14 03:53:16 2020 +0000
@@ -43,7 +43,8 @@
CrossyChicken::CrossyChicken(Level *level)
{
- this->local_level = level;
+ this->local_level = level;
+ grid = 22;
}
//main function that starts the game
@@ -206,30 +207,65 @@
}
}
-// every level is going to have the same
-void CrossyChicken::drawRoadBackground()
+
+
+
+
+
+void CrossyChicken::createMultipleRoadLane()
{
- int grid_screen_width = 22; // number of visible widths on width screen
+ int min = 0; // start from the top, and draw till 0
+ int max = grid_width; // draw 21 objects to the first lane
+ int row = 1;
- // 4 lanes of roads
- for(int i = 0; i < 4; i++){
- graphics.drawRoads(row_number);
- row_number++;
+ for(int x = 0; x < 4; x++){
+ createRoadLane(min, max, row);
+ row++; // increment the rows to the next lane
+ min += 22; // fill in the vector with 22 grid units
+ max += 22;
}
}
-
+
+// every level is going to have the same amount of blocks
+void CrossyChicken::createRoadLane(int min, int max, int row)
+{
+ std::vector<Background>::size_type it;
+
+ // fill the road objects
+ for(int it = min; it != max; it++){
+ roads.push_back(it/row, row); // it is the x pos of the obj, row is the y pos
+ }
+}
+
+void CrossyChicken::drawRoadObjects()
+{
+ graphics.getRoadObjects(roads);
+}
+
+void CrossyChicken::createTwoSafetyLanes()
+{
+ int min = 0;
+ int max = grid_width;
+ int row = 0; // first starting lane is at row 0
+
+ // there are going to be two lanes
+ for(int i = 0; i < 2; i++){
+ drawSafetyLanes(min+1, max+1, row);
+ }
+}
+
// we are going to have two safety lanes
-void CrossyChicken::drawSafetyLanes()
+void CrossyChicken::drawSafetyLanes(int min, int max, int row)
{
int state = 1;
+ SafetyLane lane;
- for(int x = 0; x < 22; x++){
- // fsm for drawing safety lane background
+ for(int z = 0; z < 22; z++){
switch(state)
{
case 1:
- graphics.drawFirstSafetyBackground(x, 0); // safety lane so row 0
- graphics.drawFirstSafetyBackground(x, 6); // middle lane so row 6
+ safety_lane.push_back(std::tr1::make_shared<Background>(z, row)); // safety lane so row 0
+ safety_lane.push_back(std::tr1::make_shared<SafetyLane>('K')); // safety lane so row 0
state++;
break;
case 2:
@@ -242,7 +278,7 @@
}
// the water sprites are going to 'move' to make it realistic
-void CrossyChicken::createWater(){
+void CrossyChicken::createWater(int row, float speed){
int state = 1;
for(it = 0; it != 21; it++)
@@ -251,26 +287,27 @@
switch(state)
{
case 1: // initial state
- row_water_one[it].push_back('F'); // first type of water
+ row_water_one[it].push_back('F', row, speed, it); // first type of water
state++; // transition to next state
break;
case 2:
- row_water_one[it].push_back('S'); // second type of water
+ row_water_one[it].push_back('S', row, speed, it); // second type of water
state++; // transition to state 3
- break;
-
+ break;
case 3:
- row_water_one[it].push_back('T'); // third type of water
+ row_water_one[it].push_back('T', row, speed, it); // third type of water
state = 1; // back to start state
break;
}
}
}
-void CrossyChicken::moveWater()
+void CrossyChicken::moveWater(Water *water, int dir)
{
+ switch(dir)
+ case 1:
for(it = 0; it != row_water_one.size(); it++){
- graphics.moveWaterWithSpeed(&row_water_one[it]);
+
}
}