Version mode graphique:
Code : Tout sélectionner
; ------------------------------------------------------------
; editeur de niveau 64 tiles - 2007 - source PureBasic 4.02
; France - Toulouse - H. Philippe - pseudo: beauregard
; mise à jour 05/10/2007
; ------------------------------------------------------------
UsePNGImageDecoder ()
If InitMouse ()=0 Or InitSprite ()=0 Or InitKeyboard ()=0 Or InitSprite3D ()=0 ; oui, il faut tout lui dire...
MessageRequester ( "Error" , "Can't open DirectX 7 or later" , 0)
End
EndIf
Enumeration ; ici, on donne un petit nom à nos sprites:
#CARO ; cadre se plaçant sur la grande image, afin de signifier le tile qu'il est possible de sélectionner.
#TILE_IMAGE ; la grande image regroupant toute les tiles.
EndEnumeration
Declare choixniv()
Declare ecriture()
Global NUM_X_TILE_SCREENS=8 ; largeur du niveau en nbre d'écran (exemple: 8 -> 8*1024=8192 colonnes).
Global NUM_Y_TILE_SCREENS=8 ; hauteur du niveau en nbre d'écran (exemple: 8 -> 8*768=6144 lignes).
Global limitXarray ;limite X du niveau en cours: limitXarray=(NUM_X_TILE_SCREENS*16)-8-8
Global limitYarray ;limite Y du niveau en cours: limitYarray=(NUM_Y_TILE_SCREENS*12)-8-8
; largeur et hauteur des tiles ( 64*64).
Global TILE_WIDTH=64
Global TILE_HEIGHT=64
; 1024*768 semble être le bon choix du moment.
Global NUM_X_TILES=1024 / TILE_WIDTH ; 1024/64=16
Global NUM_Y_TILES=768 / TILE_HEIGHT ; 768/64=12
; ** The total number of tiles on X & Y axes ** Taille du terrain, X et Y **
Global TOTAL_NUM_X_TILES= NUM_X_TILES * NUM_X_TILE_SCREENS ; 16*8= 128 tiles en largeur.
Global TOTAL_NUM_Y_TILES= NUM_Y_TILES * NUM_Y_TILE_SCREENS ; 12*8= 96 tiles en hauteur.
If OpenScreen (1024, 768, 32, "editeur de niveau 64" )=0
MessageRequester ( "Error" , "Can't open a 1024*768 - 32 bit screen !" , 0)
End
EndIf
; et maintenant, voici un défilé de variables:
Global choixplan.l,choixniveau.l,Tempo1.l
Global Cauteur.l,visibl.l
; Cauteur -> choix de l'auteur. ; visibl -> grande image visible on non.
Global TILE_IMAGE ; pas besoin de commentaire là, si ?
Global MapSpeed.w=8; vitesse de défilement ( appui sur touche 1, 2, ou 3 pavé num)
Global MapDataFile$ ; utilisé pour vos fichier de sauvegarde pour vous niveau finement ciselé.
; le plus compliqué: un tableau à 2 dimensions ( coordonnée X et Y)
Global Dim ArrayGrid.w(TOTAL_NUM_X_TILES+9,TOTAL_NUM_Y_TILES+9)
; ne tremblez pas, ça va bien se passer.
Global SCROLL_X_PIXEL, SCROLL_Y_PIXEL ; bouger les tiles avec grâce
Global POS_Y_ARRAY, POS_X_ARRAY ; position par rapport au terrain
; pointeurI -> n°tile sélectionné librement par vos soins, avec le pointeur de la souris.
Global pointeurI.w, pointeurX.w, pointeurY.w
; image servant de repère, en se plaçant sur le tile de votre choix
; ( au dessus de la grande image en fonction de la position du curseur de votre souris):
CreateSprite ( #CARO , 64, 64, 0 )
StartDrawing ( SpriteOutput ( #CARO ))
BackColor ( RGB (0,0,0))
Box (0,0, 64, 64, RGB ( 255, 0, 0)):Box (1,1, 62, 62, RGB ( 255, 255, 255))
Box (2,2, 60, 60, RGB ( 0, 0, 0))
StopDrawing ()
Global steptileX
Global steptileY
; Et voici la grande image rassemblant toute les Tiles:
; gitiles -> taille de l'image: 512*512, le premier tile, en haut à gauche, étant le tiles 0 ( quasiment vide ( avec un léger cadre)).
;g comme grande ; i comme image; tiles comme vous voulez, c'est vous qui voyez.
;LoadSprite(#TILE_IMAGE, "Data\gitiles.png",0) ; là je l'ai désactivé, dans la cas où vous n'auriez pas d'image sous la main, alors...
; j'en fabrique une, rien que pour vos petits yeux fatigués:
CreateSprite ( #TILE_IMAGE , 512, 512, 0 )
StartDrawing ( SpriteOutput ( #TILE_IMAGE ))
BackColor ( RGB (0,0,0))
Box (0,0, 64, 64, RGB (19,5,210)):Box (1,1, 62, 62, RGB ( 0, 0, 0)); le fameux tile 0
For i=0 To 6
Box (64+(i*64),0, 64, 64, RGB ( 255-(i*10) , 255-(i*10) , 255-(i*10)))
Next
For i=0 To 7
Box (0+(i*64),64, 64, 64, RGB ( 255-(i*10) , 200-(i*10) , 0))
Next
For i=0 To 7
Box (0+(i*64),128, 64, 64, RGB ( 200-(i*10) , 255-(i*10) , 0))
Next
For i=0 To 7
Box (0+(i*64),192, 64, 64, RGB ( 255-(i*10) , 0, 255-(i*10)))
Next
For i=0 To 7
Box (0+(i*64),256, 64, 64, RGB ( 0, 255-(i*10) , 255-(i*10)))
Next
For i=0 To 7
Box (0+(i*64),320, 64, 64, RGB ( 0, 255-(i*10) , 0))
Next
For i=0 To 7
Box (0+(i*64),384, 64, 64, RGB ( 255-(i*10) , 255-(i*10) , 0))
Next
For i=0 To 7
Box (0+(i*64),448, 64, 64, RGB ( 0, 0, 255-(i*10) ))
Next
FrontColor ( RGB (224,224,224)):DrawText (32-4,32-8, "0"):DrawText (32+60,32-8, "1"); oui, ça commence en haut à gauche.
StopDrawing ()
MouseLocate(512-32,384-32)
; ******************************************************************************
; ************************* BOUCLE PRINCIPALE *************************
; ******************************************************************************
Repeat ; boucle principale
FlipBuffers (): ClearScreen ( RGB (0,0,0)); inséparable ces deux là.
ExamineMouse():ExamineKeyboard (); et ces deux là aussi.
If Cauteur<2; pour que les choses sérieuses commencent, il faut d'abord choisir le niveau et le plan.
choixniv()
If Cauteur<2:Goto bouclepaschoix:EndIf ; un goto, même si ce n'est pas bo.
EndIf
If KeyboardPushed(#PB_Key_Back) And Cauteur=2 And lacheK32=0
Cauteur=0:choixniveau=0:Goto bouclepaschoix
EndIf
;- ------- limite X du niveau -------
limitXarray=(NUM_X_TILE_SCREENS* 8 )-16
;- ------- limite Y du niveau -------
limitYarray=(NUM_Y_TILE_SCREENS* 8 )-12
; dans le cas où vous voudriez un terrain de jeu plus grand, n'oubliez pas de changer les deux chiffres ( ici 8).
; ----------------------------------------------------------------------------------------------------------------------------------------------
; ***************** SCROLLING UP OR DOWN - défilement haut ou bas *********************
; ** Scroll Map 'Down' to go 'Up' ** de bas en haut
If KeyboardPushed(#PB_Key_Up) Or pointeurY<8
Speed=MapSpeed
SCROLL_Y_PIXEL=SCROLL_Y_PIXEL+Speed
If SCROLL_Y_PIXEL>=TILE_HEIGHT
SCROLL_Y_PIXEL=0
POS_Y_ARRAY=POS_Y_ARRAY-1
EndIf
EndIf
; ** Scroll Map 'Up' to go 'Down' ** de haut en bas
If KeyboardPushed(#PB_Key_Down) Or pointeurY>760
Speed=-MapSpeed
SCROLL_Y_PIXEL=SCROLL_Y_PIXEL+Speed
If SCROLL_Y_PIXEL<=0
SCROLL_Y_PIXEL=TILE_HEIGHT
POS_Y_ARRAY=POS_Y_ARRAY+1
EndIf
EndIf
; ***************** SCROLLING LEFT OR RIGHT - défilement gauche ou droite *******************
; ** Scroll Map 'Right' to go 'Left' ** de droite à gauche
If KeyboardPushed(#PB_Key_Left) Or pointeurX<8
Speed=MapSpeed
SCROLL_X_PIXEL=SCROLL_X_PIXEL+Speed
If SCROLL_X_PIXEL>=TILE_WIDTH
SCROLL_X_PIXEL=0
POS_X_ARRAY=POS_X_ARRAY-1
EndIf
EndIf
; ** Scroll Map 'Left' to go 'Right' ** de gauche à droite
If KeyboardPushed(#PB_Key_Right) Or pointeurX>1016
Speed=-MapSpeed
SCROLL_X_PIXEL=SCROLL_X_PIXEL+Speed
If SCROLL_X_PIXEL<=0
SCROLL_X_PIXEL=TILE_WIDTH
POS_X_ARRAY=POS_X_ARRAY+1
EndIf
EndIf
; *********************** STAY WITHIN ARRAY and DRAWING LIMITS **************************
; limite du terrain ( gauche, droite, haut et bas).
; *** Beginning X coordinates ***
If POS_X_ARRAY<1
POS_X_ARRAY=1
SCROLL_X_PIXEL=TILE_WIDTH
EndIf
; *** Ending X coordinates ***
If POS_X_ARRAY>(TOTAL_NUM_X_TILES-NUM_X_TILES)
POS_X_ARRAY=(TOTAL_NUM_X_TILES-NUM_X_TILES)
SCROLL_X_PIXEL=0
EndIf
; *** Beginning Y coordinates ***
If POS_Y_ARRAY<1
POS_Y_ARRAY=1
SCROLL_Y_PIXEL=TILE_HEIGHT
EndIf
; *** Ending Y coordinates ***
If POS_Y_ARRAY>(TOTAL_NUM_Y_TILES-NUM_Y_TILES)
POS_Y_ARRAY=(TOTAL_NUM_Y_TILES-NUM_Y_TILES)
SCROLL_Y_PIXEL=0
EndIf
; ************************************************ Début de la double boucle ************************************************
steptileX=-2
steptileY=-2
steparrayX=-1
steparrayY=-1
; ** Ok, this is an odd way of looping, remake the way you like **
tile44X=0:tile44Y=0
; ** Loops 17 times gets y0 and lasty+1 coordinates
While steptileY<(NUM_Y_TILES)
steptileY=steptileY+1
steparrayY=steparrayY+1
; ** Loops 22 times ** gets x0 and lastx+1 coordinates
While steptileX<(NUM_X_TILES)
steptileX=steptileX+1
steparrayX=steparrayX+1
;For cl=0 To 448 Step 64
;Next
;- un choix de 64 tiles( d'une taille de 64*64):
; là, on passe de 190 lignes à 39 lignes, c'est mieux !
For numtx=0 To 7 ; 1er ligne
If ArrayGrid(steparrayX+POS_X_ARRAY,steparrayY+POS_Y_ARRAY)=numtx
ClipSprite(#TILE_IMAGE, numtx*64, 0, 64, 64)
EndIf
Next
For numtx=8 To 15 ; 2eme ligne
If ArrayGrid(steparrayX+POS_X_ARRAY,steparrayY+POS_Y_ARRAY)=numtx
ClipSprite(#TILE_IMAGE, (numtx-8)*64, 64, 64, 64)
EndIf
Next
For numtx=16 To 23 ; 3eme ligne
If ArrayGrid(steparrayX+POS_X_ARRAY,steparrayY+POS_Y_ARRAY)=numtx
ClipSprite(#TILE_IMAGE, (numtx-16)*64, 128, 64, 64)
EndIf
Next
For numtx=24 To 31 ; 4eme ligne
If ArrayGrid(steparrayX+POS_X_ARRAY,steparrayY+POS_Y_ARRAY)=numtx
ClipSprite(#TILE_IMAGE, (numtx-24)*64, 192, 64, 64)
EndIf
Next
For numtx=32 To 39 ; 5eme ligne
If ArrayGrid(steparrayX+POS_X_ARRAY,steparrayY+POS_Y_ARRAY)=numtx
ClipSprite(#TILE_IMAGE, (numtx-32)*64, 256, 64, 64)
EndIf
Next
For numtx=40 To 47 ; 6eme ligne
If ArrayGrid(steparrayX+POS_X_ARRAY,steparrayY+POS_Y_ARRAY)=numtx
ClipSprite(#TILE_IMAGE, (numtx-40)*64, 320, 64, 64)
EndIf
Next
For numtx=48 To 55 ; 7eme ligne
If ArrayGrid(steparrayX+POS_X_ARRAY,steparrayY+POS_Y_ARRAY)=numtx
ClipSprite(#TILE_IMAGE, (numtx-48)*64, 384, 64, 64)
EndIf
Next
For numtx=56 To 63 ; 8eme ligne
If ArrayGrid(steparrayX+POS_X_ARRAY,steparrayY+POS_Y_ARRAY)=numtx
ClipSprite(#TILE_IMAGE, (numtx-56)*64, 448, 64, 64)
EndIf
Next
If ArrayGrid(steparrayX+POS_X_ARRAY,steparrayY+POS_Y_ARRAY)<65
DisplayTransparentSprite(#TILE_IMAGE, (steptileX*TILE_WIDTH)+SCROLL_X_PIXEL, (steptileY*TILE_HEIGHT)+SCROLL_Y_PIXEL)
EndIf
nbretiles+1; utilisé pour connaître le nombre de tiles affichées.
;- coller le tile de votre choix sur le terrain ( avec une marge de 24 pixels):
If pointeurX>((steptileX*TILE_WIDTH)+SCROLL_X_PIXEL)-12 And pointeurX<((steptileX*TILE_WIDTH)+SCROLL_X_PIXEL)+12
XOK=1
If pointeurY>((steptileY*TILE_HEIGHT)+SCROLL_Y_PIXEL)-12 And pointeurY<((steptileY*TILE_HEIGHT)+SCROLL_Y_PIXEL)+12
YOK=1
If MouseButton(1) And lachmb1=0 And visibl=0
lachmb1=1
XT=steparrayX+POS_X_ARRAY ;
YT=steparrayY+POS_Y_ARRAY ;
XTT=(steptileX*TILE_HEIGHT)+SCROLL_X_PIXEL
YTT=(steptileY*TILE_HEIGHT)+SCROLL_Y_PIXEL
ArrayGrid(XT,YT)=pointeurI ; pointeurI en voilà une variable qu'il est bien difficile de mettre à la bonne valeur, importante donc.
; XT comme colonne X du Tile.
; YT comme ligne Y du Tile.
; T comme Tile que vous avez choisi, voir plus bas. non pas là, plus bas.
EndIf
EndIf
EndIf
Wend
steparrayX=-1
steptileX=-2
Wend
; ************************************************ FIN de la double boucle ************************************************
; défile à la vitesse de votre choix:
If KeyboardPushed(#PB_Key_Pad1) And MapSpeed>8
MapSpeed=8
EndIf
If KeyboardPushed(#PB_Key_Pad2) And (MapSpeed<16 Or MapSpeed>16)
MapSpeed=16
EndIf
If KeyboardPushed(#PB_Key_Pad3) And MapSpeed<32
MapSpeed=32
EndIf
pointeurX=MouseX()
pointeurY=MouseY()
If MouseButton(2) Or KeyboardPushed(#PB_Key_0)
pointeurI=0 ; image 0 (transparent ou rien ) -> touche 0 ou bouton droit de la souris.
EndIf
If choixplan=1 And KeyboardPushed(#PB_Key_1):visibl=1:EndIf ; touche 1 -> tiles du plan 1.
If choixplan=2 And KeyboardPushed(#PB_Key_2):visibl=1:EndIf ; touche 2 -> tiles du plan 2.
If choixplan=3 And KeyboardPushed(#PB_Key_3):visibl=1:EndIf ; touche 3 -> tiles du plan 3.
If KeyboardPushed(#PB_Key_Space)
visibl=0 ; ne plus rendre visible la grande image.
EndIf
If visibl=1
ttileX=0:ttileY=0
EndIf
carreau=0:Csoi=0
If visibl>0 ; si l'ordre est donné d'afficher la grande image, alors...
ClipSprite(#TILE_IMAGE, 0, 0, 8*64, 8*64)
DisplayTransparentSprite(#TILE_IMAGE, 0, 0) ; ...ben on l'affiche. voilà. c'est fait.
; ici, on va joyeusement tester la position du curseur sur la grande image, voyez:
If pointeurX>ttileX And pointeurX<ttileX+512 And pointeurY>ttileY And pointeurY<ttileY+512
; tC: tiles Colonne ; tL: tiles Ligne
For tC=1 To 8 ;colonne de l'image TTILE ( 8*64=512).
For tL=1 To 8 ;ligne de l'image TTILE ( 8*64=512).
If pointeurX>ttileX+Csoi And pointeurX<ttileX+64+Csoi
caroX=ttileX+Csoi:carreau=1
EndIf
If pointeurY>ttileY+Csoi And pointeurY<ttileY+64+Csoi
caroY=ttileY+Csoi:carreau=1
EndIf
Csoi+64 ; pas toujours facile de choisir un ptit nom pour ses variables, et je le prouve ;) .
Next
Next
If MouseButton(1) And lachmb2=0
lachmb2=1
If caroY=0+ttileY ; 1er ligne.
If caroX=0+ttileX:pointeurI=0:EndIf
If caroX=64+ttileX:pointeurI=1:EndIf
If caroX=128+ttileX:pointeurI=2:EndIf
If caroX=192+ttileX:pointeurI=3:EndIf
If caroX=256+ttileX:pointeurI=4:EndIf
If caroX=320+ttileX:pointeurI=5:EndIf
If caroX=384+ttileX:pointeurI=6:EndIf
If caroX=448+ttileX:pointeurI=7:EndIf
EndIf
If caroY=64+ttileY ; 2eme ligne.
If caroX=0+ttileX:pointeurI=8:EndIf
If caroX=64+ttileX:pointeurI=9:EndIf
If caroX=128+ttileX:pointeurI=10:EndIf
If caroX=192+ttileX:pointeurI=11:EndIf
If caroX=256+ttileX:pointeurI=12:EndIf
If caroX=320+ttileX:pointeurI=13:EndIf
If caroX=384+ttileX:pointeurI=14:EndIf
If caroX=448+ttileX:pointeurI=15:EndIf
EndIf
If caroY=128+ttileY ; 3eme ligne.
If caroX=0+ttileX:pointeurI=16:EndIf
If caroX=64+ttileX:pointeurI=17:EndIf
If caroX=128+ttileX:pointeurI=18:EndIf
If caroX=192+ttileX:pointeurI=19:EndIf
If caroX=256+ttileX:pointeurI=20:EndIf
If caroX=320+ttileX:pointeurI=21:EndIf
If caroX=384+ttileX:pointeurI=22:EndIf
If caroX=448+ttileX:pointeurI=23:EndIf
EndIf
If caroY=192+ttileY ; 4eme ligne.
If caroX=0+ttileX:pointeurI=24:EndIf
If caroX=64+ttileX:pointeurI=25:EndIf
If caroX=128+ttileX:pointeurI=26:EndIf
If caroX=192+ttileX:pointeurI=27:EndIf
If caroX=256+ttileX:pointeurI=28:EndIf
If caroX=320+ttileX:pointeurI=29:EndIf
If caroX=384+ttileX:pointeurI=30:EndIf
If caroX=448+ttileX:pointeurI=31:EndIf
EndIf
If caroY=256+ttileY ; 5eme ligne.
If caroX=0+ttileX:pointeurI=32:EndIf
If caroX=64+ttileX:pointeurI=33:EndIf
If caroX=128+ttileX:pointeurI=34:EndIf
If caroX=192+ttileX:pointeurI=35:EndIf
If caroX=256+ttileX:pointeurI=36:EndIf
If caroX=320+ttileX:pointeurI=37:EndIf
If caroX=384+ttileX:pointeurI=38:EndIf
If caroX=448+ttileX:pointeurI=39:EndIf
EndIf
If caroY=320+ttileY ; 6eme ligne.
If caroX=0+ttileX:pointeurI=40:EndIf
If caroX=64+ttileX:pointeurI=41:EndIf
If caroX=128+ttileX:pointeurI=42:EndIf
If caroX=192+ttileX:pointeurI=43:EndIf
If caroX=256+ttileX:pointeurI=44:EndIf
If caroX=320+ttileX:pointeurI=45:EndIf
If caroX=384+ttileX:pointeurI=46:EndIf
If caroX=448+ttileX:pointeurI=47:EndIf
EndIf
If caroY=384+ttileY ; 7eme ligne.
If caroX=0+ttileX:pointeurI=48:EndIf
If caroX=64+ttileX:pointeurI=49:EndIf
If caroX=128+ttileX:pointeurI=50:EndIf
If caroX=192+ttileX:pointeurI=51:EndIf
If caroX=256+ttileX:pointeurI=52:EndIf
If caroX=320+ttileX:pointeurI=53:EndIf
If caroX=384+ttileX:pointeurI=54:EndIf
If caroX=448+ttileX:pointeurI=55:EndIf
EndIf
If caroY=448+ttileY ; 8eme ligne.
If caroX=0+ttileX:pointeurI=56:EndIf
If caroX=64+ttileX:pointeurI=57:EndIf
If caroX=128+ttileX:pointeurI=58:EndIf
If caroX=192+ttileX:pointeurI=59:EndIf
If caroX=256+ttileX:pointeurI=60:EndIf
If caroX=320+ttileX:pointeurI=61:EndIf
If caroX=384+ttileX:pointeurI=62:EndIf
If caroX=448+ttileX:pointeurI=63:EndIf ; pfiouuu.
EndIf
EndIf
DisplayTransparentSprite(#CARO, caroX, caroY)
EndIf
EndIf; If visibl>0
; par bonté d'âme, je laisse ici les premiers examples:
; If pointeurI=0
; ClipSprite(#TILE_IMAGE, 0, 0, 64, 64); tile en haut à gauche
; EndIf
; If pointeurI=1
; ClipSprite(#TILE_IMAGE, 64, 0, 64, 64)
;EndIf
; 1ere ligne de Tile:
If pointeurI>-1 And pointeurI<8:ClipSprite(#TILE_IMAGE, pointeurI*64, 0, 64, 64):EndIf
; 2eme ligne de Tile:
If pointeurI>7 And pointeurI<16:ClipSprite(#TILE_IMAGE, (pointeurI-8)*64, 64, 64, 64):EndIf
; 3eme ligne de Tile:
If pointeurI>15 And pointeurI<24:ClipSprite(#TILE_IMAGE, (pointeurI-16)*64, 128, 64, 64):EndIf
; 4eme ligne de Tile:
If pointeurI>23 And pointeurI<32:ClipSprite(#TILE_IMAGE, (pointeurI-24)*64, 192, 64, 64):EndIf
; 5eme ligne de Tile:
If pointeurI>31 And pointeurI<40:ClipSprite(#TILE_IMAGE, (pointeurI-32)*64, 256, 64, 64):EndIf
; 6eme ligne de Tile:
If pointeurI>39 And pointeurI<48:ClipSprite(#TILE_IMAGE, (pointeurI-40)*64, 320, 64, 64):EndIf
; 7eme ligne de Tile:
If pointeurI>47 And pointeurI<56:ClipSprite(#TILE_IMAGE, (pointeurI-48)*64, 384, 64, 64):EndIf
; 8eme ligne de Tile:
If pointeurI>55 And pointeurI<64:ClipSprite(#TILE_IMAGE, (pointeurI-56)*64, 448, 64, 64):EndIf
; l'image du pointeur doit correspondre au choix de l'auteur.
DisplayTransparentSprite(#TILE_IMAGE, pointeurX, pointeurY)
;- ordre ecriture .dat
If KeyboardPushed(#PB_Key_D) And lacheK32=0 ; enregistrer données du niveau dans le fichier .dat
lacheK32=1:ecriture()
EndIf
If KeyboardPushed(#PB_Key_D)=0 And lacheK32=1:lacheK32=0:EndIf
; .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat
bouclepaschoix:
Cauteur$= Str(Cauteur)
choixplan$= Str(choixplan)
choixniveau$= Str(choixniveau)
pointeurI$= Str(pointeurI)
visibl$= Str(visibl)
pointeurX$= Str(pointeurX)
pointeurY$= Str(pointeurY)
MapSpeed$= Str(MapSpeed)
POS_X_ARRAY$= Str(POS_X_ARRAY)
POS_Y_ARRAY$= Str(POS_Y_ARRAY)
caroX$= Str(caroX)
caroY$= Str(caroY)
nbretiles$= Str( nbretiles)
If StartDrawing(ScreenOutput())
DrawingMode(1)
If Cauteur<2
FrontColor ( RGB (255,255,255))
DrawText (1,80, "Choix de l'auteur( touches flechées haut ou bas): "); +Cauteur$)
FrontColor ( RGB (235,235,235))
If Cauteur=0:FrontColor ( RGB (240,50,50)):EndIf
DrawText (1,120, "choisissez le plan pour travailler( entre 1 et 3): " +choixplan$)
FrontColor ( RGB (235,235,235))
If Cauteur=1:FrontColor ( RGB (240,50,50)):EndIf
DrawText (1,150, "choisissez le niveau pour travailler( entre 1 et 4): " +choixniveau$)
Else
FrontColor ( RGB (255,255,255))
FrontColor ( RGB (154,154,154)):DrawText (1+1,120+1, "n°tile sélectionné: " +pointeurI$)
FrontColor ( RGB (234,234,234)):DrawText (1,120, "n°tile sélectionné: " +pointeurI$)
FrontColor ( RGB (154,154,154)):DrawText (1+1,240+1, "POS_X_ARRAY: " +POS_X_ARRAY$)
FrontColor ( RGB (234,234,234)):DrawText (1,240, "POS_X_ARRAY: " +POS_X_ARRAY$)
FrontColor ( RGB (154,154,154)):DrawText (1+1,260+1, "POS_Y_ARRAY: " +POS_Y_ARRAY$)
FrontColor ( RGB (234,234,234)):DrawText (1,260, "POS_Y_ARRAY: " +POS_Y_ARRAY$)
DrawText (1,300, "nbretiles: " +nbretiles$)
DrawText (1,360, "caroX: " +caroX$)
DrawText (1,380, "caroY: " +caroY$)
DrawText (1,400, "visibl: " +visibl$)
DrawText (1,440, "pointeurX: " +pointeurX$)
DrawText (1,460, "pointeurY: " +pointeurY$)
If visibl=1
FrontColor ( RGB (154,154,154)):DrawText (5+1,550+1, "Vous pouvez prendre une Tile, en appuyant sur le bouton gauche de la souris.")
FrontColor ( RGB (234,234,234)):DrawText (5,550, "Vous pouvez prendre une Tile, en appuyant sur le bouton gauche de la souris.")
EndIf
DrawText (1,640, "Affichage grande image regroupant toutes les tiles: Touche 1 2 ou 3")
DrawText (1,660, "Enlever grande image: barre espace")
DrawText (1,680, "MapSpeed( touche 1, 2 ou 3 du p.n.): " +MapSpeed$)
DrawText (1,720, "pour remise à 0, appuyez sur la touche Key_Back")
FrontColor ( RGB (154,154,154)):DrawText (330+1,740+1, "Sauvegarder sur le fichier .dat: Touche D")
FrontColor ( RGB (234,234,234)):DrawText (330,740, "Sauvegarder sur le fichier .dat: Touche D")
EndIf
StopDrawing()
EndIf
lachmb1=0:lachmb2=0
nbretiles=0; remise à 0 indispensable, rapport aux tableaux Dim afin de connaître le nombre de tiles qu'on affiche.
Gosub fps ; nombre d'image par seconde ( à placer dans tout vos jolis programmes, jeune étourdis !)
Until KeyboardPushed ( #PB_Key_Escape ): End ; fin de la boucle principale ( appuyez sur la touche Esc)
; *********************************************************************
; ******************** FIN DE LA BOUCLE PRINCIPALE ********************
; *********************************************************************
Procedure.l choixniv()
; choix plan 1, 2 ou 3, enfonction de vos ambitions, c'est qui voyez.
If Cauteur=0
If KeyboardPushed(#PB_Key_Up) And Tempo1=0 And choixplan<3
choixplan=choixplan+1
Tempo1=10
EndIf
If KeyboardPushed(#PB_Key_Down) And Tempo1=0 And choixplan>1
choixplan=choixplan-1
Tempo1=10
EndIf
If Tempo1>0
Tempo1=Tempo1-1
EndIf
If choixplan>0 And KeyboardPushed(#PB_Key_Return)
Cauteur=1
EndIf
EndIf
; choix niveau 1 à 4 ( déjà, si vous arrivez à pondre 4 niveaux amusant, c'est le bout de monde).
If Cauteur=1
If KeyboardPushed(#PB_Key_Up) And Tempo1=0 And choixniveau<4
choixniveau=choixniveau+1
Tempo1=10
EndIf
If KeyboardPushed(#PB_Key_Down) And Tempo1=0 And choixniveau>1
choixniveau=choixniveau-1
Tempo1=10
EndIf
If Tempo1>0
Tempo1=Tempo1-1
EndIf
If choixniveau>0 And KeyboardPushed(#PB_Key_Return)
Cauteur=2
EndIf
EndIf
; heu..., oui, là, nous allons utiliser de modeste fichiers .dat
If choixplan=1 And Cauteur=2
If choixniveau=1
MapDataFile$="p1niv01.dat"
EndIf
If choixniveau=2
MapDataFile$="p1niv02.dat"
EndIf
If choixniveau=3
MapDataFile$="p1niv03.dat"
EndIf
If choixniveau=4
MapDataFile$="p1niv04.dat"
EndIf
EndIf
If choixplan=2 And Cauteur=2
If choixniveau=1
MapDataFile$="p2niv01.dat"
EndIf
If choixniveau=2
MapDataFile$="p2niv02.dat"
EndIf
If choixniveau=3
MapDataFile$="p2niv03.dat"
EndIf
If choixniveau=4
MapDataFile$="p2niv04.dat"
EndIf
EndIf
If choixplan=3 And Cauteur=2
If choixniveau=1
MapDataFile$="p3niv01.dat"
EndIf
If choixniveau=2
MapDataFile$="p3niv02.dat"
EndIf
If choixniveau=3
MapDataFile$="p3niv03.dat"
EndIf
If choixniveau=4
MapDataFile$="p3niv04.dat"
EndIf
EndIf
; .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat
;- lecture .dat
If ReadFile(0,MapDataFile$) ; lecture données du niveau du fichier .dat ( correspondant au plan et niveau précedement choisi).
For y=1 To TOTAL_NUM_Y_TILES
For x=1 To TOTAL_NUM_X_TILES
ArrayGrid(x,y)=ReadByte(0)
Next
Next
CloseFile(0)
EndIf
; .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat .dat
SCROLL_X_PIXEL=0
SCROLL_Y_PIXEL=0
; placement au millieu du terrain:
POS_X_ARRAY=4*16
POS_Y_ARRAY=4*12
; si vous utilisez plusieurs plan pour votre jeu, vous allez vous arrachez les cheveux.
; alors en démarrant tout au milieu, c'est bien mieux.
EndProcedure
Procedure.l ecriture()
If CreateFile(0,MapDataFile$)
For y=1 To TOTAL_NUM_Y_TILES
For x=1 To TOTAL_NUM_X_TILES
WriteByte(0, ArrayGrid(x,y))
Next
Next
CloseFile(0)
EndIf
EndProcedure
fps:
If Val ( FormatDate ( "%ss" , Date ()))=sek ; regardez pas là, c'est trop compliqué. Arrêtez j'vous dis! Bon ben, je
; vous aurez prévenu...
fps+1
Else
FPS$= Str (fps)
fps=0
EndIf
sek= Val ( FormatDate ( "%ss" , Date ()))
StartDrawing ( ScreenOutput ())
DrawingMode (1)
FrontColor ( RGB (255,255,255))
DrawText (1,1, "FPS: " +FPS$)
StopDrawing ()
Return
; IDE Options = PureBasic v4.02 (Windows - x86)