PureBlock (Bloxorz) : To be continued

Advanced game related topics
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

PureBlock (Bloxorz) : To be continued

Post by Comtois »

[EDIT]
DOWNLOAD last version (27 sept 2007) here:
- Code source included.
- 33 maps
- Sound added
- Added editor 3D --> Few bugs fixed
http://herved25.free.fr/sources/PureBlock.zip

Image
____________________
As i like this game, today i started to code it, here is my first try :

Code: Select all

;Comtois
;PB 4.10 Le 26/08/07

EnableExplicit

InitEngine3D()
InitSprite()
InitKeyboard()
 
Enumeration
  #Nord
  #Est
  #Sud
  #Ouest
  #Vertical
EndEnumeration

#Taille=12
#Taille2 = #Taille/2

Structure f_Vecteur
  x.f
  y.f
  z.f
EndStructure

Structure i_Vecteur
  x.l
  y.l
  z.l
EndStructure

Structure s_Cube
  Angle.f
  p.f_Vecteur
  s.f_Vecteur
  t.f_Vecteur  
  Type.l
  Sens.l
  Case1.I_Vecteur
  Case2.I_Vecteur
  Origine.I_Vecteur
EndStructure

Structure s_Vertex
  px.f
  py.f
  pz.f
  nx.f
  ny.f
  nz.f
  u.f
  v.f
EndStructure

Global Cube.s_Cube, Px.l, Pz.l, Perdu.l, MapX.l, MapZ.l
Define.l Options, i, j, Tombe

Restore Niveau1
Read MapX
Read MapZ
Dim Map(MapX+1,MapZ+1)
Read Cube\Origine\X
Read Cube\Origine\Z
For j=1 To MapZ
  For i = 1 To MapX
    Read Map(i,j)
  Next i  
Next j

;Initialise le cube
Cube\p\x=Cube\Origine\X*#Taille
Cube\p\y=#Taille
Cube\p\z=Cube\Origine\Z*#Taille
Cube\Type = #Vertical
Cube\Sens = #Vertical 

;- Ouverture de la fenêtre et de l'écran
OpenScreen(1280,1024,32,"Test")

;- Declaration des procédures
Declare MakeMesh()
Declare Animation()

