Ok, so this is my first C++ code, I am not making any excuses though because I have been programming off and on in VB for a few years so I am aware of a number of bad practises I committed here.
So here is some code for you to feast your eyes upon, you can see how I jumped from one preferred grid referencing method to another, Coordsx, VX, GridRefx... that's what happens when you don't have a clear plan though.
I am currently restarting the project in a much more manageable way because even I have lost track of what is going on in may sections.
I posted the game running (or at least doing a good imitation of running) on youtube here
The game is a Viking raiders (spectrum) remake.
int Player1::Check_Collision(int Directions)
{
int i;
switch (Directions)
{
case 1:
//Bottom Left
if (Coordsx - vx <= -30 || Coordsy + vy >= (SCREEN_HEIGHT - 90) || Map[GridRefx - 1][GridRefy + 1].style == 1 || Map[GridRefx - 1][GridRefy + 1].Occupied == 1)
{
if (Map[GridRefx - 1][GridRefy + 1].Occupied == 1)
{
Fighting = true;
Stepinto = 2;
AnimOverlord = 0;
}
LockPSel = false;
Active = false;
Direction = 0;
return 1;
}
break;
//Down
case 2:
if (Coordsy + vy >= (SCREEN_HEIGHT - 90) || Map[GridRefx][GridRefy + 1].style == 1 || Map[GridRefx][GridRefy + 1].Occupied == 1)
{
if (Map[GridRefx][GridRefy + 1].Occupied == 1)
{
Fighting = true;
Stepinto = 2;
AnimOverlord = 0;
}
Direction = 0;
LockPSel = false;
Active = false;
return 1;
}
break;
case 3:
//Bottom Right
if (Coordsx + vx >= SCREEN_WIDTH || Coordsy + vy >= (SCREEN_HEIGHT - 90) || Map[GridRefx + 1][GridRefy + 1].style == 1 || Map[GridRefx + 1][GridRefy + 1].Occupied == 1)
{
if (Map[GridRefx + 1][GridRefy + 1].Occupied == 1)
{
Fighting = true;
Stepinto = 2;
AnimOverlord = 0;
}
Direction = 0;
LockPSel = false;
Active = false;
return 1;
}
break;
case 4:
//left
if (Coordsx - vx <= -30 || Map[GridRefx - 1][GridRefy].style == 1 || Map[GridRefx - 1][GridRefy].Occupied == 1)
{
if (Map[GridRefx - 1][GridRefy].Occupied == 1)
{
Fighting = true;
Stepinto = 2;
AnimOverlord = 0;
}
Direction = 0;
LockPSel = false;
Active = false;
return 1;
}
break;
case 6:
//right
if (Coordsx + vx >= SCREEN_WIDTH || Map[GridRefx + 1][GridRefy].style == 1 || Map[GridRefx + 1][GridRefy].Occupied == 1 )
{
if (Map[GridRefx + 1][GridRefy].Occupied == 1)
{
Fighting = true;
Stepinto = 2;
AnimOverlord = 0;
}
Direction = 0;
LockPSel = false;
Active = false;
return 1;
}
break;
case 7:
//top left
if (Coordsx - vx <= -30 || Coordsy - vy <= -30 || Map[GridRefx - 1][GridRefy - 1].style == 1 || Map[GridRefx - 1][GridRefy - 1].Occupied == 1)
{
if (Map[GridRefx - 1][GridRefy - 1].Occupied == 1)
{
Fighting = true;
Stepinto = 2;
AnimOverlord = 0;
}
Direction = 0;
LockPSel = false;
Active = false;
return 1;
}
break;
case 8:
//up
if (Coordsy - vy <= -30 || Map[GridRefx][GridRefy - 1].style == 1 || Map[GridRefx][GridRefy - 1].Occupied == 1 )
{
if (Map[GridRefx][GridRefy - 1].Occupied == 1)
{
Fighting = true;
Stepinto = 2;
AnimationCycle = true;
AnimOverlord = 0;
}
Direction = 0;
LockPSel = false;
Active = false;
return 1;
}
break;
case 9:
//top right
if (Coordsx +vx >= SCREEN_WIDTH || Coordsy - vy <= -30 || Map[GridRefx + 1][GridRefy - 1].style == 1 || Map[GridRefx + 1][GridRefy - 1].Occupied == 1)
{
if (Map[GridRefx + 1][GridRefy - 1].Occupied == 1)
{
Fighting = true;
Stepinto = 2;
AnimationCycle = true;
AnimOverlord = 0;
}
Direction = 0;
LockPSel = false;
Active = false;
return 1;
}
break;
}
return 0;
}