1

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

4 Comments

WHere? All I see is that board[1][1] is blocked. But I see that now.
But... what exactly do I do with the 1? I think I configured this wrong. :(
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.
Yeah but then how would I know what tile to draw there?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.