Macro TEXTURE(Texture, Couleur)
  CreateTexture(Texture, 128, 128)
  ;Remplissage de la texture en blanc
  StartDrawing(TextureOutput(Texture))
    Box(0, 0, TextureWidth(Texture), TextureHeight(Texture), Couleur)
    DrawingMode(#PB_2DDrawing_Outlined)
    Box(0, 0, TextureWidth(Texture), TextureHeight(Texture), $FF0000)
  StopDrawing()
EndMacro
Macro GAGNE()
  Repeat
    tombe - 1
    MoveEntity(#Entity, 0, -1, 0)
    RenderWorld()
    FlipBuffers()   
  Until Tombe < -150
  tombe = 0
EndMacro

;-Mesh
#Mesh = 0

CreateMesh(#Mesh, 100)
Options = #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate 
SetMeshData(#Mesh, Options      , ?Sommets, 24)
SetMeshData(#Mesh, #PB_Mesh_Face, ?Triangles, 12)

#MeshN=1
CreateMesh(#MeshN, 100)
Options = #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate 
SetMeshData(#MeshN, Options      , ?Sommets, 24)
SetMeshData(#MeshN, #PB_Mesh_Face, ?Triangles, 12)

;-Textures
#Texture = 0
Texture(#Texture, $BA8E3A)

#TextureSol = 1
Texture(#TextureSol, $FFFFFF)

;-Matière
#Matiere = 0
CreateMaterial(#Matiere, TextureID(#Texture))

#MatiereSol = 1
CreateMaterial(#MatiereSol, TextureID(#TextureSol))

;-Entity
#Entity = 0
CreateEntity(#Entity, MeshID(#Mesh), MaterialID(#Matiere))
MakeMesh()

#EntitySol = 1
For j=1 To MapZ
  For i=1 To MapX
    If Map(i,j)=1
      Map(i,j)= CreateEntity(#PB_Any, MeshID(#MeshN), MaterialID(#TextureSol))
      ScaleEntity(Map(i,j), #Taille, 2, #Taille) 
      EntityLocate(Map(i,j), i*#Taille, -1, j*#Taille)
    EndIf
  Next i
Next j      

;-Camera
#Camera = 0
CreateCamera(#Camera, 0, 0, 100, 100)
CameraLocate(#Camera, 0, 110, 16*#Taille)
CameraLookAt(#Camera, 5*#Taille, 0, 3*#Taille) 
   
;-Light
AmbientColor(RGB(185,185,185))
CreateLight(0,$FFFFFF,500,500,500)

;- **** MAIN ****

Repeat
 
  If ExamineKeyboard() 
   
    If Cube\Sens = #Vertical
      If KeyboardPushed(#PB_Key_Left)
        Cube\Sens = #Ouest : MakeMesh()
      ElseIf KeyboardPushed(#PB_Key_Right)
        Cube\Sens = #Est   : MakeMesh()
      ElseIf KeyboardPushed(#PB_Key_Up)
        Cube\Sens = #Nord  : MakeMesh()
      ElseIf KeyboardPushed(#PB_Key_Down)
        Cube\Sens = #Sud   : MakeMesh()
      EndIf
    EndIf
         
  EndIf
 
  Animation()
 
  ;Test position
  Perdu = #False
  If Cube\type = #Vertical
    Px = Cube\p\x / #Taille
    Pz = Cube\p\z / #Taille
    If Map(Px, Pz)=2
      GAGNE()
      Perdu = #True
    ElseIf Map(Px, Pz)=0
      Perdu = #True
    EndIf
  ElseIf Cube\type = #Nord Or Cube\type = #Sud
    Px = Cube\p\x / #Taille
    Pz = (Cube\p\z + #Taille2) / #Taille
    If Map(Px, Pz)=0
      Perdu = #True
    EndIf
    Pz = (Cube\p\z - #Taille2) / #Taille
    If Map(Px, Pz)=0
      Perdu = #True
    EndIf
  ElseIf Cube\type = #Est Or Cube\type = #Ouest
    Px = (Cube\p\x + #Taille2) / #Taille
    Pz = Cube\p\z  / #Taille
    If Map(Px, Pz)=0
      Perdu = #True
    EndIf
    Px = (Cube\p\x - #Taille2) / #Taille
    If Map(Px, Pz)=0
      Perdu = #True
    EndIf
  EndIf       
                 
         
  If Perdu
    ;Initialise le cube
    Cube\p\x=Cube\Origine\X*#Taille
    Cube\p\y=#Taille
    Cube\p\z=Cube\Origine\Z*#Taille
    Cube\Type = #Vertical
    Cube\Sens = #Vertical  
    CreateEntity(#Entity, MeshID(#Mesh), MaterialID(#Matiere))
    MakeMesh()
  EndIf
 
  RenderWorld()
 
  FlipBuffers()
 
Until KeyboardPushed(#PB_Key_Escape)


Procedure MakeMesh()
  Define. l Options, i
  Protected *Sommet, *Face, *Ptr.s_Vertex
   
  Options = #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate 
  *Sommet=AllocateMemory(SizeOf(s_Vertex)*24) ; 24 sommets et 36 octets par sommet
  *Face=AllocateMemory(6*12) ; 12 triangles et 6 octets par triangle
 
  CopyMemory(?Sommets,*Sommet,SizeOf(s_Vertex)*24)
  CopyMemory(?Triangles,*Face,6*12)
  With Cube
  Select \type
    Case #Vertical
      \s\x = 1 : \s\y = 2 : \s\z = 1
    Case #Nord, #Sud
      \s\x = 1 : \s\y = 1 : \s\z = 2
    Case #Ouest, #Est
      \s\x = 2 : \s\y = 1 : \s\z = 1
  EndSelect
 
  Select \Sens
    Case #Nord
      \t\x = 0.5 : \t\y = 0.5 : \t\z = 0.5
    Case #Sud
      \t\x = 0.5 : \t\y = 0.5 : \t\z = -0.5
    Case #Ouest
      \t\x = 0.5 : \t\y = 0.5 : \t\z = 0
    Case #Est
      \t\x = -0.5 : \t\y = 0.5 : \t\z = 0
    Case #Vertical
      \t\x = 0 : \t\y = 0.5 : \t\z = 0 
  EndSelect 
   
  *Ptr=*Sommet
  For i = 1 To 24
    *Ptr\px = (*Ptr\px + \t\x) * \s\x*#Taille
    *Ptr\py = (*Ptr\py + \t\y) * \s\y*#Taille
    *Ptr\pz = (*Ptr\pz + \t\z) * \s\z*#Taille
    *Ptr + SizeOf(s_Vertex) 
  Next i
     
  SetMeshData(#Mesh, Options      , *Sommet, 24)
  SetMeshData(#Mesh, #PB_Mesh_Face, *Face  , 12)
   
  EntityLocate(#Entity, \p\x-\t\x*\s\x*#Taille, 0, \p\z-\t\z*\s\z*#taille)
  EndWith
EndProcedure

Procedure Animation()
  Define.f Delta
  Delta = 4.5
  
  Select Cube\Sens

    Case #Ouest
      Cube\Angle + Delta
      RotateEntity(#Entity,0,0,Cube\Angle)

      If Int(Cube\Angle) = 90
        Cube\Angle = 0 : Cube\Sens = #Vertical
        If Cube\Type = #Vertical
          Cube\Type = #Ouest
          Cube\p\x - 1.5*#Taille
        ElseIf Cube\Type = #Est Or Cube\Type = #Ouest
          Cube\Type = #Vertical
          Cube\p\x - 1.5*#Taille
        Else 
          Cube\p\x - #Taille
        EndIf
      EndIf
     
    Case #Est
      Cube\Angle - Delta
      RotateEntity(#Entity,0,0,Cube\Angle)
   
      If Int(Cube\Angle) = -90
        Cube\Angle = 0 : Cube\Sens = #Vertical
         
        If Cube\Type = #Vertical
          Cube\Type = #Est
          Cube\p\x + 1.5*#Taille
        ElseIf Cube\Type = #Est Or Cube\Type = #Ouest
          Cube\Type = #Vertical
          Cube\p\x + 1.5*#Taille
        Else
          Cube\p\x + #Taille 
        EndIf
       
      EndIf   
     
  Case #Nord
      Cube\Angle - Delta
      RotateEntity(#Entity,0,Cube\Angle,0)

      If Int(Cube\Angle) = -90
        Cube\Angle = 0 : Cube\Sens = #Vertical
 
        If Cube\Type = #Vertical
          Cube\Type = #Nord
          Cube\p\z - 1.5*#Taille
        ElseIf Cube\Type = #Nord Or Cube\Type = #Sud
          Cube\Type = #Vertical
          Cube\p\z - 1.5*#Taille
        Else
          Cube\p\z - #Taille 
        EndIf
       
      EndIf
           
  Case #Sud
      Cube\Angle + Delta
      RotateEntity(#Entity,0,Cube\Angle,0)
     
      If Int(Cube\Angle) = 90
        Cube\Angle = 0 :  Cube\Sens = #Vertical
 
        If Cube\Type = #Vertical
          Cube\Type = #Sud
          Cube\p\z + 1.5*#Taille
        ElseIf Cube\Type = #Nord Or Cube\Type = #Sud
          Cube\Type = #Vertical
          Cube\p\z + 1.5*#Taille
        Else
          Cube\p\z + #Taille 
        EndIf 

      EndIf 
  EndSelect 
     
EndProcedure

;{ Définition du cube
DataSection
Sommets:
;Dessus 0 à 3
Data.f -0.5,0.5,-0.5
Data.f 0,1,0
Data.f 0,0

Data.f 0.5,0.5,-0.5
Data.f 0,1,0
Data.f 0,1

Data.f 0.5,0.5,0.5
Data.f 0,1,0
Data.f 1,1

Data.f -0.5,0.5,0.5
Data.f 0,1,0
Data.f 1,0

;Dessous 4 à 7
Data.f -0.5,-0.5,0.5
Data.f 0,-1,0
Data.f 0,0

Data.f 0.5,-0.5,0.5
Data.f 0,-1,0
Data.f 0,1

Data.f 0.5,-0.5,-0.5
Data.f 0,-1,0
Data.f 1,1

Data.f -0.5,-0.5,-0.5
Data.f 0,-1,0
Data.f 1,0

;Devant 8 à 11
Data.f -0.5,0.5,0.5
Data.f 0,0,1
Data.f 0,0

Data.f 0.5,0.5,0.5
Data.f 0,0,1
Data.f 0,1

Data.f 0.5,-0.5,0.5
Data.f 0,0,1
Data.f 1,1

Data.f -0.5,-0.5,0.5
Data.f 0,0,1
Data.f 1,0

;Derrière 12 à 15
Data.f 0.5,0.5,-0.5
Data.f 0,0,-1
Data.f 0,0

Data.f -0.5,0.5,-0.5
Data.f 0,0,-1
Data.f 0,1

Data.f -0.5,-0.5,-0.5
Data.f 0,0,-1
Data.f 1,1

Data.f 0.5,-0.5,-0.5
Data.f 0,0,-1
Data.f 1,0

;Cote gauche 16 à 19
Data.f -0.5,0.5,-0.5
Data.f -1,0,0
Data.f 0,0

Data.f -0.5,0.5,0.5
Data.f -1,0,0
Data.f 0,1

Data.f -0.5,-0.5,0.5
Data.f -1,0,0
Data.f 1,1

Data.f -0.5,-0.5,-0.5
Data.f -1,0,0
Data.f 1,0

;Cote droit 20 à 23
Data.f 0.5,0.5,0.5
Data.f 1,0,0
Data.f 0,0

Data.f 0.5,0.5,-0.5
Data.f 1,0,0
Data.f 0,1

Data.f 0.5,-0.5,-0.5
Data.f 1,0,0
Data.f 1,1

Data.f 0.5,-0.5,0.5
Data.f 1,0,0
Data.f 1,0

Triangles:
;Face en Haut
Data.w 2,1,0
Data.w 0,3,2
;Face en Bas
Data.w 6,5,4
Data.w 4,7,6
;Face Avant
Data.w 10,9,8
Data.w 8,11,10
;Face Arrière
Data.w 14,13,12
Data.w 12,15,14
;Face Gauche
Data.w 18,17,16
Data.w 16,19,18
;Face Droite
Data.w 22,21,20
Data.w 20,23,22

Niveau1:
Data.l 10,6
Data.l 2, 2
Data.l 1,1,1,0,0,0,0,0,0,0
Data.l 1,1,1,1,1,1,0,0,0,0
Data.l 1,1,1,1,1,1,1,1,1,0
Data.l 0,1,1,1,1,1,1,1,1,1
Data.l 0,0,0,0,0,1,1,2,1,1
Data.l 0,0,0,0,0,0,1,1,1,0
Niveau2:
Data.l 15,6
Data.l 2, 5
Data.l 0,0,0,0,0,0,1,1,1,1,0,0,1,1,1
Data.l 1,1,1,1,0,0,1,1,4,1,0,0,1,2,1
Data.l 1,1,3,1,0,0,1,1,1,1,0,0,1,1,1
Data.l 1,1,1,1,0,0,1,1,1,1,0,0,1,1,1
Data.l 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data.l 1,1,1,1,0,0,1,1,1,1,0,0,0,0,0
EndDataSection
;}
Last edited by Comtois on Fri Sep 28, 2007 9:16 am, edited 10 times in total.
Please correct my english
http://purebasic.developpez.com/
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Excellent! Image
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Nice bit of coding. :)
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Fantastic bit of coding... Finally a level I can win! (i have found 2 ways off so far!) :D

Added a bit to count Keyresses on my own... Cannot make it load the second level yet... Hmmm

Lets share some maps! 8)
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

Rook Zimbabwe wrote:Lets share some maps! 8)
Ok , now there is 6 maps.

http://herved25.free.fr/sources/PureBlock.zip 100% PureBasic + Ogre, yes it is possible to make 3D game with PB :)

I forgot the most important switch (teleport) , i will add it for the next time .
Please correct my english
http://purebasic.developpez.com/
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

Added switch Teleport. and 14 maps.
Please correct my english
http://purebasic.developpez.com/
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Comtois... this is FANTASTIC work! :D Have you given any thought to sounds to be used? I have some I have made that you might could use... a CLICK for the switch activating... possibly a electronic break apaprt for the map change... if you wanted.

I did have a very small suggestion: The distance that the blox drops before it goes to the new level is long... maybe the block could drop faster? Maybe a shorter distance??

I did discover that the texture on the BLOX changes at times... I had suspected this issue abut not until I cahnged the texture to a linear one did I see what happened... :D

It does not seem to look for the Engine3D.dll lib in the same folder... I am having difficulty running the new version. I do own PB 4.02 and a licensed copy at that! :D

Keep up the good work!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

Rook Zimbabwe wrote:Have you given any thought to sounds to be used? I have some I have made that you might could use... a CLICK for the switch activating... possibly a electronic break apaprt for the map change... if you wanted.
Why not, i can give a try to your sounds :)
I did have a very small suggestion: The distance that the blox drops before it goes to the new level is long... maybe the block could drop faster? Maybe a shorter distance??
Yes i will change that.
I did discover that the texture on the BLOX changes at times... I had suspected this issue abut not until I cahnged the texture to a linear one did I see what happened... :D
You discovered the tip :)
Ok so i changed the texture, now the BLOX is translucent.
It does not seem to look for the Engine3D.dll lib in the same folder... I am having difficulty running the new version. I do own PB 4.02 and a licensed copy at that! :D
I copied engine3D.dll and stlport_vc646.dll in windows\System32 .

New version :
Added few sounds
Maps 15 and 16.
BLOX is translucent.
Counter of move.

http://herved25.free.fr/sources/PureBlock.zip
Please correct my english
http://purebasic.developpez.com/
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4792
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

This is excellent work, I have been playing for a while now, to relax.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Excellent work and extremely entertaining :D

What a wonderful contribution.

cheers
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

Got to level 17!

You need an end of levels routine instead of the crash :D

Very nice, but I think you should expand upon the original game a little.

Suggestions....

Water could be used, which single blocks can float on!
You could have multi levels, with an elevator!
Crumbling floor, only pass once!

Bug....

More of a bad gfx effect... when the block is only supported on one end the block should roll over the edge instead of current effect.

Nice code though :D
Paid up PB User !
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

on 4.02 the level isn raised, always again the first level.
oh... and have a nice day.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

That is nice. I like simple graphics but full of new ideas.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

My only other suggestions:

#1: KEEP GOING!!! You can take this to a whole new level!!!

#2: maybe you should just put the DLL files in the game folder?

#3 OK I will set up a few links for sounds on my website and link here (all can use free!)
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

I added an editor 3D, the source code is available in the archiv.
All suggestions will be welcome.

To add an event
Click on a switch while pressing on key [SHIFT]
Then click on another block while pressing the key [CTRL]
Now you have two blocks selected.
Then click the right button of the mouse and choose an event, it will appear in the treeGadget () on your right.

To delete an Event, click on the TreeGadget() with left button of the mouse while pressing the key [DELETE].

Sorry for my bad english.
Please correct my english
http://purebasic.developpez.com/
Post Reply