Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "fbgfx.bi"
- const as integer scr_w = 320, scr_h = 240
- screenres scr_w, scr_h,32,,FB.GFX_HIGH_PRIORITY
- type vec2f
- declare constructor()
- declare constructor( tx as single, ty as single )
- x as single
- y as single
- end type
- type line_struct
- p1 as vec2f
- p2 as vec2f
- end type
- type map_struct
- as integer collision
- as integer cl
- linez(5) as line_struct
- 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
- '==box added shit==
- dim shared Map(150, 150) AS map_struct
- map(0,0).collision = 1
- map(0,0).cl = 3
- map(0,0).linez(0).p1 = vec2f(0,0)
- map(0,0).linez(0).p2 = vec2f(16,0)
- map(0,0).linez(1).p1 = vec2f(16,0)
- map(0,0).linez(1).p2 = vec2f(16,16)
- map(0,0).linez(2).p1 = vec2f(16,16)
- map(0,0).linez(2).p2 = vec2f(0,16)
- map(0,0).linez(3).p1 = vec2f(0,16)
- map(0,0).linez(3).p2 = vec2f(0,0)
- map(1,0) = map(0,0)
- map(1,1).collision = 2
- map(1,1).cl = 1
- map(1,1).linez(0).p1 = vec2f(16, 0)
- map(1,1).linez(0).p2 = vec2f(0, 16)
- map(18,1).collision = 2
- map(18,1).cl = 1
- map(18,1).linez(0).p1 = vec2f(16,16)
- map(18,1).linez(0).p2 = vec2f(0,0)
- map(5,5).collision = 1
- map(5,5).cl=0
- map(5,5).linez(0).p1 = vec2f(0,16)
- map(5,5).linez(0).p2 = vec2f(16,16)
- map(10,10) = map(0,0)
- '==================
- for y as integer = 0 to 14
- map(0, y) = map(0,0)
- map(19, y) = map(0,0)
- next
- for x as integer = 0 to 19
- map(x, 0) = map(0,0)
- map(x, 14) = map(0,0)
- next
- pl = type(scr_w\2, scr_h\2)
- Radius = 8
- curTime = timer
- do
- deltaTime = timer-curTime
- curTime = timer
- var moveSpeed = 350*deltaTime
- 'PlD.X=0
- 'PlD.Y=0
- 'if multikey(FB.SC_LEFT) then PlD.X -= 1'moveSpeed
- 'if multikey(FB.SC_RIGHT) then PlD.X += 1' moveSpeed
- 'if multikey(FB.SC_UP) then PlD.Y -= 1' moveSpeed
- 'if multikey(FB.SC_DOWN) then PlD.Y += 1' moveSpeed
- ''PlD.X += (-PlD.X*.95)*deltaTime
- ''PlD.Y += (-PlD.Y*.95)*deltaTime
- 'Pl.X+=PlD.X'*deltaTime
- 'Pl.Y+=PlD.Y'*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*5)*deltaTime
- PlD.Y += (-PlD.Y*5)*deltaTime
- Pl.X+=PlD.X*deltaTime
- Pl.Y+=PlD.Y*deltaTime
- for x as integer = 0 to 20
- for y as integer = 0 to 15
- if not map(x,y).collision=0 then
- for c as integer = 0 to map(x,y).cl
- dim as vec2f tt = map(x,y).linez(c).p1
- dim as vec2f tt2 = map(x,y).linez(c).p2
- tt.x+=(x*16)
- tt.y+=(y*16)
- tt2.x+=(x*16)
- tt2.y+=(y*16)
- Cent = vec2f_perp( tt, tt2 )
- Ero = cPointline( tt, tt2, PL )
- tDist = vec2f_Dist( Pl, Ero )
- if tDist<Radius then
- Pl.X+=Cent.X*(Radius-tDist)
- Pl.Y+=Cent.Y*(Radius-tDist)
- end if
- next
- end if
- next
- next
- screenlock
- line(0,0)-(scr_w-1, scr_h-1),0,bf
- circle (Pl.X,Pl.Y),Radius, &hffffff00
- pset (Pl.X,Pl.Y), &hffffff00
- for x as integer = 0 to 20
- for y as integer = 0 to 15
- if not map(x,y).collision=0 then
- for c as integer = 0 to map(x,y).cl
- line( map(x,y).linez(c).p1.x+(x*16), map(x,y).linez(c).p1.y+(y*16) ) - ( map(x,y).linez(c).p2.x+(x*16), map(x,y).linez(c).p2.y+(y*16) ), &hffffff00
- next
- end if
- next
- next
- screensync
- screenunlock
- sleep 3,1
- loop until multikey(FB.SC_ESCAPE)
- constructor vec2f()
- end constructor
- constructor vec2f( tx as single, ty as single )
- this.x = tx
- this.y = ty
- end constructor
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement