When I run the following code, for some reason it executes as if the else is always true, however when I take away the else statement, the if statements work fine, thus indicating that the if statements do work, I think, however I cannot set Player.moving = true without some kind of else.
if (Player.x > j * 25 - 15 &&
Player.x < j * 25 + 10 &&
Player.y > i * 25 &&
Player.y < i * 25 + 25 &&
Player.direction === 1
) {
Player.moving = false;
}
else if (Player.x > j * 25 &&
Player.x < j * 25 + 25 &&
Player.y > i * 25 - 15 &&
Player.y < i * 25 + 10 &&
Player.direction === 2
) {
Player.moving = false;
}
else if (Player.x > j * 25 &&
Player.x < j * 25 + 40 &&
Player.y > i * 25 &&
Player.y < i * 25 + 25 &&
Player.direction === 3
) {
Player.moving = false;
}
else if (Player.x > j * 25 &&
Player.x < j * 25 + 25 &&
Player.y > i * 25 &&
Player.y < i * 25 + 50 &&
Player.direction === 4
) {
Player.moving = false;
}
else {
Player.moving = true;
}
Where i and j are the indices of the object in a tile map, such that the tilemap looks something like this: var tilemap = [" "," "];
For instance when
if (Player.x > j * 25 &&
Player.x < j * 25 + 40 &&
Player.y > i * 25 &&
Player.y < i * 25 + 25 &&
Player.direction === 3
) {
Player.moving = false;
}
is the only code present. The player will cease its movement to the left when the object at [i][j] is to the left of it as expected. However, with the else statement present, it simply continues to move, Player.moving stays true. Thanks for any help!