Very nice and easy to change into zoom-in/out...
Global objList:TList=CreateList()
Graphics 640,480,0,60
Global s#=1.0
For Local i=1 To 25
Local o:obj=New obj
o.x=Rand(-GraphicsWidth(),GraphicsWidth())
o.y=Rand(-GraphicsHeight(),GraphicsHeight())
Next
Global youX#,youY#
While KeyHit(KEY_ESCAPE)=0
Cls
If KeyDown(KEY_NUMADD) Then s:+0.1
If KeyDown(KEY_NUMSUBTRACT) Then s:-0.1
If s<0.1 Then s=0.1
If s>4 Then s=4
If KeyDown(KEY_UP) Then youY:-1.0*s
If KeyDown(KEY_DOWN) Then youY:+1.0*s
If KeyDown(KEY_LEFT) Then youX:-1.0*s
If KeyDown(KEY_RIGHT) Then youX:+1.0*s
updateObjs()
SetColor 0,255,0
DrawRect (GraphicsWidth()/2)-3,(GraphicsHeight()/2)-3,7*s,7*s
SetColor 255,255,255;DrawText s,0,0
DrawText "Press +/- on the numpad to zoom. Cursors to move",0,10
Flip
Wend
End
Type obj
Field x,y
Method New() ListAddLast(objList,Self); End Method
Method update()
Local dx=(youX*s)-GraphicsWidth()/2 'here you have forgotten the scalefactor
Local dy=(youY*s)-GraphicsHeight()/2 'here you have forgotten the scalefactor
SetScale 1,1
SetColor 255,0,0
DrawRect (x*s-3)-dx,(y*s-3)-dy,7*s,7*s
End Method
End Type
Function updateObjs()
For Local i:obj=EachIn objList
i.update()
Next
End Function
|