Le système de tiles que j'emploie me permet de choisir des tiles aléatoirement(pas utilisé ici sauf pour la mer). En effet, si je prend un sprite tiles_woh où les tiles se répètent périodiquement, je pourrais varier le dessins des tiles(exemple, colonne tile terre tous les 48 pixels => clipsprite pour les tiles_terre avec un random qui donne 0, 48, 96...)
Les tiles sont stylisés(c'est mon choix, mais ça se dicute

Pour le chateau, je prévois le placement de tours, le remplissage automatique des zones "encerclées" par des tiles chateau.
Je rajouterai les fonctions de reconnaissances et de calculs de surfaces
La fonction grille est là mais désactivée(commentaires)
Voilà les tiles(à mettre dans le même dossier que le programme):
Un aperçu:
http://www.heisspiter.net/upload/230207/woh.PNG
Le code:
Code : Tout sélectionner
;***world of huibit v0.1***
;projet microwargame en 16 couleurs
;etape 1 creation de la carte
;creation carte aleatoire(nouveau systeme de decoupage de l'ecran)
; exemple utilisation macro pour creer les bordures
;fabrication chateau amis(bleu) (version simplifiee au max)
;***purebasic v4.02***
;************************
;***déclarations***
#largeur_ecran=1280
#hauteur_ecran=1024
#x_carte_max= #largeur_ecran/16-1
#y_carte_max=#hauteur_ecran/16-1
Enumeration
#spr_tile
#spr_carte
#spr_blason_bleu
#spr_blason_rouge
EndEnumeration
Structure couche
mer.b
terre.b
montagne.b
chateau.b
neutre.b
bordure.b
numero_ile.l
surface_ile.l
visible.b
visite.b
x_detect.b
y_detect.b
EndStructure
;***variables****
Global x_carte.b, y_carte.b,x_curseur.b,y_curseur.b,x_blason_bleu.b,y_blason_bleu.b,x_blason_rouge.b,y_blason_rouge.b
;***tableau***
Global Dim carte.couche(#x_carte_max,#y_carte_max); carte(79,63) cad 80*64 tiles 16*16
;*************
Macro zone_et_bordure(numero_tile,largeur_rivage,zone_interieure,zone_exterieure)
;affichage des carrés de zone_interieure
For y_carte=1 To #y_carte_max-1
For x_carte=1 To #x_carte_max-1
If carte(x_carte,y_carte)\zone_interieure=1
ClipSprite(#spr_tile,numero_tile*16,64,16,16)
DisplaySprite(#spr_tile,x_carte*16,y_carte*16)
;affichage de rivages rectilignes
;affichage du rivage N
If carte(x_carte,y_carte-1)\zone_exterieure=1
ClipSprite(#spr_tile,numero_tile*16,48,16,8)
DisplayTransparentSprite(#spr_tile,x_carte*16,y_carte*16)
EndIf
;affichage du rivage S
If carte(x_carte,y_carte+1)\zone_exterieure=1
ClipSprite(#spr_tile,numero_tile*16,56,16,8)
DisplayTransparentSprite(#spr_tile,x_carte*16,y_carte*16+16-largeur_rivage)
EndIf
;affichage du rivage E
If carte(x_carte+1,y_carte)\zone_exterieure=1
ClipSprite(#spr_tile,8+numero_tile*16,32,8,16)
DisplayTransparentSprite(#spr_tile,x_carte*16+16-largeur_rivage,y_carte*16)
EndIf
;affichage du rivage O
If carte(x_carte-1,y_carte)\zone_exterieure=1
ClipSprite(#spr_tile,numero_tile*16,32,8,16)
DisplayTransparentSprite(#spr_tile,x_carte*16,y_carte*16)
EndIf
EndIf
Next x_carte
Next y_carte
;affichage des rivages courbes
For y_carte=1 To #y_carte_max-1
For x_carte=1 To #x_carte_max-1
If carte(x_carte,y_carte)\zone_interieure=1
;bords de mer concaves
;affichage des coins mer NO
If carte(x_carte,y_carte-1)\zone_interieure=1 And carte(x_carte-1,y_carte)\zone_interieure=1 And carte(x_carte-1,y_carte-1)\zone_exterieure=1
ClipSprite(#spr_tile,8+numero_tile*16,24,8,8)
DisplayTransparentSprite(#spr_tile,x_carte*16-(8-largeur_rivage),y_carte*16-(8-largeur_rivage))
EndIf
;affichage des coins mer NE
If carte(x_carte,y_carte-1)\zone_interieure=1 And carte(x_carte+1,y_carte)\zone_interieure=1 And carte(x_carte+1,y_carte-1)\zone_exterieure=1
ClipSprite(#spr_tile,numero_tile*16,24,8,8)
DisplayTransparentSprite(#spr_tile,x_carte*16+16-largeur_rivage,y_carte*16-(8-largeur_rivage))
EndIf
;affichage des coins mer SE
If carte(x_carte+1,y_carte)\zone_interieure=1 And carte(x_carte,y_carte+1)\zone_interieure=1 And carte(x_carte+1,y_carte+1)\zone_exterieure=1
ClipSprite(#spr_tile,numero_tile*16,16,8,8)
DisplayTransparentSprite(#spr_tile,x_carte*16+16-largeur_rivage,y_carte*16+16-largeur_rivage)
EndIf
;affichage des coins mer SO
If carte(x_carte-1,y_carte)\zone_interieure=1 And carte(x_carte,y_carte+1)\zone_interieure=1 And carte(x_carte-1,y_carte+1)\zone_exterieure=1
ClipSprite(#spr_tile,8+numero_tile*16,16,8,8)
DisplayTransparentSprite(#spr_tile,x_carte*16-(8-largeur_rivage),y_carte*16+16-largeur_rivage)
EndIf
;bords de mer convexes
;affichage des coins mer NO
If carte(x_carte,y_carte-1)\zone_exterieure=1 And carte(x_carte-1,y_carte)\zone_exterieure=1
ClipSprite(#spr_tile,numero_tile*16,0,8,8)
DisplayTransparentSprite(#spr_tile,x_carte*16,y_carte*16)
EndIf
;affichage des coins mer NE
If carte(x_carte,y_carte-1)\zone_exterieure=1 And carte(x_carte+1,y_carte)\zone_exterieure=1
ClipSprite(#spr_tile,8+numero_tile*16,0,8,8)
DisplayTransparentSprite(#spr_tile,x_carte*16+8,y_carte*16)
EndIf
;affichage des coins mer SE
If carte(x_carte+1,y_carte)\zone_exterieure=1 And carte(x_carte,y_carte+1)\zone_exterieure=1
ClipSprite(#spr_tile,8+numero_tile*16,8,8,8)
DisplayTransparentSprite(#spr_tile,x_carte*16+8,y_carte*16+8)
EndIf
;affichage des coins mer SO
If carte(x_carte-1,y_carte)\zone_exterieure=1 And carte(x_carte,y_carte+1)\zone_exterieure=1
ClipSprite(#spr_tile,numero_tile*16,8,8,8)
DisplayTransparentSprite(#spr_tile,x_carte*16,y_carte*16+8)
EndIf
EndIf
Next x_carte
Next y_carte
EndMacro
Procedure.b detection(x.b,y.b,choix.s)
carte(x,y)\x_detect=x
carte(x,y)\y_detect=y
a.b=carte(x,y)\x_detect
b.b=carte(x,y)\y_detect
carte(a,b)\visite=1
If choix="mer"
;***test haut***
If carte(a,b-1)\mer=1 And carte(a,b-1)\visite=0
detection(a,b-1,"mer")
EndIf
;***test droite***
If carte(a+1,b)\mer=1 And carte(a+1,b)\visite=0
detection(a+1,b,"mer")
EndIf
;***test bas***
If carte(a,b+1)\mer=1 And carte(a,b+1)\visite=0
detection(a,b+1,"mer")
EndIf
;***test gauche***
If carte(a-1,b)\mer=1 And carte(a-1,b)\visite=0
detection(a-1,b,"mer")
EndIf
EndIf
EndProcedure
Procedure.b decoupage(pas.b,taille_x_echantillon.b,taille_y_echantillon.b)
While dy.b <=taille_y_echantillon
dx.b=0
While dx<=taille_x_echantillon
If (x_carte+dx<#x_carte_max) And (y_carte+dy<#y_carte_max)
carte(x_carte+dx,y_carte+dy)\terre=Round(Random(2)/2,1);fonction force le random, à rajouter dans les paramêtres de découpage!
EndIf
dx=dx+pas
Wend
dy=dy+pas
Wend
EndProcedure
Procedure.b affichage_tiles(zone.s)
Select zone
Case"terre"
zone_et_bordure(0,3,terre,mer)
Case "montagne"
zone_et_bordure(1,3,montagne,terre)
Case "chateau"
zone_et_bordure(3,8,chateau,neutre)
EndSelect
EndProcedure
Procedure .b affichage_bordure()
For y_carte=0 To #y_carte_max
For x_carte=0 To #x_carte_max
If x_carte=0 Or y_carte=0 Or x_carte=#x_carte_max Or y_carte=#y_carte_max
ClipSprite(#spr_tile,32,64,16,16)
DisplaySprite(#spr_tile,x_carte*16,y_carte*16)
EndIf
Next x_carte
Next y_carte
EndProcedure
Procedure .b affichage_mer()
For y_carte=1 To #y_carte_max-1
For x_carte=1 To #x_carte_max-1
If carte(x_carte,y_carte)\mer=1
ClipSprite(#spr_tile,32,Random(3)*16,16,16)
DisplaySprite(#spr_tile,x_carte*16,y_carte*16)
EndIf
Next x_carte
Next y_carte
EndProcedure
Procedure.b placement_blasons()
While carte(x_blason_bleu,y_blason_bleu)\mer+carte(x_blason_bleu+1,y_blason_bleu)\mer+carte(x_blason_bleu+1,y_blason_bleu+1)\mer+carte(x_blason_bleu,y_blason_bleu+1)\mer+carte(x_blason_rouge,y_blason_rouge)\mer+carte(x_blason_rouge+1,y_blason_rouge)\mer+carte(x_blason_rouge+1,y_blason_rouge+1)\mer+carte(x_blason_rouge,y_blason_rouge+1)\mer<>0
x_blason_bleu=Random(#x_carte_max-1)
y_blason_bleu=Random(#y_carte_max-1)
x_blason_rouge=Random(#x_carte_max-1)
y_blason_rouge=Random(#y_carte_max-1)
Wend
carte(x_blason_bleu,y_blason_bleu)\chateau=1
carte(x_blason_bleu,y_blason_bleu)\neutre=0
carte(x_blason_bleu+1,y_blason_bleu)\chateau=1
carte(x_blason_bleu+1,y_blason_bleu)\neutre=0
carte(x_blason_bleu+1,y_blason_bleu+1)\chateau=1
carte(x_blason_bleu+1,y_blason_bleu+1)\neutre=0
carte(x_blason_bleu,y_blason_bleu+1)\chateau=1
carte(x_blason_bleu,y_blason_bleu+1)\neutre=0
UseBuffer(#spr_carte)
affichage_tiles("chateau")
UseBuffer(-1)
EndProcedure
decoupage(3,#x_carte_max,#y_carte_max)
For y_carte=0 To #y_carte_max Step 3
For x_carte=0 To #x_carte_max Step 3
If carte(x_carte,y_carte)\terre=1
decoupage(1,2,2)
EndIf
Next x_carte
Next y_carte
;pas de terre collée à la bordure rose
For y_carte=1 To #y_carte_max-1
For x_carte=1 To #x_carte_max-1
carte(x_carte,y_carte)\mer=carte(x_carte,y_carte)\terre Not carte(x_carte,y_carte)\terre
If y_carte=1 Or y_carte=#y_carte_max-1 Or x_carte=1 Or x_carte=#x_carte_max-1
carte(x_carte,y_carte)\mer=1
carte(x_carte,y_carte)\terre=0
EndIf
Next x_carte
Next y_carte
;***création des bordures exterieures(cadre)***
For y_carte=0 To #y_carte_max
For x_carte=0 To #x_carte_max
If x_carte=0 Or y_carte=0 Or x_carte=#x_carte_max Or y_carte=#y_carte_max
carte(x_carte,y_carte)\bordure=1
EndIf
Next x_carte
Next y_carte
;***bouchage des trous***
y_carte=2
For x_carte=2 To #x_carte_max-2
If carte(x_carte,y_carte)\mer=1
detection(x_carte,y_carte,"mer")
EndIf
Next x_carte
y_carte=#y_carte_max-2
For x_carte=2 To #x_carte_max-2
If carte(x_carte,y_carte)\mer=1
detection(x_carte,y_carte,"mer")
EndIf
Next x_carte
x_carte=2
For y_carte=2 To #y_carte_max
If carte(x_carte,y_carte)\mer=1
detection(x_carte,y_carte,"mer")
EndIf
Next y_carte
x_carte=#x_carte_max-2
For y_carte=2 To #y_carte_max-2
If carte(x_carte,y_carte)\mer=1
detection(x_carte,y_carte,"mer")
EndIf
Next y_carte
For y_carte=2 To #y_carte_max-1
For x_carte=2 To #x_carte_max-1
If carte(x_carte,y_carte)\visite=0 And carte(x_carte,y_carte)\mer=1
carte(x_carte,y_carte)\montagne=1
carte(x_carte,y_carte)\mer=0
carte(x_carte,y_carte)\visite=0
EndIf
Next x_carte
Next y_carte
;suppression des montagnes proches de la mer
For y_carte=2 To #y_carte_max-1
For x_carte=2 To #x_carte_max-1
If carte(x_carte,y_carte)\montagne=1 And (carte(x_carte-1,y_carte+1)\mer=1 Or carte(x_carte+1,y_carte-1)\mer=1 Or carte(x_carte+1,y_carte+1)\mer=1 Or carte(x_carte-1,y_carte-1)\mer=1)
carte(x_carte,y_carte)\montagne=0
carte(x_carte,y_carte)\terre=1
EndIf
Next x_carte
Next y_carte
;remplissage structure neutre pour tiles exterieures dans l'appel de la procedure pour la construction du chateau
For y_carte=1 To #y_carte_max-1
For x_carte=1 To #x_carte_max-1
carte(x_carte,y_carte)\neutre=1
Next x_carte
Next y_carte
InitSprite()
InitKeyboard()
InitMouse()
OpenScreen(#largeur_ecran,#hauteur_ecran,32,"world_of_huitbit")
UsePNGImageDecoder()
LoadSprite(#spr_tile,"tiles_woh.png")
;blasons rouge et bleu
CreateSprite(#spr_blason_bleu,16,16)
UseBuffer(#spr_blason_bleu)
ClipSprite(#spr_tile,64,0,16,16)
DisplaySprite(#spr_tile,0,0)
UseBuffer(-1)
CreateSprite(#spr_blason_rouge,16,16)
UseBuffer(#spr_blason_rouge)
ClipSprite(#spr_tile,64,16,16,16)
DisplaySprite(#spr_tile,0,0)
UseBuffer(-1)
;dessin de la carte
CreateSprite(#spr_carte,#largeur_ecran,#hauteur_ecran)
UseBuffer(#spr_carte)
ClearScreen(RGB(0,128,128))
affichage_bordure()
affichage_mer()
affichage_tiles("terre")
affichage_tiles("montagne")
UseBuffer(-1)
;affichage de la grille
; StartDrawing(SpriteOutput(#spr_carte))
; For i=2 To #x_carte_max-1
; For j=2 To #y_carte_max-1
; LineXY(i*16,16,i*16,#hauteur_ecran-16,RGB(0,0,0))
; LineXY(16,16*j,#largeur_ecran-16,16*j,RGB(0,0,0))
; Next j
; Next i
; StopDrawing()
MouseLocate(#largeur_ecran/2,#hauteur_ecran/2)
placement_blasons()
Repeat
Delay(24)
ExamineKeyboard()
ExamineMouse()
DisplaySprite(#spr_carte,0,0)
DisplayTransparentSprite(#spr_blason_bleu,x_blason_bleu*16+8,y_blason_bleu*16+8)
DisplayTransparentSprite(#spr_blason_rouge,x_blason_rouge*16+8,y_blason_rouge*16+8)
x_curseur=Int(MouseX()/16)
y_curseur=Int(MouseY()/16)
If x_curseur>0 And x_curseur<#x_carte_max-1 And y_curseur>0 And y_curseur<#y_carte_max-1
If carte(x_curseur,y_curseur)\mer+carte(x_curseur+1,y_curseur)\mer+carte(x_curseur+1,y_curseur+1)\mer+carte(x_curseur,y_curseur+1)\mer=0
If carte(x_curseur,y_curseur-1)\chateau+carte(x_curseur+1,y_curseur-1)\chateau=2 Or carte(x_curseur+2,y_curseur)\chateau+carte(x_curseur+2,y_curseur+1)\chateau=2 Or carte(x_curseur,y_curseur+2)\chateau+carte(x_curseur+1,y_curseur+2)\chateau=2 Or carte(x_curseur-1,y_curseur)\chateau+carte(x_curseur-1,y_curseur+1)\chateau=2 Or (x_curseur = x_blason_bleu And y_curseur = y_blason_bleu)
DisplayRGBFilter(x_curseur*16,y_curseur*16,32,32,0,128,0)
If MouseButton(#PB_MouseButton_Left)
carte(x_curseur,y_curseur)\chateau=1
carte(x_curseur,y_curseur)\neutre=0
carte(x_curseur+1,y_curseur)\chateau=1
carte(x_curseur+1,y_curseur)\neutre=0
carte(x_curseur+1,y_curseur+1)\chateau=1
carte(x_curseur+1,y_curseur+1)\neutre=0
carte(x_curseur,y_curseur+1)\chateau=1
carte(x_curseur,y_curseur+1)\neutre=0
UseBuffer(#spr_carte)
affichage_tiles("chateau")
UseBuffer(-1)
EndIf
Else
DisplayRGBFilter(x_curseur*16,y_curseur*16,32,32,255,0,0)
EndIf
Else
DisplayRGBFilter(x_curseur*16,y_curseur*16,32,32,255,0,0)
EndIf
EndIf
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or MouseButton(#PB_MouseButton_Right)
Ma question :
Quelles techniques étaient employées par les graphistes des années 80 pour dessiner les sprites 16*16, car certains arrivaient à faire de vrai petits miracles!
Hasta la vista!