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
- Graphics(800, 600, 0)
- AutoMidHandle(True)
- Global line_sections:TImage = LoadAnimImage("line_sprites.png", 16, 16, 0, 3)
- Global image_linesections:TImage = LoadAnimImage("line_sprites.png", 16, 16, 0, 3)
- Local mainplayer:TPlayer = New TPlayer.Create(400, 300, 0, 3)
- SetLineWidth(2)
- SetBlend(LIGHTBLEND)
- SetAlpha(.75)
- SetColor(255, 0, 0)
- While Not KeyHit(KEY_ESCAPE) And Not AppTerminate()
- Cls()
- TPlayer.UpdatePlayers()
- TPlayer.RenderPlayers()
- Flip()
- End While
- Type TTrailPoint
- Field m_x:Float, m_y:Float
- Rem
- bbdoc: Create a trail point.
- returns: Itself.
- End Rem
- Method Create:TTrailPoint(x:Float, y:Float)
- m_x = x
- m_y = y
- Return Self
- End Method
- End Type
- Type TPlayer
- Global g_list:TList = New TList
- Field m_link:TLink
- Field m_x:Float, m_y:Float, m_direction:Float, m_speed:Float = 1
- Field m_trailpoints:TList = New TList
- Method New()
- m_link = g_list.AddLast(Self)
- End Method
- Rem
- bbdoc: Create a player.
- returns: Itself.
- End Rem
- Method Create:TPlayer(x:Float, y:Float, direction:Float, speed:Float)
- m_x = x
- m_y = y
- m_direction = m_direction
- m_speed = speed
- m_trailpoints.AddFirst(New TTrailPoint.Create(m_x, m_y))
- 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: Update the player.
- returns: Nothing.
- End Rem
- Method Update()
- ' record the current direction
- Local initial_direction:Float = m_direction
- Local initial_x:Float = m_x
- Local initial_y:Float = m_y
- m_direction:- (KeyHit(KEY_LEFT) - KeyHit(KEY_RIGHT)) * 45
- If m_direction > 360 Then m_direction = 45.0 Else If m_direction < 0.0 Then m_direction = 315.0
- m_x:- Cos(m_direction) * m_speed
- m_y:- Sin(m_direction) * m_speed
- If initial_direction <> m_direction
- m_trailpoints.AddLast(New TTrailPoint.Create(initial_x, initial_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()
- Local a:TTrailPoint, b:TTrailPoint
- Local link:TLink = m_trailpoints.FirstLink()
- While link And link._value <> link
- If a
- b = a
- End If
- a = TTrailPoint(link._value)
- If b
- DrawVectorLine(a.m_x, a.m_y, b.m_x, b.m_y)
- End If
- link = link._succ
- End While
- a = TTrailPoint(m_trailpoints.LastLink()._value)
- DrawVectorLine(m_x, m_y, a.m_x, a.m_y)
- SetAlpha(alpha)
- SetRotation(rotation)
- DrawOval(m_x - 3, m_y - 3, 6, 6)
- DrawText("Direction: " + m_direction, 15, 15)
- 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
- 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)))
- ' Draw first end sprite rotated
- SetRotation(angle)
- DrawImage(image_linesections, x, y, 0)
- ' Draw the stretched middle portion
- DrawImageRect(image_linesections, x + Cos(angle) * 8.0, y + Sin(angle) * 8.0, width, 16.0, 1)
- ' Draw second end sprite rotated
- DrawImage(image_linesections, x2, y2, 2)
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement