Qbasicnews.com

Full Version: Too many blue squares
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In a map i am putting together,i have encountered a problem, when i press "t" it should redraw the map, but if the blue brick (the player) has moved, you get a lot of blue squares appear above him, could someone PLEASE help me correct this, the code is

Code:
DIM grass(1000), grass2(1000), bground(1000)
DIM SHARED map(21, 20)
SCREEN 12

FOR y = 1 TO 10
FOR x = 1 TO 10
READ c
PSET (x, y), c
NEXT
NEXT

DATA 02,10,02,02,02,02,10,02,02,02
DATA 02,02,02,02,10,02,02,02,02,10
DATA 02,02,10,02,02,02,02,02,02,02
DATA 10,02,02,02,02,10,02,02,10,02
DATA 02,02,10,02,02,02,02,02,02,02
DATA 10,02,02,02,10,02,02,10,02,02
DATA 02,10,02,02,02,02,02,02,02,10
DATA 02,02,02,02,10,02,02,02,02,02
DATA 02,10,02,02,02,02,10,02,10,02
DATA 02,02,02,10,02,02,02,02,02,02

GET (1, 1)-(10, 10), grass

CLS

FOR y = 1 TO 10
FOR x = 1 TO 10
READ c
PSET (x, y), c
NEXT
NEXT

DATA 02,02,10,02,02,10,02,02,10,02
DATA 10,02,02,02,02,02,02,02,02,02
DATA 02,02,10,02,10,02,10,02,10,02
DATA 10,02,02,02,02,02,02,02,02,02
DATA 02,02,10,02,02,10,02,10,02,02
DATA 10,02,02,02,02,02,02,02,02,10
DATA 02,02,10,02,10,02,10,02,02,02
DATA 02,02,02,02,02,02,02,02,10,02
DATA 02,10,02,02,10,02,10,02,02,02
DATA 02,02,02,10,02,02,02,02,02,10

GET (1, 1)-(10, 10), grass2


CLS

FOR my = 0 TO 19
FOR mx = 0 TO 20
RANDOMIZE TIMER
READ map(mx, my)
NEXT
NEXT

DATA 1,1,2,1,2,2,2,1,1,2,1,2,1,1,2,2,2,2,2,2
DATA 2,2,1,2,1,2,1,2,1,1,1,2,2,2,1,1,1,1,1,1
DATA 1,1,1,1,2,2,2,1,1,2,1,2,1,1,1,2,2,2,2,2
DATA 2,2,2,2,2,2,1,1,2,1,1,1,1,2,2,1,1,1,2,1
DATA 1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2
DATA 1,1,1,1,2,2,2,1,1,2,2,2,1,1,2,2,2,2,2,2
DATA 2,2,1,2,1,2,1,2,1,1,2,2,2,2,1,1,1,1,1,1
DATA 1,1,1,1,2,2,2,1,1,2,2,2,1,1,2,2,2,2,2,2
DATA 2,2,2,2,2,2,1,1,2,1,1,1,1,2,2,1,1,1,2,1
DATA 1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2
DATA 2,2,1,2,1,2,1,2,1,1,2,2,2,2,1,1,1,1,1,1
DATA 1,1,1,1,2,2,2,1,1,2,2,2,1,1,2,1,2,2,2,2
DATA 2,2,2,2,2,2,1,1,2,1,1,1,1,2,2,1,1,1,2,1
DATA 1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2
DATA 1,1,1,1,2,2,2,1,1,1,2,2,1,1,2,1,2,2,2,2
DATA 1,1,1,1,2,2,2,1,1,2,2,2,1,1,2,2,2,2,2,2
DATA 2,2,1,2,1,2,1,2,1,1,2,2,2,2,1,1,1,1,1,1
DATA 1,1,1,1,2,2,2,2,2,2,2,2,1,1,2,2,2,2,2,2
DATA 2,2,2,2,2,2,1,1,2,1,1,1,1,2,2,1,1,1,2,1
DATA 1,2,2,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,2,2
DATA 2,2,2,1,1,1,2,2,2,1,1,2,1,2,2,2,1,2,1,2

nx = 150
ny = 150
x = 100
y = 100

CLS

re:
FOR my = 0 TO 19
FOR mx = 0 TO 20
IF map(mx, my) = 1 THEN PUT (mx * 10, my * 10), grass
IF map(mx, my) = 2 THEN PUT (mx * 10, my * 10), grass2
NEXT
NEXT

LOCATE 20, 20: PRINT "Press [esc] to end"

GET (x, x)-(x + 10, x + 10), bground
LINE (x, x)-(x + 10, y + 10), 1, BF

DO
key$ = INKEY$

LINE (x, y)-(x + 10, y + 10), 1, BF

SELECT CASE key$

CASE "a"
IF x > 0 THEN
LINE (x, y)-(x + 10, y + 10), 0, BF
PUT (x, y), bground
x = x - 10
GET (x, y)-(x + 10, y + 10), bground
END IF

CASE "d"
IF x < 200 THEN
LINE (x, y)-(x + 10, y + 10), 0, BF
PUT (x, y), bground
x = x + 10
GET (x, y)-(x + 10, y + 10), bground
END IF

CASE "w"
IF y > 0 THEN
LINE (x, y)-(x + 10, y + 10), 0, BF
PUT (x, y), bground
y = y - 10
GET (x, y)-(x + 10, y + 10), bground
END IF

CASE "s"
IF y < 190 THEN
LINE (x, y)-(x + 10, y + 10), 0, BF
PUT (x, y), bground
y = y + 10
GET (x, y)-(x + 10, y + 10), bground
END IF

CASE "t"
'testing map redraw
CLS
GOTO re


CASE CHR$(27)
END

CASE " "
IF x = nx + 10 AND y = ny THEN
LOCATE 15, 20: PRINT "Hello, my name is Nadine"
DO
key$ = INKEY$
IF key$ = CHR$(27) THEN END
LOOP UNTIL key$ = " "
LINE (150, 220)-(400, 300), 0, BF
END IF

END SELECT

WAIT &H3DA, 8
LINE (nx, ny)-(nx + 10, ny + 10), 5, BF
LINE (nx + 10, ny)-(nx + 10, ny + 10)

LOOP
LINE 98 :wink:

it is better to have a sub that redraws than to goto(pls no debate). it is more modular and can give more flexablility in programing.
Thanks, HOW DID I MISS THAT, oh wait, i was looking for an error in the main loop, it never occoured to me that it was outside the loop :oops:
i was confused one time when black pixles showed up in my game. i forgot i didnt finish the data images.