October 28, 2021, 11:26:59

Author Topic: [bb] Fish! by Ion [ 1+ years ago ]  (Read 705 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Fish! by Ion [ 1+ years ago ]
« on: June 29, 2017, 00:28:38 »
Title : Fish!
Author : Ion
Posted : 1+ years ago

Description : Generates "fishes" with a little variation

Code :
Code: BlitzBasic
  1. ;********************************
  2. ; Fishes! by Ion
  3. ; Copyright (c) 2009 E.Sandberg (Ion)
  4. ; This code is free to the public domain
  5. ;
  6. ;********************************
  7.  
  8. ;Funny variables
  9. Type TFish
  10.         Field Entity, Yaw#, Speed#
  11. End Type
  12. Global fishes.TFish[999]
  13.  
  14. ;Initialize
  15. Graphics3D 1024, 768, 16, 2
  16. SetBuffer BackBuffer()
  17. SeedRnd MilliSecs()
  18. WireFrame False
  19. HidePointer
  20.  
  21. ;A little light
  22. light = CreateLight()
  23.  
  24. ;Set up the camera
  25. camera = CreateCamera()
  26. campiv = CreatePivot()
  27. EntityParent camera, campiv
  28. PositionEntity camera, 0, 50, -50
  29. RotateEntity camera, 45, 0, 0
  30. CameraClsColor camera, 64, 64, 255
  31. CameraFogMode camera, 1
  32. CameraFogColor camera, 64, 64, 255
  33. CameraFogRange camera, 10, 100
  34.  
  35. ;Create 100 fishes!
  36. For i = 0 To 99
  37.         f.TFish = New TFish
  38.         fEntity = CreateFish()
  39.         fYaw = Rnd(-1, 1)
  40.         fSpeed = Rnd(0.1, 0.5)
  41.         PositionEntity fEntity, Rand(-50, 50), Rand(-50, 50), Rand(-50, 50)
  42.         RotateEntity fEntity, 0, Rand(0, 360), Rand(-45, 45)
  43.         fishes[i] = f
  44. Next
  45.  
  46. ;Gameloop
  47. While Not KeyHit(1)
  48.         TurnEntity campiv, 0, -MouseXSpeed(), 0
  49.         For i = 0 To 99
  50.                 AnimateFish(fishes[i]Entity, an + 90*i)
  51.                 MoveEntity fishes[i]Entity, fishes[i]Speed, 0, 0
  52.                 TurnEntity fishes[i]Entity, 0, fishes[i]Yaw, 0
  53.         Next
  54.        
  55.         an = an + Rnd(10, 20)
  56.         an = an Mod 360
  57.        
  58.         MoveMouse 320, 240
  59.         RenderWorld
  60.         Flip
  61. Wend
  62.  
  63. ;Create a fish!
  64. Function CreateFish()
  65.         mesh = CreateMesh()
  66.         surf = CreateSurface(mesh)
  67.        
  68.         v0 = AddVertex(surf, 1, 0, 0)
  69.         v1 = AddVertex(surf, 0, -0.5, 0)
  70.         v2 = AddVertex(surf, 0, 0.5, 0)
  71.         v3 = AddVertex(surf, -1, 0, -0.5)
  72.         v4 = AddVertex(surf, -1, 0, 0.5)
  73.         v5 = AddVertex(surf, -2, 0.5, 0)
  74.         v6 = AddVertex(surf, Rand(-2.5, -1), Rand(1, 1.2), 0)
  75.         v7 = AddVertex(surf, -2, -0.5, 0)
  76.         v8 = AddVertex(surf, -3, -0.8, 0)
  77.         v9 = AddVertex(surf, -3.5, -0.5, 0)
  78.         v10 = AddVertex(surf, -3.5, 1.5, 0)
  79.         v11 = AddVertex(surf, -1, Rand(0.5, -1), 0)
  80.        
  81.         ;Head
  82.         AddTriangle surf, v3, v2, v0
  83.         AddTriangle surf, v0, v2, v4
  84.         AddTriangle surf, v1, v3, v0
  85.         AddTriangle surf, v0, v4, v1
  86.         AddTriangle surf, v3, v5, v2
  87.         AddTriangle surf, v2, v5, v4
  88.  
  89.         ;Fin
  90.         AddTriangle surf, v5, v6, v2
  91.         AddTriangle surf, v2, v6, v5
  92.        
  93.         ;Body
  94.         AddTriangle surf, v3, v7, v5
  95.         AddTriangle surf, v5, v7, v4
  96.         AddTriangle surf, v3, v1, v7
  97.         AddTriangle surf, v7, v1, v4
  98.        
  99.         ;Back-fin
  100.         AddTriangle surf, v7, v10, v5
  101.         AddTriangle surf, v5, v10, v7
  102.         AddTriangle surf, v7, v9, v10
  103.         AddTriangle surf, v10, v9, v7
  104.         AddTriangle surf, v8, v9, v7
  105.         AddTriangle surf, v7, v9, v8
  106.        
  107.         ;Under-fin
  108.         AddTriangle surf, v11, v7, v1
  109.         AddTriangle surf, v1, v7, v11
  110.  
  111.         UpdateNormals mesh
  112.        
  113.         ;Color fish!
  114.         For i = 0 To 10
  115.                 VertexColor surf, i, Rnd(0, 255), Rnd(0, 255), Rnd(0, 255)
  116.         Next
  117.         EntityFX mesh, 2
  118.         Return mesh
  119. End Function
  120.  
  121. ;Stops a fish's animation!
  122. Function StopFish(mesh)
  123.         surf = GetSurface(mesh, 1)
  124.         VertexCoords surf, 10, VertexX(surf, 10), VertexY(surf, 10), 0
  125.         VertexCoords surf, 9, VertexX(surf, 9), VertexY(surf, 9), 0
  126.         VertexCoords surf, 8, VertexX(surf, 8), VertexY(surf, 8), 0
  127.         VertexCoords surf, 6, VertexX(surf, 6), VertexY(surf, 6), 0
  128.         VertexCoords surf, 5, VertexX(surf, 5), VertexY(surf, 5), 0
  129.         VertexCoords surf, 7, VertexX(surf, 7), VertexY(surf, 7), 0
  130.         VertexCoords surf, 11, VertexX(surf, 11), VertexY(surf, 11), 0
  131.        
  132.         VertexCoords surf, 3, VertexX(surf, 3), VertexY(surf, 3), -0.5
  133.         VertexCoords surf, 4, VertexX(surf, 4), VertexY(surf, 4), 0.5
  134.         VertexCoords surf, 2, VertexX(surf, 2), VertexY(surf, 2), 0
  135.         VertexCoords surf, 1, VertexX(surf, 1), VertexY(surf, 1), 0
  136. End Function
  137.  
  138. ;Animate a fish!
  139. Function AnimateFish(mesh, an#)
  140.         surf = GetSurface(mesh, 1)
  141.         VertexCoords surf, 10, VertexX(surf, 10), VertexY(surf, 10), Sin(an)*0.5
  142.         VertexCoords surf, 9, VertexX(surf, 9), VertexY(surf, 9), Sin(an)*0.5
  143.         VertexCoords surf, 8, VertexX(surf, 8), VertexY(surf, 8), Sin(an)*0.5
  144.         VertexCoords surf, 6, VertexX(surf, 6), VertexY(surf, 6), Cos(an)*-0.2
  145.         VertexCoords surf, 5, VertexX(surf, 5), VertexY(surf, 5), Cos(an)*-0.2
  146.         VertexCoords surf, 7, VertexX(surf, 7), VertexY(surf, 7), Cos(an)*-0.2
  147.         VertexCoords surf, 11, VertexX(surf, 11), VertexY(surf, 11), Cos(an)*-0.2
  148.                
  149.         VertexCoords surf, 3, VertexX(surf, 3), VertexY(surf, 3), -0.5+Cos(an)*-0.1
  150.         VertexCoords surf, 4, VertexX(surf, 4), VertexY(surf, 4), 0.5+Cos(an)*-0.1
  151.         VertexCoords surf, 2, VertexX(surf, 2), VertexY(surf, 2), Sin(an)*-0.1
  152.         VertexCoords surf, 1, VertexX(surf, 1), VertexY(surf, 1), Sin(an)*-0.1
  153. End Function


Comments :


Guy Fawkes(Posted 1+ years ago)

 Ur fish code PAWNS! can u edit it so if the fishes "hear" or "see" the camera, they get scared and swim away? that would be SO COOL! =D


Nate the Great(Posted 1+ years ago)

 cool lol, I wish my neural network code was in b3d so I could give em some brains lol


Stevie G(Posted 1+ years ago)

 Excellent!


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal