November 28, 2020, 02:22:35 PM

Author Topic: [bb] Ai by The_Black_Knight [ 1+ years ago ]  (Read 700 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Ai by The_Black_Knight [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Ai
Author : The_Black_Knight
Posted : 1+ years ago

Description : This is an AI script that im using in my game.

Code :
Code: BlitzBasic
  1. ; Ai
  2. ; ------------------
  3. ;Made By Nathanael Senn - The Black Knight
  4. ;-------------------
  5.  
  6. ;Set Graphics
  7. Graphics3D 1024,768,32,1
  8. SetBuffer BackBuffer()
  9.  
  10. ; Create the timer to 60 fps
  11. frameTimer=CreateTimer(60)
  12.  
  13. ;Make Player Cam
  14. camera=CreateCamera()
  15.  
  16. ;Make light
  17. light=CreateLight()
  18. RotateEntity light,90,0,0
  19.  
  20. ;Set types
  21. enemy_type = 1
  22. box_type   = 2
  23. allie_type = 3
  24.  
  25. ;Make enemy
  26. enemy=CreateSphere()
  27. EntityType enemy,enemy_type
  28.  
  29. ;Make Allie
  30. allie=CreateSphere()
  31. EntityType allie,allie_Type
  32. PositionEntity allie, 130, 0, 130
  33.  
  34. ; Create cubes
  35. hun=100
  36. Dim cube(hun)
  37.  
  38. For box = 1 To 100
  39.  
  40.     If x >= 100
  41.         x=10
  42.         z=z+10
  43.     EndIf
  44.    
  45.     x=x+10
  46.     cube(box)=CreateCube()
  47.     EntityType cube(box),box_type
  48.     PositionEntity cube(box),x,0,z
  49.    
  50. Next
  51.  
  52. ;Make ran points
  53. nine = 9
  54. Dim ranpoint(nine)
  55.  
  56. For r=1 To 9
  57.  
  58.     If r = 1
  59.         x = 120
  60.         z = 120
  61.     EndIf
  62.    
  63.     If r = 2
  64.         x = 120
  65.         z = 55
  66.     EndIf
  67.    
  68.     If r = 3
  69.         x = 120
  70.         z = 0
  71.     End If
  72.  
  73.     If r = 4
  74.         x = 55
  75.         z = 120
  76.     End If
  77.  
  78.     If r = 5
  79.         x = 55
  80.         z = 55
  81.     EndIf
  82.  
  83.     If r = 6
  84.         x = 55
  85.         z = 0
  86.     EndIf
  87.  
  88.     If r = 7
  89.         x = 0
  90.         z = 120
  91.     EndIf
  92.    
  93.     If r = 8
  94.         x = 0
  95.         z = 55
  96.     EndIf
  97.    
  98.     If r = 9
  99.         x = 0
  100.         z = 0
  101.     End If
  102.    
  103.     ranpoint(r) = CreateCone()
  104.     PositionEntity ranpoint(r), x, 0, z
  105.    
  106. Next
  107.  
  108. ;Set enemy move
  109. moveenemy = 0
  110. moveallie = 0
  111.  
  112. ;Set Collisions
  113. Collisions enemy_type,box_type,2,2
  114. Collisions allie_type,box_type,2,2
  115.  
  116. ;Main Loop
  117. While Not KeyDown( 1 )
  118.  
  119. ;Set enemy and allie radius
  120. EntityRadius enemy ,1
  121. EntityRadius allie ,1
  122.  
  123. ;Set fps to 60
  124. WaitTimer(frameTimer) ; Pause until the timer reaches 60
  125. Cls
  126.  
  127. ;Add 1 to ran timer
  128. entime = entime + 1
  129. altime = altime + 1
  130.  
  131. ;Enemy ai
  132. If moveenemy = 1
  133.     MoveEntity enemy, 0, 0, .3
  134. EndIf
  135.  
  136. If moveenemy = 0
  137.     e = Rnd (1,9)
  138.     PointEntity enemy,ranpoint(e)
  139.     moveenemy = 1
  140. EndIf
  141.  
  142. For rote=1 To 100
  143.  
  144.     If entime >=25
  145.         PointEntity enemy,ranpoint(e)
  146.     EndIf
  147.  
  148. Next
  149.  
  150. If EntityDistance (enemy, ranpoint(e)) <= 1
  151.     moveenemy = 0
  152. EndIf
  153.  
  154. For rote=1 To 100
  155.    
  156.     If EntityDistance (enemy, cube(rote)) <=2
  157.         rot = Rnd(1,10)
  158.         entime = 0
  159.    
  160.     If rot <= 5
  161.         TurnEntity enemy, 0,45,0
  162.     EndIf
  163.    
  164.     If rot >= 6
  165.         TurnEntity enemy, 0,-45,0
  166.     EndIf
  167.    
  168.     EndIf
  169.  
  170. Next
  171.  
  172. ;Allie ai
  173. If moveallie = 1
  174.     MoveEntity allie, 0, 0, .3
  175. EndIf
  176.  
  177. If moveallie = 0
  178.     r = Rnd (1,9)
  179.     PointEntity allie,ranpoint(r)
  180.     moveallie = 1
  181. EndIf
  182.  
  183. For rote=1 To 100
  184.  
  185.     If altime >=25
  186.         PointEntity allie,ranpoint(r)
  187.     EndIf
  188.  
  189. Next
  190.  
  191. If alchase = 1 And altime >=25
  192.     PointEntity allie,enemy
  193. EndIf
  194.  
  195. If EntityDistance (allie, enemy) <=10
  196.     moveallie = 3
  197. EndIf  
  198.  
  199. If EntityDistance (allie, enemy) <=20 And EntityDistance (allie, enemy) >= 10 And EntityVisible ( allie,enemy )
  200.     alchase = 1
  201.     moveallie = 1
  202. EndIf
  203.  
  204. If EntityDistance (allie, ranpoint(r)) <= 1
  205.     moveallie = 0
  206. EndIf
  207.  
  208. For rote=1 To 100
  209.    
  210.     If EntityDistance (allie, cube(rote)) <=2
  211.         rot = Rnd(1,10)
  212.         altime = 0
  213.    
  214.     If rot <= 5
  215.         TurnEntity allie, 0,45,0
  216.     EndIf
  217.    
  218.     If rot >= 6
  219.         TurnEntity allie, 0,-45,0
  220.     EndIf
  221.    
  222.     EndIf
  223.  
  224. Next
  225.  
  226. ;Player movement
  227. If KeyDown( 200 )=True Then MoveEntity camera,0,0,1
  228. If KeyDown( 208 )=True Then MoveEntity camera,0,0,-1
  229. If KeyDown( 205)=True Then yaw#=yaw#-1
  230. If KeyDown( 203 )=True Then yaw#=yaw#+1
  231. If KeyDown( 45 )=True Then roll#=roll#-1
  232. If KeyDown( 44 )=True Then roll#=roll#+1
  233.  
  234. ;Mouse look
  235. myspd#=MouseYSpeed()*0.1
  236. mxspd#=MouseXSpeed()*.1
  237. MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
  238. yaw#=yaw#-mxspd#
  239. pitch#=pitch#+myspd#
  240. RotateEntity camera,pitch#,yaw#,roll#
  241.  
  242. UpdateWorld
  243. RenderWorld
  244. Text 0,20,"Roll: "+EntityRoll#( enemy )
  245. Text 0,35,"Roll: "+EntityYaw#( enemy )
  246. Text 0,50,"Roll: "+EntityPitch#( enemy )
  247. Flip
  248.  
  249. Wend
  250.  
  251. End


Comments :


_33(Posted 1+ years ago)

 Pretty nice and simple code.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal