Tetris piece crash

Everything related to 3D programming
User avatar
SPH
Enthusiast
Enthusiast
Posts: 571
Joined: Tue Jan 04, 2011 6:21 pm

Tetris piece crash

Post 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
;}

Last edited by SPH on Tue Apr 11, 2023 3:51 pm, edited 1 time in total.

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Tetris piece crash

Post by DK_PETER »

Remove the Entity() inside the IsEntity().
Simply check the entity by value alone.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 571
Joined: Tue Jan 04, 2011 6:21 pm

Re: Tetris piece crash

Post by SPH »

Thank you for your answer.

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

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
PeDe
Enthusiast
Enthusiast
Posts: 284
Joined: Sun Nov 26, 2017 3:13 pm

Re: Tetris piece crash

Post 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
User avatar
SPH
Enthusiast
Enthusiast
Posts: 571
Joined: Tue Jan 04, 2011 6:21 pm

Re: Tetris piece crash

Post 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

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Tetris piece crash

Post 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.
Post Reply