iFitQuest to Android: Stage 8 – Visit the Fields

“Visit the Fields” was the next game to be created. The goal of this game is to visit green, amber and red fields in order of the colour of a traffic light within the time limit.

This game was similar to the coins game in terms of generating static markers. However, the markers are not equal like the coins were. Therefore, they remain as their own markers e.g. Green Marker, Amber Marker, Red Marker.

To create the fields I created a for-loop which randomly assigns each of the different fields into one of three areas – either top, middle or bottom of the map (Zone1, Zone2, Zone3):

wolfmapjssay5

 

So it looks like this:

wolfmapjssay6

 

Inside the for-loop the latitude and longitude coordinates of the green, amber and red markers are added to two different arrays. With the green markers coordinates at element 0 in both arrays, the amber coordinates at element 1 and the red coordinates at element 2.

The next part of the program is checking to see whether or not the user’s current position is in the fields and in particular, the correct field. As the player has to visit the fields in the order Green->Amber->Red, if they visit an amber or red field before the green field, they should refuse to disappear from the screen. However, if they visit the green field, it should disappear:

wolfmapjssay7

 

wolfmapjssay8

 

Here is the code with booleans controlling field access:

if((greenLight==false)
&& (coordinate.latitude<=LightLatitudeArray.get(0)+0.0002)&& (coordinate.latitude>=LightLatitudeArray.get(0)-0.0002)
&& (coordinate.longitude<=LightLongitudeArray.get(0)+0.0002)&& (coordinate.longitude>=LightLongitudeArray.get(0)-0.0002))
{
green.remove();
currentColour = “amber”;
barcolour = Color.YELLOW;
greenLight = true;
}

else if((greenLight==true)
&& (coordinate.latitude<=LightLatitudeArray.get(1)+0.0002)&& (coordinate.latitude>=LightLatitudeArray.get(1)-0.0002)
&& (coordinate.longitude<=LightLongitudeArray.get(1)+0.0002)&& (coordinate.longitude>=LightLongitudeArray.get(1)-0.0002))
{
amber.remove();
currentColour = “red”;
barcolour = Color.RED;
amberLight = true;
}

else if((greenLight==true) && (amberLight==true)
&& (coordinate.latitude<=LightLatitudeArray.get(2)+0.0002)&& (coordinate.latitude>=LightLatitudeArray.get(2)-0.0002)
&& (coordinate.longitude<=LightLongitudeArray.get(2)+0.0002)&& (coordinate.longitude>=LightLongitudeArray.get(2)-0.0002))
{
red.remove();
redLight = true;
complete = true;

}

The final stage of the game was to help guide the user through the fields process. To do this, I added two information bars:

wolfmapjssay9

Leave a comment