summaryrefslogtreecommitdiff
path: root/vectorgfx
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-10-17 22:45:06 +0000
committerIan C <ianc@noddybox.co.uk>2005-10-17 22:45:06 +0000
commitb85e83e98755140c446e60cda6ec545bd8ccab6f (patch)
tree8c85251ad90c8847bcceda4fa349b7c89d51d970 /vectorgfx
parent1d97a8ae700e0fb2e94eb30f604e54155860fae8 (diff)
Improved collision processing so that the points, objects and lines that cause collisions can be got.
Diffstat (limited to 'vectorgfx')
-rw-r--r--vectorgfx/obj2.2dbin148 -> 60 bytes
-rw-r--r--vectorgfx/test.bmx112
2 files changed, 95 insertions, 17 deletions
diff --git a/vectorgfx/obj2.2d b/vectorgfx/obj2.2d
index b1936cf..5b31b57 100644
--- a/vectorgfx/obj2.2d
+++ b/vectorgfx/obj2.2d
Binary files differ
diff --git a/vectorgfx/test.bmx b/vectorgfx/test.bmx
index ee346aa..c668e92 100644
--- a/vectorgfx/test.bmx
+++ b/vectorgfx/test.bmx
@@ -15,17 +15,17 @@ SetBlend(ALPHABLEND)
Const SIZE:Int=20
Const MSIZE:Int=40
-'Local o1:TVectorGfxObject=New TVectorGfxObject
-'Local o2:TVectorGfxObject=New TVectorGfxObject
+Local o1:TVectorGfxObject=New TVectorGfxObject
+Local o2:TVectorGfxObject=New TVectorGfxObject
-Local o1:TVectorGfxObject=TVectorGfxObject.Load("obj1.2d")
-Local o2:TVectorGfxObject=TVectorGfxObject.Load("obj2.2d")
+'Local o1:TVectorGfxObject=TVectorGfxObject.Load("obj1.2d")
+'Local o2:TVectorGfxObject=TVectorGfxObject.Load("obj2.2d")
Local cm:TVectorGfxCollisionMap=TVectorGfxCollisionMap.Create(MSIZE,MSIZE)
Local l:TList=CreateList()
-Rem
+'Rem
l.Clear()
l.AddLast(TVectorGfxPoint.Create(-SIZE,-SIZE))
l.AddLast(TVectorGfxPoint.Create(SIZE,-SIZE))
@@ -44,29 +44,42 @@ o1.y=300
o1.Save("obj1.2d")
l.Clear()
-l.AddLast(TVectorGfxPoint.Create(-SIZE/2,-SIZE/2))
-l.AddLast(TVectorGfxPoint.Create(SIZE/2,-SIZE/2))
-l.AddLast(TVectorGfxPoint.Create(SIZE/2,SIZE/2))
-l.AddLast(TVectorGfxPoint.Create(-SIZE/2,SIZE/2))
+l.AddLast(TVectorGfxPoint.Create(-SIZE,0))
+l.AddLast(TVectorGfxPoint.Create(SIZE,0))
o2.SetPoints(l.ToArray())
l.Clear()
l.AddLast(TVectorGfxLine.Create(0,1,255,255,255,0))
-l.AddLast(TVectorGfxLine.Create(1,2,255,255,255,0))
-l.AddLast(TVectorGfxLine.Create(2,3,255,255,255,0))
-l.AddLast(TVectorGfxLine.Create(3,0,255,255,255,0))
o2.SetLines(l.ToArray())
o2.Save("obj2.2d")
-EndRem
+'EndRem
Type FadeLine Extends TVectorGfxLineStyle
- Method Draw:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, id:Int, colmap:TVectorGfxCollisionMap)
+ Method Draw:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, id:Int, obj:TVectorGfxObject, line:Int, colmap:TVectorGfxCollisionMap, actor:Int, list:TList)
+ 'Method Draw:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, id:Int, colmap:TVectorGfxCollisionMap)
Local mask:Int=0
Local lp:TList=DoLine(x1,y1,x2,y2)
For Local p:TAlgoPoint=EachIn lp
SetColor(r,g,b)
- mask:|colmap.SetCollision(p.x,p.y,id)
+
+ 'Rem
+ If colmap
+ If actor
+ Local c:TVectorGfxCollision=colmap.GetCollision(p.x,p.y)
+
+ If c
+ mask:|c.mask
+ If list
+ list.AddLast(c)
+ EndIf
+ EndIf
+ Else
+ mask:|colmap.SetCollision(p.x,p.y,id,obj,line)
+ EndIf
+ EndIf
+ 'EndRem
+ 'mask:|colmap.SetCollision(p.x,p.y,id)
Plot(p.x,p.y)
r=Max(0,r-10)
g=Max(0,g-10)
@@ -77,9 +90,65 @@ Type FadeLine Extends TVectorGfxLineStyle
End Method
End Type
+Type Particle
+ Field x:Double
+ Field y:Double
+ Field a:Double
+ Field v:TVector
+
+ Function Create:Particle(x:Int, y:Int, v:TVector)
+ Local o:Particle=New Particle
+ o.x=x
+ o.y=y
+ o.v=v
+ o.a=1
+ Return o
+ End Function
+
+ Method Update()
+ x:+v.x
+ y:+v.y
+ a:-0.01
+
+ If a>0
+ SetAlpha(a)
+ Plot(x,y)
+ EndIf
+ End Method
+
+ Function Process(list:TList)
+ Local l:TLink=list.FirstLink()
+ Local t:TLink
+
+ SetColor(255,255,255)
+
+ While l<>Null
+ Local p:Particle=Particle(l.Value())
+ p.Update()
+
+ If p.a<0.01
+ t=l.NextLink()
+ l.Remove()
+ l=t
+ Else
+ l=l.NextLink()
+ EndIf
+ Wend
+
+ SetAlpha(1)
+ End Function
+End Type
+
+Local list:TList=CreateList()
+Local plist:TList=CreateList()
+
While Not KeyHit(KEY_ESCAPE)
+ Local t=MilliSecs()
+
Cls
+ Particle.Process(plist)
+
cm.Clear()
cm.SetOffset(MouseX()-MSIZE/2,MouseY()-MSIZE/2)
@@ -104,7 +173,16 @@ While Not KeyHit(KEY_ESCAPE)
o2.x=MouseX()
o2.y=MouseY()
- o2.Draw(cm)
+
+ list.Clear()
+ o2.Draw(cm,True,list)
+
+ SetColor(255,0,255)
+ For Local c:TVectorGfxCollision=EachIn list
+ Local v:TVector=c.obj.Normal(c.line)
+ plist.AddLast(Particle.Create(c.x,c.y,v))
+ 'DrawLine(c.x,c.y,c.x+v.x*10,c.y+v.y*10)
+ Next
For Local i:Int=0 To 3
Local p:TVectorGfxPoint[]=o1.AdjustedCoords(i)
@@ -113,7 +191,7 @@ While Not KeyHit(KEY_ESCAPE)
DrawLine(o1.x+p[0].x,o1.y+p[0].y,o1.x+p[0].x+v.x*20,o1.y+p[0].y+v.y*20)
Next
- DrawText MilliSecs() + ":Col=" + o2.Draw(cm),0,0
+ DrawText (MilliSecs()-t) + ":Col=" + o2.Draw(cm),0,0
Flip
FlushMem