The best way to do this is to use the drawing commands that QBasic has preprogrammed and then use a variable to specify where they start from. Try something like this:
SCREEN 13
DO
DO
LINE (X%,Y%) - (X% + 100, Y% + 100),5,BF
X$ = INKEY$
LOOP UNTIL X$ <> ""
IF X$ = CHR$(0) + "K" THEN: X% = X% + 1 'RIGHT ARROW
IF X$ = CHR$(0) + "M" THEN: X% = X% - 1 'LEFT ARROW
IF X$ = CHR$(0) + "H" THEN: Y% = Y% + 1 'DOWN ARROW
IF X$ = CHR$(0) + "P" THEN: Y% = Y% - 1 'UP ARROW
LOOP UNTIL X$ = CHR$(27)
This'll make a box move around the screen pixel by pixel. You can make as many boxes as you want and just make it so your character can't move through them.
The other way to do it is to use an array and DATA statements. You create your world in the data statements, and then load it into an array. I did this for an RPG I'm making and I have a HUGE world that scrolls very smoothly.
Here's a small example.
SCREEN 13
DIM MAPINFO%(5, 5)
RESTORE MAP
FOR I = 1 TO 5
FOR J = 1 TO 5
READ INFO%
MAPINFO%(J, I) = INFO%
NEXT
NEXT
DO
DO
X$ = INKEY$
LOOP UNTIL X$ <> ""
CLS
FOR I = 1 TO 5
FOR J = 1 TO 5
LINE(J*10-10-X%,I*10-10-Y%)-(J*10-X%,I*10-Y%),MAPINFO%(J,I),BF
'The line above is from text wrap. It should
'be one continuous line.
NEXT
NEXT
IF X$ = CHR$(0) + "K" THEN : X% = X% + 1 'RIGHT ARROW
IF X$ = CHR$(0) + "M" THEN : X% = X% - 1 'LEFT ARROW
IF X$ = CHR$(0) + "H" THEN : Y% = Y% + 1 'DOWN ARROW
IF X$ = CHR$(0) + "P" THEN : Y% = Y% - 1 'UP ARROW
LOOP UNTIL X$ = CHR$(27)
MAP:
DATA 1,1,1,1,1
DATA 1,0,0,0,1
DATA 1,0,0,0,1
DATA 1,0,0,0,1
DATA 1,1,1,1,1
That code should make a hollow blue box move around the screen. You can increase the size of the map by using more data statements, or by making the numbers bigger. (Right now it's set to 10).
well.. hmmm
it will be slower but...,
screen 12
dim map(128,96)
for y=1 to 96
for x=1 to 128
randomize timer
c=int(rnd*15)+1
map(x,y)=c
next
next
gosub initscreen
checkkey:
a$=inkey$
if a$="" then goto checkkey
if right$(a$,1)="K" then x=x+1:gosub initscreen
if right$(a$,1)="M" then x=x-1:gosub initscreen
if right$(a$,1)="H" then y=y-1:gosub initscreen
if right$(a$,1)="P" then y=y+1:gosub initscreen
if a$="q" or a$="Q" then end
goto checkkey
initscreen:
if x< 0 then x=0
if y<0 then y=0
if x>64 then x=64
if y>48 then y=48
for dy=1 to 48
for dx=1 to 64
line ((dx-1)*10,(dy-1)*10)-(dx*10,dy*10),map(x+dx,y+dy)
next
next
return
it creates a randomize colored 10*10 boxes in screen and they move.the map size is 2*2k.
i need poke and peek to make it faster....
i know all the basics. p*t scrolling's the only thing i have problems with in my rpg. i downloaded all the tutorials for qb and read them all, but sadly there's next to nothing to p*t or p*p scrolling, and the tuts that actually do explain it is poorly done...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.