Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
66
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. AppTitle = "FOOBORK"
  11. Graphics(800, 600, 0)
  12. AutoMidHandle(True)
  13. Global image_linesections:TImage = LoadAnimImage("line_sprites.png", 16, 16, 0, 3)
  14.  
  15. Local mainplayer:TPlayer = New TPlayer.Create(400, 300, [0, 0, 255], [KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN], 3.0)
  16. Local secondplayer:TPlayer = New TPlayer.Create(200, 300, [255, 0, 0], [KEY_A, KEY_W, KEY_D, KEY_S], 3.0)
  17. SetBlend(LIGHTBLEND)
  18. SetAlpha(0.75)
  19.  
  20. While Not KeyHit(KEY_ESCAPE) And Not AppTerminate()
  21.     Cls()
  22.     If KeyHit(KEY_1)
  23.         mainplayer.m_moveangle = 45.0
  24.     Else If KeyHit(KEY_2)
  25.         mainplayer.m_moveangle = 90.0
  26.     End If
  27.     If KeyDown(KEY_SPACE)
  28.         TPlayer.ResetPlayerTrails()
  29.     End If
  30.     TPlayer.UpdatePlayers()
  31.     TPlayer.RenderPlayers()
  32.     SetColor(255, 255, 255)
  33.     DrawText("Direction, moveangle: " + mainplayer.m_direction + ", " + mainplayer.m_moveangle, 15.0, 15.0)
  34.     Flip()
  35. End While
  36.  
  37. Rem
  38.     bbdoc: Section of a trail.
  39. End Rem
  40. Type TTrailSection
  41.    
  42.     Field m_x:Float, m_y:Float
  43.     Field m_x2:Float, m_y2:Float
  44.    
  45.     Rem
  46.         bbdoc: Create a new trail section.
  47.         returns: Nothing.
  48.     End Rem
  49.     Method Create:TTrailSection(x:Float, y:Float, x2:Float, y2:Float)
  50.         m_x = x
  51.         m_y = y
  52.         m_x2 = x2
  53.         m_y2 = y2
  54.         Return Self
  55.     End Method
  56.    
  57. '#region Field accessors
  58.    
  59.     Rem
  60.         bbdoc: Set the section's beginning and ending positions.
  61.         returns: Nothing.
  62.     End Rem
  63.     Method Set(x:Float, y:Float, x2:Float, y2:Float)
  64.         m_x = x
  65.         m_y = y
  66.         m_x2 = x2
  67.         m_y2 = y2
  68.     End Method
  69.    
  70.     Rem
  71.         bbdoc: Set the section's beginning position.
  72.         returns: Nothing.
  73.     End Rem
  74.     Method SetBeginning(x:Float, y:Float)
  75.         m_x = x
  76.         m_y = y
  77.     End Method
  78.    
  79.     Rem
  80.         bbdoc: Set the section's ending position.
  81.         returns: Nothing.
  82.     End Rem
  83.     Method SetEnding(x:Float, y:Float)
  84.         m_x2 = x
  85.         m_y2 = y
  86.     End Method
  87.    
  88. '#end region Field accessors
  89.    
  90.     Rem
  91.         bbdoc: Render the trail section.
  92.         returns: Nothing.
  93.         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.
  94.     End Rem
  95.     Method Render()
  96.         Rem
  97.         SetAlpha(RndFloat() * 0.5 + 0.5)
  98.         Local angle:Float = ATan2(m_y2 - m_y, m_x2 - m_x)
  99.         Local width:Float = Sqr(((m_y2 - m_y) * (m_y2 - m_y)) + ((m_x2 - m_x) * (m_x2 - m_x)))
  100.         SetRotation(angle)
  101.         DrawImage(image_linesections, m_x, m_y, 0)
  102.         DrawImageRect(image_linesections, m_x + Cos(angle) * 8.0, m_y + Sin(angle) * 8.0, width, 16.0, 1)
  103.         DrawImage(image_linesections, m_x2, m_y2, 2)
  104.         End Rem
  105.         DrawVectorLine(m_x, m_y, m_x2, m_y2)
  106.     End Method
  107.    
  108.     Rem
  109.         bbdoc: Clone the section.
  110.         returns: A clone of the section.
  111.     End Rem
  112.     Method Clone:TTrailSection()
  113.         Return New TTrailSection.Create(m_x, m_y, m_x2, m_y2)
  114.     End Method
  115.    
  116. End Type
  117.  
  118. Rem
  119.     bbdoc: Player type.
  120. End Rem
  121. Type TPlayer
  122.    
  123.     Global g_list:TList = New TList
  124.    
  125.     Field m_link:TLink
  126.     Field m_x:Float, m_y:Float
  127.     Field m_color:Int[], m_keys:Int[]
  128.     Field m_direction:Float, m_speed:Float, m_moveangle:Float
  129.    
  130.     Field m_activesection:TTrailSection
  131.     Field m_trailsections:TList
  132.    
  133.     Method New()
  134.         m_link = g_list.AddLast(Self)
  135.         m_activesection = New TTrailSection
  136.         m_trailsections = New TList
  137.     End Method
  138.    
  139.     Rem
  140.         bbdoc: Create a player.
  141.         returns: Itself.
  142.     End Rem
  143.     Method Create:TPlayer(x:Float, y:Float, color:Int[], keys:Int[], speed:Float = 1.0, moveangle:Float = 45.0, direction:Float = 0.0)
  144.         m_x = x
  145.         m_y = y
  146.         m_color = color
  147.         m_keys = keys
  148.         m_speed = speed
  149.         m_moveangle = moveangle
  150.         m_direction = m_direction
  151.         ResetTrail()
  152.         Return Self
  153.     End Method
  154.    
  155.     Rem
  156.         bbdoc: Remove the player.
  157.         returns: Nothing.
  158.     End Rem
  159.     Method Remove()
  160.         If m_link
  161.             m_link.Remove()
  162.             m_link = Null
  163.         End If
  164.     End Method
  165.    
  166.     Rem
  167.         bbdoc: Reset the player's trail.
  168.         returns: Nothing.
  169.     End Rem
  170.     Method ResetTrail()
  171.         m_trailsections.Clear()
  172.         m_activesection.Set(m_x, m_y, m_x, m_y)
  173.         'm_trailpoints.AddFirst(New TTrailPoint.Create(m_x, m_y))
  174.     End Method
  175.    
  176.     Rem
  177.         bbdoc: Update the player.
  178.         returns: Nothing.
  179.     End Rem
  180.     Method Update()
  181.         Local direction:Float = m_direction
  182.         Local x:Float = m_x, y:Float = m_y
  183.         Rem
  184.         ' Explicit directional control
  185.         If KeyHit(m_keys[0])
  186.             m_direction = 0.0
  187.         Else If KeyHit(m_keys[1])
  188.             m_direction = 90.0
  189.         Else If KeyHit(m_keys[2])
  190.             m_direction = 180.0
  191.         Else If KeyHit(m_keys[3])
  192.             m_direction = 270.0
  193.         End If
  194.         End Rem
  195.         ' Angled movement (8-point, 4-point)
  196.         m_direction:- (KeyHit(m_keys[0]) - KeyHit(m_keys[2])) * m_moveangle
  197.         If m_direction > 360.0 Then m_direction = m_moveangle Else If m_direction < 0.0 Then m_direction = 360.0 - m_moveangle
  198.         m_activesection.SetEnding(m_x, m_y)
  199.         m_x:- Cos(m_direction) * m_speed
  200.         m_y:- Sin(m_direction) * m_speed
  201.         If Not(direction = m_direction)
  202.             m_trailsections.AddLast(m_activesection)
  203.             m_activesection = m_activesection.Clone()
  204.             m_activesection.Set(x, y, x, y)
  205.         End If
  206.     End Method
  207.    
  208.     Rem
  209.         bbdoc: Render the player and its trail.
  210.         returns: Nothing.
  211.     End Rem
  212.     Method Render()
  213.         Local alpha:Float = GetAlpha()
  214.         Local rotation:Float = GetRotation()
  215.         SetColor(m_color[0], m_color[1], m_color[2])
  216.         Local link:TLink = m_trailsections.FirstLink()
  217.         Local section:TTrailSection
  218.         While link And link._value <> link
  219.             section = TTrailSection(link._value)
  220.             section.Render()
  221.             link = link._succ
  222.         End While
  223.         'If section
  224.         '   DrawVectorLine(section.m_x2, section.m_y2, m_activesection.m_x2, m_activesection.m_y2)
  225.         'Else
  226.             DrawVectorLine(m_activesection.m_x, m_activesection.m_y, m_activesection.m_x2, m_activesection.m_y2)
  227.         'End If
  228.         SetAlpha(alpha)
  229.         SetRotation(rotation)
  230.         DrawOval(m_x - 3.0, m_y - 3.0, 6.0, 6.0)
  231.     End Method
  232.    
  233.     Rem
  234.         bbdoc: Update all players.
  235.         returns: Nothing.
  236.     End Rem
  237.     Function UpdatePlayers()
  238.         For Local player:TPlayer = EachIn g_list
  239.             player.Update()
  240.         Next
  241.     End Function
  242.    
  243.     Rem
  244.         bbdoc: Render all players.
  245.         returns: Nothing.
  246.     End Rem
  247.     Function RenderPlayers()
  248.         For Local player:TPlayer = EachIn g_list
  249.             player.Render()
  250.         Next
  251.     End Function
  252.    
  253.     Rem
  254.         bbdoc: Reset all players' trails.
  255.         returns: Nothing.
  256.     End Rem
  257.     Function ResetPlayerTrails()
  258.         For Local player:TPlayer = EachIn g_list
  259.             player.ResetTrail()
  260.         Next
  261.     End Function
  262.    
  263. End Type
  264.  
  265. Function DrawVectorLine(x:Float, y:Float, x2:Float, y2:Float)
  266.     SetAlpha(RndFloat() * 0.5 + 0.5)
  267.     Local angle:Float = ATan2(y2 - y, x2 - x)
  268.     Local width:Float = Sqr(((y2 - y) * (y2 - y)) + ((x2 - x) * (x2 - x)))
  269.     SetRotation(angle)
  270.     DrawImage(image_linesections, x, y, 0)
  271.     DrawImageRect(image_linesections, x + Cos(angle) * 8.0, y + Sin(angle) * 8.0, width, 16.0, 1)
  272.     DrawImage(image_linesections, x2, y2, 2)
  273. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement