Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "fbgfx.bi"
- const as integer scr_w = 800, scr_h = 600
- screenres scr_w, scr_h,32,,FB.GFX_HIGH_PRIORITY
- type vec2f
- x as single
- y as single
- end type
- declare function vec2f_perp( byref a as vec2f, b as vec2f ) as vec2f
- declare function cPointline( byref va as vec2f, byref vb as vec2f, byref vPoint as vec2f ) as vec2f
- declare sub vec2f_normalize( byref v as vec2f )
- declare function vec2f_len( byref v as vec2f ) as single
- declare function vec2f_dot( byref a as vec2f, byref b as vec2f ) as single
- declare function vec2f_dist( byref va as vec2f, byref vb as vec2f ) as single
- dim as vec2f Pl, Pld, Cent, Ero
- dim as single Radius, tDist
- dim as double deltaTime = timer, curTime = timer
- dim as integer i, ip1, Num_Verts
- pl = type(scr_w\2, scr_h\2)
- Radius = 32
- read Num_Verts
- dim Lines(Num_Verts) as vec2f
- for i = 0 to ubound(Lines)
- read Lines(i).X, Lines(i).Y
- next
- curTime = timer
- do
- deltaTime = timer-curTime
- curTime = timer
- var moveSpeed = 350*deltaTime
- if multikey(FB.SC_LEFT) then PlD.X -= moveSpeed
- if multikey(FB.SC_RIGHT) then PlD.X += moveSpeed
- if multikey(FB.SC_UP) then PlD.Y -= moveSpeed
- if multikey(FB.SC_DOWN) then PlD.Y += moveSpeed
- PlD.X += (-PlD.X*.95)*deltaTime
- PlD.Y += (-PlD.Y*.95)*deltaTime
- Pl.X+=PlD.X*deltaTime
- Pl.Y+=PlD.Y*deltaTime
- screenlock
- line(0,0)-(scr_w-1, scr_h-1),0,bf
- for i=0 to ubound(Lines)-1 step 2
- ip1 = i+1
- Cent = vec2f_perp( Lines(i), Lines(ip1) )
- Ero = cPointline( Lines(i), Lines(ip1), PL )
- tDist = vec2f_Dist( Pl, Ero )
- if tDist<Radius then
- Pl.X+=Cent.X*(Radius-tDist)
- Pl.Y+=Cent.Y*(Radius-tDist)
- end if
- line(Lines(i).X, Lines(i).Y)-(Lines(ip1).X, Lines(ip1).Y),&hffffff00
- line(Ero.X, Ero.Y)-(Ero.X + (Cent.X*Radius), Ero.Y + (Cent.Y*Radius)),&hffffffff
- next
- circle (Pl.X,Pl.Y),Radius, &hffffff00
- pset (Pl.X,Pl.Y), &hffffff00
- screensync
- screenunlock
- sleep 30,1
- loop until multikey(FB.SC_ESCAPE)
- function cPointline( byref va as vec2f, byref vb as vec2f, byref vPoint as vec2f ) as vec2f
- dim as vec2f tVector1
- dim as vec2f tVector2
- dim as vec2f vReturn
- dim as single d
- dim as single t
- tVector1.X = VPoint.X - Va.X
- tVector1.Y = VPoint.Y - Va.Y
- tVector2.X = Vb.X - Va.X
- tVector2.Y = Vb.Y - Va.Y
- vec2f_normalize( tVector2 )
- d = vec2f_dist( vA, vB )
- t = vec2f_dot( tVector2, tVector1 )
- if t<=0 then return Va
- if t>=d then return Vb
- vReturn.X = Va.X + (tVector2.X * t)
- vReturn.Y = Va.Y + (tVector2.Y * t)
- return vReturn
- end function
- function vec2f_dist( byref va as vec2f, byref vb as vec2f ) as single
- dim as single dx
- dim as single dy
- dx = va.X - vb.X
- dy = va.Y - vb.Y
- return sqr(dx^2+dy^2)
- end function
- sub vec2f_normalize( byref v as vec2f )
- dim as single vLen
- vLen = vec2f_len ( v )
- v.x /= vLen
- v.y /= vLen
- end sub
- function vec2f_len( byref v as vec2f ) as single
- dim as single tLen
- tLen = sqr(v.x^2 + v.y^2)
- if tLen = 0 then tLen = 1
- return tLen
- end function
- function vec2f_dot( byref a as vec2f, byref b as vec2f ) as single
- return a.x*b.x + a.y*b.y
- end function
- function vec2f_perp( byref a as vec2f, byref b as vec2f ) as vec2f
- dim as single vLen
- dim as vec2f d
- d.x = b.x - a.x
- d.y = b.y - a.y
- vLen = vec2f_len( d )
- return type( d.y / vLen, -d.x / vLen )
- end function
- data 21
- data 50,70
- data 10,240
- data 10,240
- data 100,340
- data 100,340
- data 125,400
- data 125,400
- data 300,450
- data 300,450
- data 450,470
- data 450,470
- data 600,370
- data 600,370
- data 550,300
- data 550,300
- data 625,250
- data 625,250
- data 500,10
- data 500,10
- data 320,50
- data 320,50
- data 50,70
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement