Main Menu

Smoothly Scroll my Camera

Started by Draco9898, March 29, 2008, 06:57:44 PM

Previous topic - Next topic

Draco9898

PlayBASIC Code: [Select]
; PROJECT : Smooth Scrolling Camera
; AUTHOR : Trevor aka Draco9898
; CREATED : 3/29/2008
; ---------------------------------------------------------------------
setfps 60: ScreenVsync 1
Global ScreenW#=800: Global ScreenH#=600
OpenScreen ScreenW#,ScreenH#,16,2

type tCam
LastX#,LastY#
X#,Y#
targx#,targy#
endtype
Dim Cam as Tcam

type tBoxx
X,Y,RgBRed
endtype
Dim boxx(45) as tboxx
boxx(1).x#=200
boxx(1).y#=200
boxx(1).RgBRed=0
For X=2 to 45
boxx(x).x=rnd(3000)
boxx(x).y=rnd(600)
boxx(X).RgBRed=rnd(255)
Next X


CreateCamera 1
CameraCLScolour 1,RGB(88, 145, 207)
Do
CaptureTOscene: ClsScene
`logic
`CAM MOVEMENT
if rightkey()=1
Cam.targX#=Cam.targX# +50
endif
if leftkey()=1
Cam.targX#=Cam.targX# -50
endif
if downkey()=1
Cam.targY#=Cam.targY# +50
endif
if upkey()=1
Cam.targY#=Cam.targY# -50
endif
`SCROLL CAMERA SMOOTHLY
Cam.LastX#=GetCameraX(1)
Cam.LastY#=GetCameraY(1)
X#=(Cam.TargX#-Cam.X#)/14
Y#=(Cam.TargY#-Cam.Y#)/14
Cam.X#=Cam.X#+X#
Cam.Y#=Cam.Y#+Y#
PositionCamera 1,cam.X,cam.Y

`BOXXes
For X=1 to 45
X#=Boxx(x).X#: Y#=Boxx(x).Y#
BoxC 0+X#,0+Y#,80+X#,80+Y#,1,RGB(boxx(X).RgBRed,0,0)
Next X

X#=10+Cam.X#: Y#=10+Cam.Y#
text X#,Y#,str$(Cam.TargX#)+ " "+ str$(Cam.TargY#)
DrawCamera 1
Sync
Loop

DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin