views:

70

answers:

2

OK so the array is not working.

My code: http://www.javadan.pastebin.com/C9QiVySe

I am trying to check if blocked(lastX,lastY) of the following tile he is on. I count the tile the player is standing on by adding or minusing X and Y when they go up, down, left, or right. So if the player starts at 0,0, they press down twice and right once. they will be at (2,1). Then the code checks to see if board[2][1] is blocked (which is not). The code specifically states that board[1][1] is blocked but the console says its true for random tiles... :(

Help? Thanks.

+1  A: 

Well, (1,1) is not blocked (BLOCKED == 1, and board[1][1] == 2). On the other hand, (2,1) is blocked. Speaking of which, you might be a bit confused by indexing: given your layout of the blocked array, you should index it using [lastY][lastX], not the other way around.

Also, I don't see any call to blocked() in keyPressed, so you're not actually checking for blockage before moving the player.

Keith Randall
I see what you mean... well now I don't know WHAT to do with my code... :\ or how to make them blocked.
Dan
+1  A: 

What exactly are you asking? You mentioned moving to (2, 1), but (2, 1) is blocked in the array you load. You do realize that BLOCKED == 1, right?

You also never check if the player is blocked at all in keyPressed.

Justin Ardini
WHere? All I see is that board[1][1] is blocked. But I see that now.
Dan
But... what exactly do I do with the 1? I think I configured this wrong. :(
Dan
It may be clearer for you if you specifically put BLOCKED where you intend in loadBoard, i.e. { 2,2,24,24,24,24,24,BLOCKED,3,0,0,0 }. It's equivalent to what you have, though.
Justin Ardini
Yeah but then how would I know what tile to draw there?
Dan