Code: Select all
void player::setPreviousLocation()
{
if(facingUp)
y = y + speed;
if(facingDown)
y = y - speed;
if(facingLeft)
x = x + speed;
if(facingRight)
x = x - speed;
}
void player::applyCollision(int a, int b, int c, int d)
{
if(y > a && y < b && x > c && x < d)
{
setPreviousLocation();
}
}
applyCollision(#, #, #, #);
applyCollision(#, #, #, #);
applyCollision(#, #, #, #);
applyCollision(#, #, #, #);
etc. for every level of the game. I've thought about making a separate program that allows you to click on specific points on the screen, and
store the value of the first two click's y coordinates (which would be 'a' and 'b' in terms of the applyCollision() function), and the last two click's x coordinates(which would be 'c' and 'd' in terms of the applyCollision() function). The values will be stored in a notepad file using the fstream library, breaking a line between every 4 numbers. I want to know how I could allow my game to read these notepad files and call the applyCollision() function, taking every four numbers in the notepad file as its parameters with the usage of a for loop. This way, I can save myself the trouble of listing down the applyCollision function for every level, and simply have the coordinates stored into notepad files for each level.