Qbasicnews.com

Full Version: Scrolling Stopped Working, why?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This simple code was working not long ago...i changed some stuff and it stopped...why?

Code:
option explicit

DECLARE SUB Draw.Map
DECLARE Function int.rnd(base1 as long, base2 as long) as long
DIM ScrWidth as unsigned integer
DIM ScrHeight as unsigned integer

Type Attack
    Minattack as integer
    MaxAttack as integer
END Type

Type Defence
    MinDefence as integer
    MaxDefence as integer
END Type

Type Health
    CurHealth as integer
    MaxHealth as integer
END TYPE

TYPE player
    x as integer
    y as integer
    ScreenX as integer
    ScreenY as integer
    SpriteX as short
    SpriteY as short
    PHealth as health
    PAttack as Attack
    PWepAttack as Attack
    PDefence as Defence
    PArmDefence as Defence
END TYPE

TYPE Camera
    X as integer
    Y as integer
END TYPE

ScrWidth=400
ScrHeight=300

'#include "incs.bi"
const enter = CHR$(13)
const tb = CHR$(9)
const esc = CHR$(27)
const up = CHR$(255) + CHR$(72)
const down = CHR$(255) + CHR$(80)
const lft = CHR$(255) + CHR$(75)
const rght = CHR$(255) + CHR$(77)
const F1 = CHR$(255) + ";"
const F2 = CHR$(255) + "<"
const F3 = CHR$(255) + "="
const F4 = CHR$(255) + ">"
const F5 = CHR$(255) + "?"
const F6 = CHR$(255) + "@"
const F7 = CHR$(255) + "A"
const F8 = CHR$(255) + "B"
const F9 = CHR$(255) + "C"
const F10 = CHR$(255) + "D"
const F11 = CHR$(255) + "à"
const F12 = CHR$(255) + "Ã¥"
const Insert = CHR$(255) + "R"
const Home = CHR$(255) + "G"
const Delete = CHR$(255) + "S"
const PageUp = CHR$(255) + "I"
const PageDown = CHR$(255) + "Q"


Screenres ScrWidth,ScrHeight,32,,1
screenset 1,0


DIM SHARED Player as player
player.x=0
player.y=0
player.screenx=21
player.screeny=21
Player.SpriteX = 18
Player.SpriteY = 20
DIM SHARED ViewCamera as camera
ViewCamera.x=0
ViewCamera.y=0
DIM SHARED unused,unusedx,unusedy as integer

CONST XtilePS = 10
CONST YtilePS = 10
CONST MapXTiles = 100
CONST MapYTiles = 100
DIM SHARED Map(-10 to MapXTiles + 10,-10 to MapYTiles+10) as long
FOR unusedY = 0 to MapYTiles+1
FOR unusedX = 0 to MapXTiles+1
map(unusedx,unusedy) = rgb(int.rnd(255,1),int.rnd(255,1),int.rnd(255,1))
NEXT
NEXT

DIM SHARED BlockMap(-10 to MapXTiles + 10,-10 to MapYTiles+10) as long

Draw.Map

DIM key as string

DO
    
    key = inkey$
    if key=lft then player.screenx-=2 :player.x-=2:CLS: DRAW.MAP
    if key=rght then player.screenx+=2:player.x+=2 :CLS: DRAW.MAP
    if key=up then player.screeny-=2 :player.y-=2:CLS: DRAW.MAP
    if key=down then player.screeny+=2: player.y+=2:CLS: DRAW.MAP
    
    If Player.ScreenX <= 20+Player.ScreenX AND viewCamera.X > 0 then ViewCamera.X -= 1: Player.ScreenX += 2: Draw.Map
    If Player.ScreenX >= (XTilePS*20+Player.ScreenX) AND viewCamera.X < (MapXTiles-XTilePS) then ViewCamera.X += 1: Player.ScreenX -= 2: Draw.Map
    If Player.ScreenY <= 20+Player.ScreenY AND viewCamera.Y > 0 then ViewCamera.Y -= 1: Player.ScreenY += 2: Draw.Map
    If Player.Screeny >= (YTilePS*20+Player.ScreenY) AND viewCamera.Y < (MapYTiles-YTilePS) then ViewCamera.Y += 1: Player.ScreenY -= 2: Draw.Map
        
        LOCATE 1,32: PRINT "Player X:";player.x
         LOCATE 2,32: PRINT "Player Y:";player.y
         ScreenCopy
LOOP until MULTIKEY(1)
END

SUB Draw.Map
DIM cx as integer
DIM cy as integer
Cx = ViewCamera.X
Cy = ViewCamera.Y

FOR unusedY = 1 to YTilePS+1
CY = ViewCamera.Y + UnusedY
FOR unusedX = 1 to XTilePS+1
LINE (UnusedX*21, UnusedY*21)-(21*UnusedX+20,21*UnusedY+20), Map(CX,CY), BF
CX = ViewCamera.X + UnusedX
NEXT
NEXT

LINE (Player.ScreenX,player.ScreenY)-(Player.ScreenX+player.SpriteX,player.screeny+Player.SpriteY), rgb(255,255,255), BF

END SUB

Function int.rnd(base1 as long, base2 as long) as long    
return(int(rnd*base1)+base2)
END FUNCTION
First, do yo have the old working code?
Quote:First, do yo have the old working code?

unfortnately not Sad
Never mind, i noticed the problem...i used .ScreenY and .ScreenX instead of .SpriteY and .SpriteX :oops: