The mojo app is set up within the collision module where the tlBox class is. Without it I get an error: Identifier 'DrawLine' not found.
#rem
bbdoc: Type For handling Axis Aligned Bounding Boxes
about: <p>This type can be used To create bounding boxes For the purpose of collision checking. This is the type used To stored objects in #tlQuadTree. It's
extended by #tlCircle And #tlPolygon. To implement collision checking in you game/app will probably End up inlcluding these as a Field within
your own types, And possibly extending these types so that they can contain a Field linking back To your own entity/actor types. Use #SetPosistion And #Move
To align them in your game world, using these methods also ensures that they will be updated within the quadtree If they belong in one.</p>
<p>It's worth noting that if you want a bounding box that can be orientated then create a 4 sided poly using a #tlPolygon.</p>
<p>The world coordinates are stored as a vector within the Field World, so you can use world.x And world.y To retreive the coordinates of the box.</p>
#End
Class tlBox
Field vertices:tlVector2[]
Field tformvertices:tlVector2[]
Field normals:tlVector2[]
Field tformmatrix:tlMatrix2 = New tlMatrix2
Field tl_corner:tlVector2 'top left corner
Field br_corner:tlVector2 'bottom right corner
Field width:Float
Field height:Float
Field quadlist:TList = CreateList() 'list of quad nodes this rect is in
Field quads:Int 'number of quads the rect is in
Field AreaCheckCount:Int
Field quadtree:tlQuadTree
Field collisiontype:Int
Field world:tlVector2
Field boxoffset:tlVector2 = New tlVector2
Field scale:tlVector2 = New tlVector2
Field velocity:tlVector2 = New tlVector2
Field handle:tlVector2 = New tlVector2
Method New()
tformmatrix.Create()
boxoffset.Create(0, 0)
scale.Create(1, 1)
velocity.Create(0, 0)
handle.Create(0, 0)
End Method
Field collisionlayer:Int
Field _data:Object
#rem
bbdoc: Create a New #tlBox
returns: New tlBox
about: Creates a New Bounding box that you can use For collision checking And adding To a #tlQuadTree. The x And y coordinates represent
the top left corner of the bounding box. You can also assign some data To the boundary as handy way To store some extra info about the boundary.
#End
Method Create:tlBox(x:Float, y:Float, w:Float, h:Float, layer:Int = tlLAYER_1, Data:Object = Null)
If w < 0
x+=w
w = Abs(w)
End If
If h < 0
y+=h
h = Abs(h)
End If
vertices = New tlVector2[4]
handle.x = w / 2
handle.y = h / 2
vertices[0] = New tlVector2
vertices[0].Create(-handle.x, -handle.y)
vertices[1] = New tlVector2
vertices[1].Create(-handle.x, h - handle.y)
vertices[2] = New tlVector2
vertices[2].Create(w - handle.x, h - handle.y)
vertices[3] = New tlVector2
vertices[3].Create(w - handle.x, -handle.y)
normals = New tlVector2[4]
tformvertices = New tlVector2[4]
For Local c:Int = 0 To 3
normals[c] = New tlVector2
normals[c].Create(0, 0)
tformvertices[c] = New tlVector2
tformvertices[c].Create(0, 0)
Next
handle.x = 0
handle.y = 0
tl_corner = New tlVector2
tl_corner.Create(0, 0)
br_corner = New tlVector2
br_corner.Create(0, 0)
world = New tlVector2
world.Create(x + w / 2, y + h / 2)
UpdateNormals()
TForm()
collisionlayer = layer
_data = Data
Return Self
End Method
' More methods...
#rem
bbdoc: Draw this tlBox
about: Use this If you need To draw the bounding box For debugging purposes
#End
Method Draw(offsetx:Float = 0, offsety:Float = 0, boundingbox:Int = False)
DrawLine (tl_corner.x - offsetx, tl_corner.y - offsety, br_corner.x - offsetx, tl_corner.y - offsety)', False)
DrawLine (br_corner.x - offsetx, tl_corner.y - offsety, br_corner.x - offsetx, br_corner.y - offsety)', False)
DrawLine (br_corner.x - offsetx, br_corner.y - offsety, tl_corner.x - offsetx, br_corner.y - offsety)', False)
DrawLine (tl_corner.x - offsetx, br_corner.y - offsety, tl_corner.x - offsetx, tl_corner.y - offsety)', False)
End Method
The method is called like so:
' test obstacle
Scene_Wall[1] = CreateBox(946, 212, 40, 220)
Scene_Wall[1].Draw(946,212)
... where Scene_Wall[1] is a tlBox object.
|