Water Collision

Currently, everytime I move my player into the "w" on my map it doesn't recognize the collision I set up. I shouldn't be able to move onto the "w" as it stands for water.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//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!";
		}
Is obstructed not used, or used somewhere else, and where is canMove defined?

Just taking a shot here, but I guess putting !obstructed into the four if statements will make it work.
can move is defined as a boolean above along with rotating and inbounds
I tried using !obstructed, still allows me to go through it at first, but then leaves me stuck afterwards. Thanks for the input though
Topic archived. No new replies allowed.