Page 1 of 1

Tetris piece crash

Posted: Mon Apr 10, 2023 4:02 am
by SPH
When creating a Tetris piece, I have a lag between the crates.
I can turn it all over the place, but I don't understand....
Bug or no bug?

THANKS :idea:

Code: Select all

EnableExplicit

Define Dim camera(1),Dim light(1),Dim mesh(20),Dim material(1),Dim entity(20)
Define xx.f, yy.f, zz.f, xx2.f, yy2.f, zz2.f
Define i.l,u.l,n.l,x.l,y.l,taille_x,taille_y,piece,piece_tetris
Define b.b

Define mesh, entity

ExamineDesktops()
InitEngine3D(#PB_Engine3D_DebugLog) : InitSprite() : InitKeyboard() : InitMouse()
OpenScreen(DesktopWidth(0), DesktopHeight(0), 32, "3D de base")
Add3DArchive(#PB_Compiler_Home + "examples\3D\Data\Textures", #PB_3DArchive_FileSystem)

; Camera
camera(0) = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(camera(0), 0, 6, 40) 
CameraLookAt(camera(0), 0, 0, 0)
RotateCamera(camera(0), 0 ,0 ,0)

; Si pas de ciel, couleur de fond
CameraBackColor(camera(0), RGB(184, 134, 11))

; Lumiere
light(0) = CreateLight(#PB_Any, RGB(255, 255, 255), -100, 100, 0)

; Création du premier cube

material(0) = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any, "caisse.png")))

Dim piece.b(3,3) ; une pièce tetris dans un Dim
For y=0 To 3
  For x=0 To 3
    Read.b piece(x,y)
  Next
Next
;;;;;;

i=0 ; creation de 4 caisses
For y=0 To 3
  For x=0 To 3
    If piece(x,y)=1
      mesh(i) = CreateCube(#PB_Any, 1)
      entity(i) = CreateEntity(#PB_Any, MeshID(mesh(i)), MaterialID(material(0)))
      MoveEntity(entity(i), x, y, 0)
      i+1
    EndIf
  Next
Next

;;;;;; lier 4 caisses pour en faire une piece tetris  
For u=1 To 3
  AttachEntityObject(entity(0), "", EntityID(entity(u)))
Next


; Boucle 3D
yy=-0.02
Repeat
  ExamineKeyboard()
  ExamineMouse()

  MoveEntity(entity(0), 0, yy, 0)
  RenderWorld() 
  FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(#PB_MouseButton_Middle)
End

;{

DataSection
  ;;;
  Data.b 0,0,0,0
  Data.b 1,1,1,1
  Data.b 0,0,0,0
  Data.b 0,0,0,0
  ;;;
EndDataSection
;}


Re: Tetris piece crash

Posted: Mon Apr 10, 2023 7:42 pm
by DK_PETER
Remove the Entity() inside the IsEntity().
Simply check the entity by value alone.

Re: Tetris piece crash

Posted: Tue Apr 11, 2023 10:26 am
by SPH
Thank you for your answer.

Could you correct the code and post it? (because I don't know where the error is)

Re: Tetris piece crash

Posted: Tue Apr 11, 2023 12:20 pm
by PeDe
When the K key is pressed, you release 'Entity(0)'. But in the next line you access it again with 'MoveEntity(...)'. Here also belongs a check or something like that.

Code: Select all

67:  If KeyboardReleased(#PB_Key_K) And IsEntity(Entity(0))
68:    FreeEntity(Entity(0)) 
69:  EndIf
70:  
71:  MoveEntity(entity(0), 0, yy, 0)
Peter

Re: Tetris piece crash

Posted: Tue Apr 11, 2023 3:53 pm
by SPH
Thank you for your answer.
But I wasn't talking about the K key.
Corrected code (and shortcuts) on post 1
The descending Tetris piece is broken. why?

Code: Select all

  Data.b 0,0,0,0
  Data.b 1,1,1,1
  Data.b 0,0,0,0
  Data.b 0,0,0,0

Re: Tetris piece crash

Posted: Tue Apr 11, 2023 7:37 pm
by Caronte3D
I think exists a bug in the 3D Engine on the MoveEntity, because no matter what flags you use, the move is ever relative (I think).
I copy several lines:
MoveEntity(entity(i), x, y, 0,#PB_Absolute|#PB_World)
MoveEntity(entity(i), x, y, 0,#PB_Absolute|#PB_World)
MoveEntity(entity(i), x, y, 0,#PB_Absolute|#PB_World)
MoveEntity(entity(i), x, y, 0,#PB_Absolute|#PB_World)
MoveEntity(entity(i), x, y, 0,#PB_Absolute|#PB_World)
MoveEntity(entity(i), x, y, 0,#PB_Absolute|#PB_World)
MoveEntity(entity(i), x, y, 0,#PB_Absolute|#PB_World)
If I understand ok, the entity(i) should be in the same coordinates, no matter how many MoveEntity was done, because the flags are absolute, but on each line the entity moves more and more.