Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clipping and scrolling

Status
Not open for further replies.

Barok

MIS
Dec 13, 2002
134
0
0
CA
i'm currently trying to make a scrolling engine that scrolls pixel by pixel. how would i be able to do this? could someone explain this to me?
 
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$ <> &quot;&quot;
IF X$ = CHR$(0) + &quot;K&quot; THEN: X% = X% + 1 'RIGHT ARROW
IF X$ = CHR$(0) + &quot;M&quot; THEN: X% = X% - 1 'LEFT ARROW
IF X$ = CHR$(0) + &quot;H&quot; THEN: Y% = Y% + 1 'DOWN ARROW
IF X$ = CHR$(0) + &quot;P&quot; 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$ <> &quot;&quot;
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) + &quot;K&quot; THEN : X% = X% + 1 'RIGHT ARROW
IF X$ = CHR$(0) + &quot;M&quot; THEN : X% = X% - 1 'LEFT ARROW
IF X$ = CHR$(0) + &quot;H&quot; THEN : Y% = Y% + 1 'DOWN ARROW
IF X$ = CHR$(0) + &quot;P&quot; 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).

That should get you started.
 
sorry. i should have been more specific.

imagine a map bigger than the screen. when the player presses an arrow key, the screen scrolls left or right. the whole screen is filled.

what i want is an effect kinda like those old rpg's. final fantasy 1-6, for example. or dragon warrior/quest series.

thanks anyways!
 
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$=&quot;&quot; then goto checkkey
if right$(a$,1)=&quot;K&quot; then x=x+1:gosub initscreen
if right$(a$,1)=&quot;M&quot; then x=x-1:gosub initscreen
if right$(a$,1)=&quot;H&quot; then y=y-1:gosub initscreen
if right$(a$,1)=&quot;P&quot; then y=y+1:gosub initscreen
if a$=&quot;q&quot; or a$=&quot;Q&quot; 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....
 
My code was for a large style RPG, like I said, I used that tecnique to make a very very large map. I was just showing you the basics.
 
I just realized that the above address will not take you to the tutorial. When you get to that site go to tutorials, and then to scrolling.
 
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...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top