Page 1 of 1

moving a number around on a bitmap

Posted: Fri Aug 18, 2006 12:12 pm
by intellisquid
Hi all. I'm trying to make a turn-based, puzzle style game that runs on a tile-based map. The player is a bit on a map, just like the walls and objects are. My code isn't working, though.

The 'up' and 'down' code follows. Up works, but down does not. They look exactly the same to me, so if anyone can tell me why down isn't working, I'd greatly appreciate it. I've run into the same problem when trying to use the 'right' key, too. I know I'm missing something really simple. :shock:

Map is a 20x12 array. I'll gladly post more code if needed. thanks in advance!

Code: Select all

IF k$ = "u" THEN
 FOR y = 0 TO 11
 FOR x = 0 TO 19
 IF map(x, y) = 2 THEN
  map(x, y) = 0
  map(x, y - 1) = 2
 END IF
 NEXT x
 NEXT y
END IF

IF k$ = "d" THEN
 FOR y = 0 TO 11
 FOR x = 0 TO 19
 IF map(x, y) = 2 THEN
  map(x, y) = 0
  map(x, y + 1) = 2
 END IF
 NEXT x
 NEXT y
END IF

Re: moving a number around on a bitmap

Posted: Fri Aug 18, 2006 3:14 pm
by Stoves
In the k$ = "d" code, change FOR y = 0 TO 11 to FOR y = 11 TO 0 STEP -1

In the k$ = "r" code, change FOR x = 0 TO 19 to FOR x = 19 TO 0 STEP -1

The reason for your problem on moving down and right is that you end up changing bits before you get a chance to scan them.

BTW, if you'd like to use arrow keys instead of letters, check out the following:

change "u" to CHR$(0) + "H"
change "d" to CHR$(0) + "P"
change "l" to CHR$(0) + "K"
change "r" to CHR$(0) + "M"

NOTE: To use the arrow keys, you must be using the INKEY$ function instead of the INPUT or INPUT$(1) command to check input.
(so precede checking the value of k$ with a line like "k$ = INKEY$")

Let me know if any of this doesn't make sense. I'm at work, so posting quickly.

Posted: Sat Aug 19, 2006 11:36 am
by intellisquid
I think it makes perfect sense, finally. I had to play around with it for awhile, but eventually I realized changing a bit on x+1 or y+1 means the for/next loop is going to keep changing the bit until it pushes it out of the bounds of the array, because it has yet to scan x+1 or y+1...
Anyway, thank you so much. :D Have a good one.

Posted: Sat Aug 19, 2006 2:51 pm
by intellisquid
This is probably common knowledge, but I also figured out a shrewd little shortcut, of adding x+1 or y+1 by itself to 'trick' the for/next loop into skipping the bit the player has just moved into. :lol: