Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. SuperStrict
  3.  
  4. Framework brl.blitz
  5. Import brl.linkedlist
  6. Import brl.glmax2d
  7. Import brl.random
  8. Import brl.pngloader
  9.  
  10. Graphics(800, 600, 0)
  11. AutoMidHandle(True)
  12. Global line_sections:TImage = LoadAnimImage("line_sprites.png", 16, 16, 0, 3)
  13. Global image_linesections:TImage = LoadAnimImage("line_sprites.png", 16, 16, 0, 3)
  14.  
  15. Local mainplayer:TPlayer = New TPlayer.Create(400, 300, 0, 3)
  16. SetLineWidth(2)
  17. SetBlend(LIGHTBLEND)
  18. SetAlpha(.75)
  19. SetColor(255, 0, 0)
  20.  
  21. While Not KeyHit(KEY_ESCAPE) And Not AppTerminate()
  22.     Cls()
  23.     TPlayer.UpdatePlayers()
  24.     TPlayer.RenderPlayers()
  25.     Flip()
  26. End While
  27.  
  28. Type TTrailPoint
  29.    
  30.     Field m_x:Float, m_y:Float
  31.    
  32.     Rem
  33.         bbdoc: Create a trail point.
  34.         returns: Itself.
  35.     End Rem
  36.     Method Create:TTrailPoint(x:Float, y:Float)
  37.         m_x = x
  38.         m_y = y
  39.         Return Self
  40.     End Method
  41.    
  42. End Type
  43.  
  44. Type TPlayer
  45.    
  46.     Global g_list:TList = New TList
  47.    
  48.     Field m_link:TLink
  49.     Field m_x:Float, m_y:Float, m_direction:Float, m_speed:Float = 1
  50.     Field m_trailpoints:TList = New TList
  51.    
  52.     Method New()
  53.         m_link = g_list.AddLast(Self)
  54.     End Method
  55.    
  56.     Rem
  57.         bbdoc: Create a player.
  58.         returns: Itself.
  59.     End Rem
  60.     Method Create:TPlayer(x:Float, y:Float, direction:Float, speed:Float)
  61.         m_x = x
  62.         m_y = y
  63.         m_direction = m_direction
  64.         m_speed = speed
  65.         m_trailpoints.AddFirst(New TTrailPoint.Create(m_x, m_y))
  66.         Return Self
  67.     End Method
  68.    
  69.     Rem
  70.         bbdoc: Remove the player.
  71.         returns: Nothing.
  72.     End Rem
  73.     Method Remove()
  74.         If m_link
  75.             m_link.Remove()
  76.             m_link = Null
  77.         End If
  78.     End Method
  79.    
  80.     Rem
  81.         bbdoc: Update the player.
  82.         returns: Nothing.
  83.     End Rem
  84.     Method Update()
  85.         ' record the current direction
  86.         Local initial_direction:Float = m_direction
  87.         Local initial_x:Float = m_x
  88.         Local initial_y:Float = m_y
  89.        
  90.         m_direction:- (KeyHit(KEY_LEFT) - KeyHit(KEY_RIGHT)) * 45
  91.         If m_direction > 360 Then m_direction = 45.0 Else If m_direction < 0.0 Then m_direction = 315.0
  92.         m_x:- Cos(m_direction) * m_speed
  93.         m_y:- Sin(m_direction) * m_speed
  94.         If initial_direction <> m_direction
  95.             m_trailpoints.AddLast(New TTrailPoint.Create(initial_x, initial_y))
  96.         End If
  97.     End Method
  98.    
  99.     Rem
  100.         bbdoc: Render the player and its trail.
  101.         returns: Nothing.
  102.     End Rem
  103.     Method Render()
  104.         Local alpha:Float = GetAlpha()
  105.         Local rotation:Float = GetRotation()
  106.         Local a:TTrailPoint, b:TTrailPoint
  107.         Local link:TLink = m_trailpoints.FirstLink()
  108.         While link And link._value <> link
  109.             If a
  110.                 b = a
  111.             End If
  112.             a = TTrailPoint(link._value)
  113.             If b
  114.                 DrawVectorLine(a.m_x, a.m_y, b.m_x, b.m_y)
  115.             End If
  116.             link = link._succ
  117.         End While
  118.         a = TTrailPoint(m_trailpoints.LastLink()._value)
  119.         DrawVectorLine(m_x, m_y, a.m_x, a.m_y)
  120.        
  121.         SetAlpha(alpha)
  122.         SetRotation(rotation)
  123.         DrawOval(m_x - 3, m_y - 3, 6, 6)
  124.         DrawText("Direction: " + m_direction, 15, 15)
  125.     End Method
  126.    
  127.     Rem
  128.         bbdoc: Update all players.
  129.         returns: Nothing.
  130.     End Rem
  131.     Function UpdatePlayers()
  132.         For Local player:TPlayer = EachIn g_list
  133.             player.Update()
  134.         Next
  135.     End Function
  136.    
  137.     Rem
  138.         bbdoc: Render all players.
  139.         returns: Nothing.
  140.     End Rem
  141.     Function RenderPlayers()
  142.         For Local player:TPlayer = EachIn g_list
  143.             player.Render()
  144.         Next
  145.     End Function
  146.    
  147. End Type
  148.  
  149. Function DrawVectorLine(x:Float, y:Float, x2:Float, y2:Float)
  150.     SetAlpha(RndFloat() * 0.5 + 0.5)
  151.     Local angle:Float = ATan2(y2 - y, x2 - x)
  152.     Local width:Float = Sqr(((y2 - y) * (y2 - y)) + ((x2 - x) * (x2 - x)))
  153.     ' Draw first end sprite rotated
  154.     SetRotation(angle)
  155.     DrawImage(image_linesections, x, y, 0)
  156.     ' Draw the stretched middle portion
  157.     DrawImageRect(image_linesections, x + Cos(angle) * 8.0, y + Sin(angle) * 8.0, width, 16.0, 1)
  158.     ' Draw second end sprite rotated
  159.     DrawImage(image_linesections, x2, y2, 2)
  160. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement