[WIP] March - a "tug of war" game

March is a tug of war game inspired by an old flash game that I used to play all the time; Warlords: call to arms.

W̶A̶R̶N̶I̶N̶G̶:̶ ̶t̶h̶e̶ ̶g̶a̶m̶e̶ ̶i̶s̶ ̶b̶u̶g̶g̶y̶.̶ ̶I̶t̶ ̶m̶a̶y̶ ̶c̶a̶u̶s̶e̶ ̶y̶o̶u̶r̶ ̶a̶r̶d̶u̶b̶o̶y̶ ̶t̶o̶ ̶r̶e̶s̶e̶t̶ ̶p̶e̶r̶i̶o̶d̶i̶c̶a̶l̶l̶y̶,̶ ̶a̶n̶d̶ ̶k̶e̶e̶p̶ ̶y̶o̶u̶ ̶f̶r̶o̶m̶ ̶u̶p̶l̶o̶a̶d̶i̶n̶g̶ ̶c̶o̶d̶e̶ [Fixed]. This was the issue that brought me to these forums and was solved in this tread with the help of @Pharap, @filmote, and @city41.

layout

spearie Bowie merchentie swordie VS zomb skele witch horror golem demon crab

You will have access to units that have strengths and weaknesses. When a unit reaches the right side of the screen, you will be granted an amount of gold, based on the unit. Gold will be used to buy units.

Right now, the player will play until they are overrun in an attempt to get a high score. In the future, depending on how this project goes, I’d like to add more objectives. Maybe a campaign with bosses or giving the player territory to fight over.

3 Likes

If you want to look at the changes I made to my local copy, I’ve posted them here.

1 Like

This looks cool, I will try it later this week (headed out of town tonight)

1 Like

Hopefully it will look more like a game by then xD

I have a question about the line 275 in March.ino: if(AllyUnits[i].active) It works as intended… but I’m not sure how.

The goal is to find an allyUnit that has active == false, in order to switch it to true. But if thats the case, why is the line not if(!AllyUnits[i].active)?

Ah, good question.

Basically I’ve inverted the logic.

Before what you were trying to do was this:

void placeUnit()
{
	if((playerunitcount < UNIT_COUNT) && (lanePoint > 0) && (lanePoint < 6))
		for(uint8_t i = 0; i < UNIT_COUNT; ++i)
		{
			if(!AllyUnits[i].active)
			{
				AllyUnits[i].setType(unitSelect);
				AllyUnits[i].setLane(lanePoint-1);
				AllyUnits[i].setPos(0);
				AllyUnits[i].setActivity(true);
				++playerunitcount;
				break;
			}
		}
}

So essentially you’re looping through looking for a unit that’s active.
The way you were originally doing it was to check if the unit was active and if it was active then do what you need to do to it.

What I’m doing is sort of the opposite.
Instead of looking for an inactive enemy (i.e. !AllyUnit[i].active), I’m checking if the enemy is active and deciding to ignore it if it is active.

void placeUnit(void)
{
	if((playerunitcount < UNIT_COUNT) && (lanePoint > 0) && (lanePoint < 6))
		for(uint8_t i = 0; i < UNIT_COUNT; ++i)
		{
			if(AllyUnits[i].active)
				continue;

			AllyUnits[i].setType(unitSelect);
			AllyUnits[i].setLane(lanePoint - 1);
			AllyUnits[i].setPos(0);
			AllyUnits[i].setActivity(true);
			++playerunitcount;
			break;
		}
}

continue (in case you haven’t encountered it before) basically means “ignore the rest of the code block, carry on with the next loop iteration”.

Neither way is more correct than the other, it’s just a matter of taste/style.

I prefer to use the continue approach here because it results in fewer levels of nesting (i.e. less braces) and it means that you don’t have to read to the end of the block to understand what’s going on.
With the if(!AllyUnits[i].active) { ... } approach, you’re forced to read to the next end curly brace (}) to make sure that there’s nothing else happening after the check.
With the if(AllyUnits[i].active) continue; approach, you immediately know that if a unit is active then nothing happens to it and the loop continues.

(I take a similar approach with break, and with return in functions.)

2 Likes