well im trying to make a side scroller, but the camera won't display past the screenboarder.
Graphics 800,600,32,2
SeedRnd MilliSecs()
SetBuffer BackBuffer()
Global fullscreen = CreateImage(GraphicsWidth(),GraphicsHeight())
Global camerax,cameray,cameravx,cameravy,cameramove
Type dot
Field x,y
End Type
For loop = 1 To 50
dot.dot = New dot
dot\x = Rand(0,GraphicsWidth())
dot\y = Rand(0,GraphicsHeight())
Next
While Not KeyDown(1)
;draw the screen borders
Line 0,0,GraphicsWidth(),0
Line 0,0,0,GraphicsHeight()
Line GraphicsWidth()-1,0,GraphicsWidth()-1,GraphicsHeight()-1
Line 0,GraphicsHeight()-1,GraphicsWidth()-1,GraphicsHeight()-1
For dot.dot = Each dot
Plot dot\x,dot\y
Next
x = x + MouseXSpeed()
y = y + MouseYSpeed()
If y < 0 Then y = 0
If y > 600 Then y = 600
If x < 0 Then x = 0
If x > 800 Then x = 800
updatecamera(x,y)
Flip
Cls
Wend
Function updatecamera(x,y)
GrabImage(fullscreen,camerax,cameray)
Cls
DrawImage(fullscreen,0,0)
; move the camera to the player
If x-400 > camerax+100 Then camerax = camerax + 2 : cameravx = cameravx + 1
If y-500 > cameray+40 Then cameray = cameray + 2 : cameravy = cameravy + 1
If x-400 < camerax-100 Then camerax = camerax - 2 : cameravx = cameravx - 1
If y-500 < cameray-40 Then cameray = cameray - 2 : cameravy = cameravy - 1
; jumps the camera if it is too far
If x-400 > camerax+340 Then camerax = camerax + 4 : cameravx = cameravx + 3
If y-500 > cameray+140 Then cameray = cameray + 4 : cameravy = cameravy + 3
If x-400 < camerax-340 Then camerax = camerax - 4 : cameravx = cameravx - 3
If y-500 < cameray-140 Then cameray = cameray - 4 : cameravy = cameravy - 3
If cameramove = False Then cameravx = 0 : cameravy = 0
camerax = camerax + cameravx ;update the camera's velocity
cameray = cameray + cameravy
cameramove = False
End Function
|