Page 1 of 3

PureBlock (Bloxorz) : To be continued

Posted: Sun Aug 26, 2007 6:20 pm
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
;}

Posted: Sun Aug 26, 2007 6:28 pm
by Fluid Byte
Excellent! Image

Posted: Sun Aug 26, 2007 6:40 pm
by Derek
Nice bit of coding. :)

Posted: Mon Aug 27, 2007 3:49 am
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)

Posted: Sat Sep 08, 2007 10:35 pm
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 .

Posted: Sun Sep 09, 2007 9:05 am
by Comtois
Added switch Teleport. and 14 maps.

Posted: Tue Sep 11, 2007 4:09 am
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!

Posted: Tue Sep 11, 2007 3:09 pm
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

Posted: Tue Sep 11, 2007 3:23 pm
by Fangbeast
This is excellent work, I have been playing for a while now, to relax.

Posted: Tue Sep 11, 2007 3:47 pm
by rsts
Excellent work and extremely entertaining :D

What a wonderful contribution.

cheers

Posted: Tue Sep 11, 2007 4:57 pm
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

Posted: Tue Sep 11, 2007 5:32 pm
by Kaeru Gaman
on 4.02 the level isn raised, always again the first level.

Posted: Tue Sep 11, 2007 7:34 pm
by Psychophanta
That is nice. I like simple graphics but full of new ideas.

Posted: Wed Sep 12, 2007 4:00 am
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!)

Posted: Mon Sep 17, 2007 9:53 am
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.