1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
//water collision NSEW (North South East West / W,A,S,D) int dirX[4] = { 0, 1, 0, -1 }; int dirY[4] = { -1, 0, 1, 0 }; int lookX = player.x + dirX[player.facingNow]; int lookY = player.y + dirY[player.facingNow]; char c = map[lookX][lookY].terrain; bool obstructed = false; switch (c){ case 'w': obstructed = true; break; } //update player location switch (tolower(key)) { case 'w': //north player.facingNow = kNorth; rotating = (player.facingNow != player.facingLast); inBounds = (player.y > kEdge_top); if (!rotating && inBounds && canMove) player.y--; break; case 's': player.facingNow = kSouth; rotating = (player.facingNow != player.facingLast); inBounds = (player.y < kEdge_bottom); if (!rotating && inBounds && canMove) player.y++; break; case 'd': player.facingNow = kEast; rotating = (player.facingNow != player.facingLast); inBounds = (player.x < kEdge_right); if (!rotating && inBounds && canMove) player.x++; break; case 'a': player.facingNow = kWest; rotating = (player.facingNow != player.facingLast); inBounds = (player.x > kEdge_left); if (!rotating && inBounds && canMove) player.x--; break; //other actions here case 'q': playing = false; break; default: cout << "\nI don't understand that command!"; }
obstructed
canMove
!obstructed