November 25, 2020, 08:54:41 AM

Author Topic: [bb] sphere_and_box by RiverRatt [ 1+ years ago ]  (Read 606 times)

Offline BlitzBot

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

Description : sphere pushing a box around

Code :
Code: BlitzBasic
  1. ;sphere moveing a box around by Matt Anthony
  2. ;This code was made with the help of people on the blitz
  3. ;forum and is free to all
  4.  
  5. Graphics3D 640,480,16
  6. SetBuffer BackBuffer()
  7.  
  8. Const cube_col=1
  9. Const sphere_col=2
  10.  
  11.  
  12. light= CreateLight()
  13.  
  14.  
  15. camera=CreateCamera()
  16. PositionEntity camera,0,40,0
  17.  
  18. Type cubedata
  19. Field x#,y#
  20. End Type
  21.  
  22. Type circledata
  23. Field x#,y#
  24. End Type
  25.  
  26. AutoMidHandle =True
  27.  
  28. box.cubedata = New cubedata
  29. boxx#=-10
  30. boxy#=40
  31. cube= CreateCube()
  32. ScaleEntity cube,3,3,3
  33. PositionEntity cube,boxx#,boxy#,20
  34. EntityColor cube,255,0,0
  35. EntityType cube,cube_col;collisionccccccccccccccccccccccccccccc
  36.  
  37. ;player
  38. circle.circledata = New circledata
  39. circlex#=10
  40. circley#=40
  41. sphere= CreateSphere()
  42. EntityColor sphere,0,0,255
  43.  
  44. PositionEntity sphere,circlex#,circley#,20
  45. EntityType sphere,sphere_col;collisionccccccccccccccccccccccccccccc
  46.  
  47. Collisions sphere_col,cube_col,2,3
  48.  
  49. Global rsx#= .25  ;right movment value
  50. Global lsx#=-.25  ;left movment value
  51. Global usy#=-.25  ;up movement value
  52. Global dsy#= .25  ;down movement value
  53. ;Const bx#=1
  54. While Not KeyHit(1);Main MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  55.  
  56. If KeyDown(30) MoveEntity sphere,lsx#,0,0
  57. If KeyDown(32) MoveEntity sphere,rsx#,0,0
  58. If KeyDown(17) MoveEntity sphere,0,dsy#,0
  59. If KeyDown(31) MoveEntity sphere,0,usy#,0
  60. UpdateWorld()
  61. RenderWorld()
  62.  
  63. Color 255,255,0
  64. Text 335,500,"Collision Detection"
  65. Text 10,20,circlex + circley
  66. If EntityCollided(sphere,cube_col);collision
  67.         Text 370,80,"Collided !!!"
  68.  
  69.         If EntityX(sphere)+1.5 > EntityX(cube) Then ; Check on wich side the sphere is
  70.  
  71.                 TranslateEntity cube,-.25,0,0
  72.  
  73.         EndIf
  74.  
  75.         If EntityX(sphere)-1.5 < EntityX(cube) Then ; Check on wich side the sphere is
  76.  
  77.                 TranslateEntity cube,.25,0,0
  78.         EndIf
  79. EndIf
  80.  
  81.        
  82. If EntityCollided(sphere,cube_col);collision
  83.         Text 370,80,"Collided !!!"
  84.        
  85.         If EntityY(sphere)+1.5 < EntityY(cube) Then ; Check on wich side the sphere is
  86.  
  87.                 TranslateEntity cube,0,.25,0
  88.         EndIf
  89.  
  90.         If EntityY(sphere)-1.5 > EntityY(cube) Then ; Check on wich side the sphere is
  91.  
  92.                 TranslateEntity cube,0,-.25,0
  93.         EndIf
  94.  
  95.  
  96.  
  97.        
  98.  
  99. EndIf
  100.  
  101.  
  102. Flip
  103. Wend ;End of Main MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  104. End


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal