Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SuperStrict
- Framework brl.blitz
- Import brl.linkedlist
- Import brl.glmax2d
- Import brl.random
- Import brl.pngloader
- AppTitle = "FOOBORK"
- Graphics(800, 600, 0)
- AutoMidHandle(True)
- Global image_linesections:TImage = LoadAnimImage("line_sprites.png", 16, 16, 0, 3)
- Local mainplayer:TPlayer = New TPlayer.Create(400, 300, [0, 0, 255], [KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN], 3.0)
- Local secondplayer:TPlayer = New TPlayer.Create(200, 300, [255, 0, 0], [KEY_A, KEY_W, KEY_D, KEY_S], 3.0)
- SetBlend(LIGHTBLEND)
- SetAlpha(0.75)
- While Not KeyHit(KEY_ESCAPE) And Not AppTerminate()
- Cls()
- If KeyHit(KEY_1)
- mainplayer.m_moveangle = 45.0
- Else If KeyHit(KEY_2)
- mainplayer.m_moveangle = 90.0
- End If
- If KeyDown(KEY_SPACE)
- TPlayer.ResetPlayerTrails()
- End If
- TPlayer.UpdatePlayers()
- TPlayer.RenderPlayers()
- SetColor(255, 255, 255)
- DrawText("Direction, moveangle: " + mainplayer.m_direction + ", " + mainplayer.m_moveangle, 15.0, 15.0)
- Flip()
- End While
- Rem
- bbdoc: Section of a trail.
- End Rem
- Type TTrailSection
- Field m_x:Float, m_y:Float
- Field m_x2:Float, m_y2:Float
- Rem
- bbdoc: Create a new trail section.
- returns: Nothing.
- End Rem
- Method Create:TTrailSection(x:Float, y:Float, x2:Float, y2:Float)
- m_x = x
- m_y = y
- m_x2 = x2
- m_y2 = y2
- Return Self
- End Method
- '#region Field accessors
- Rem
- bbdoc: Set the section's beginning and ending positions.
- returns: Nothing.
- End Rem
- Method Set(x:Float, y:Float, x2:Float, y2:Float)
- m_x = x
- m_y = y
- m_x2 = x2
- m_y2 = y2
- End Method
- Rem
- bbdoc: Set the section's beginning position.
- returns: Nothing.
- End Rem
- Method SetBeginning(x:Float, y:Float)
- m_x = x
- m_y = y
- End Method
- Rem
- bbdoc: Set the section's ending position.
- returns: Nothing.
- End Rem
- Method SetEnding(x:Float, y:Float)
- m_x2 = x
- m_y2 = y
- End Method
- '#end region Field accessors
- Rem
- bbdoc: Render the trail section.
- returns: Nothing.
- about: NOTE: This method changes the alpha and rotation. It is best used in batch, so that calls to reset the alpha and rotation are minimized.
- End Rem
- Method Render()
- Rem
- SetAlpha(RndFloat() * 0.5 + 0.5)
- Local angle:Float = ATan2(m_y2 - m_y, m_x2 - m_x)
- Local width:Float = Sqr(((m_y2 - m_y) * (m_y2 - m_y)) + ((m_x2 - m_x) * (m_x2 - m_x)))
- SetRotation(angle)
- DrawImage(image_linesections, m_x, m_y, 0)
- DrawImageRect(image_linesections, m_x + Cos(angle) * 8.0, m_y + Sin(angle) * 8.0, width, 16.0, 1)
- DrawImage(image_linesections, m_x2, m_y2, 2)
- End Rem
- DrawVectorLine(m_x, m_y, m_x2, m_y2)
- End Method
- Rem
- bbdoc: Clone the section.
- returns: A clone of the section.
- End Rem
- Method Clone:TTrailSection()
- Return New TTrailSection.Create(m_x, m_y, m_x2, m_y2)
- End Method
- End Type
- Rem
- bbdoc: Player type.
- End Rem
- Type TPlayer
- Global g_list:TList = New TList
- Field m_link:TLink
- Field m_x:Float, m_y:Float
- Field m_color:Int[], m_keys:Int[]
- Field m_direction:Float, m_speed:Float, m_moveangle:Float
- Field m_activesection:TTrailSection
- Field m_trailsections:TList
- Method New()
- m_link = g_list.AddLast(Self)
- m_activesection = New TTrailSection
- m_trailsections = New TList
- End Method
- Rem
- bbdoc: Create a player.
- returns: Itself.
- End Rem
- Method Create:TPlayer(x:Float, y:Float, color:Int[], keys:Int[], speed:Float = 1.0, moveangle:Float = 45.0, direction:Float = 0.0)
- m_x = x
- m_y = y
- m_color = color
- m_keys = keys
- m_speed = speed
- m_moveangle = moveangle
- m_direction = m_direction
- ResetTrail()
- Return Self
- End Method
- Rem
- bbdoc: Remove the player.
- returns: Nothing.
- End Rem
- Method Remove()
- If m_link
- m_link.Remove()
- m_link = Null
- End If
- End Method
- Rem
- bbdoc: Reset the player's trail.
- returns: Nothing.
- End Rem
- Method ResetTrail()
- m_trailsections.Clear()
- m_activesection.Set(m_x, m_y, m_x, m_y)
- 'm_trailpoints.AddFirst(New TTrailPoint.Create(m_x, m_y))
- End Method
- Rem
- bbdoc: Update the player.
- returns: Nothing.
- End Rem
- Method Update()
- Local direction:Float = m_direction
- Local x:Float = m_x, y:Float = m_y
- Rem
- ' Explicit directional control
- If KeyHit(m_keys[0])
- m_direction = 0.0
- Else If KeyHit(m_keys[1])
- m_direction = 90.0
- Else If KeyHit(m_keys[2])
- m_direction = 180.0
- Else If KeyHit(m_keys[3])
- m_direction = 270.0
- End If
- End Rem
- ' Angled movement (8-point, 4-point)
- m_direction:- (KeyHit(m_keys[0]) - KeyHit(m_keys[2])) * m_moveangle
- If m_direction > 360.0 Then m_direction = m_moveangle Else If m_direction < 0.0 Then m_direction = 360.0 - m_moveangle
- m_activesection.SetEnding(m_x, m_y)
- m_x:- Cos(m_direction) * m_speed
- m_y:- Sin(m_direction) * m_speed
- If Not(direction = m_direction)
- m_trailsections.AddLast(m_activesection)
- m_activesection = m_activesection.Clone()
- m_activesection.Set(x, y, x, y)
- End If
- End Method
- Rem
- bbdoc: Render the player and its trail.
- returns: Nothing.
- End Rem
- Method Render()
- Local alpha:Float = GetAlpha()
- Local rotation:Float = GetRotation()
- SetColor(m_color[0], m_color[1], m_color[2])
- Local link:TLink = m_trailsections.FirstLink()
- Local section:TTrailSection
- While link And link._value <> link
- section = TTrailSection(link._value)
- section.Render()
- link = link._succ
- End While
- 'If section
- ' DrawVectorLine(section.m_x2, section.m_y2, m_activesection.m_x2, m_activesection.m_y2)
- 'Else
- DrawVectorLine(m_activesection.m_x, m_activesection.m_y, m_activesection.m_x2, m_activesection.m_y2)
- 'End If
- SetAlpha(alpha)
- SetRotation(rotation)
- DrawOval(m_x - 3.0, m_y - 3.0, 6.0, 6.0)
- End Method
- Rem
- bbdoc: Update all players.
- returns: Nothing.
- End Rem
- Function UpdatePlayers()
- For Local player:TPlayer = EachIn g_list
- player.Update()
- Next
- End Function
- Rem
- bbdoc: Render all players.
- returns: Nothing.
- End Rem
- Function RenderPlayers()
- For Local player:TPlayer = EachIn g_list
- player.Render()
- Next
- End Function
- Rem
- bbdoc: Reset all players' trails.
- returns: Nothing.
- End Rem
- Function ResetPlayerTrails()
- For Local player:TPlayer = EachIn g_list
- player.ResetTrail()
- Next
- End Function
- End Type
- Function DrawVectorLine(x:Float, y:Float, x2:Float, y2:Float)
- SetAlpha(RndFloat() * 0.5 + 0.5)
- Local angle:Float = ATan2(y2 - y, x2 - x)
- Local width:Float = Sqr(((y2 - y) * (y2 - y)) + ((x2 - x) * (x2 - x)))
- SetRotation(angle)
- DrawImage(image_linesections, x, y, 0)
- DrawImageRect(image_linesections, x + Cos(angle) * 8.0, y + Sin(angle) * 8.0, width, 16.0, 1)
- DrawImage(image_linesections, x2, y2, 2)
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement