puis les sprites:
Code : Tout sélectionner
;****************déclaration des variables*****************
Enumeration
#case_bordure
#case_mer
#case_terre
#case_visite
#spr_bordure
#spr_terre
#spr_rustine
#spr_rivage
#spr_curseur
EndEnumeration
x_carte.b=0 ; position x sur la carte
y_carte.b=0 ; position y sur la carte
x_souris.b=0 ; position x de la souris
y_souris.b=0 ; position y de la souris
tirage.s="" ; variable utilsée dans la conversion déc-bin
inc_tirage.b=0 ; curseur pour selectionner un caractère dans tirage
inc_ile.l=0 ; compteur utilisé pour identifier les îles
numero_ile.l=0 ; identifiant d'île, utilisé pour calculer la surface
surface_ile.l=0 ;surface de l'île
Global inc_ile.l ;pour continuer à indexer les case carte() dans les procedures
;*****************tableaux************************
Dim carte.b(63,47,1); tableau 64*48*2 0: carte 1: numéros des îles
Dim x_detection.b(63,47) ;mémorisation des coordonnées
Dim y_detection.b(63,47) ;initiales de la case testée
;****************declaration de la procedure detection1**************
Declare.b detection1(x,y,choix)
;****************procedure detection0********************************
Procedure.b detection0(x,y,choix)
x_detection(x,y)=x
y_detection(x,y)=y
carte(x_detection(x,y),y_detection(x,y),0)=#case_visite
If choix=#case_terre
carte(x_detection(x,y),y_detection(x,y),1)=inc_ile
EndIf
If choix=#case_mer Or choix=#case_terre
;****haut****
If carte(x_detection(x,y),y_detection(x,y)-1,0)=choix
detection1(x_detection(x,y),y_detection(x,y)-1,choix)
EndIf
;****droite****
If carte(x_detection(x,y)+1,y_detection(x,y),0)=choix
detection1(x_detection(x,y)+1,y_detection(x,y),choix)
EndIf
;****bas****
If carte(x_detection(x,y),y_detection(x,y)+1,0)=choix
detection1(x_detection(x,y),y_detection(x,y)+1,choix)
EndIf
;****gauche****
If carte(x_detection(x,y)-1,y_detection(x,y),0)=choix
detection1(x_detection(x,y)-1,y_detection(x,y),choix)
EndIf
EndIf
If choix=#case_terre
;****haut droite****
If carte(x_detection(x,y)+1,y_detection(x,y)-1,0)=choix
detection1(x_detection(x,y)+1,y_detection(x,y)-1,choix)
EndIf
;**** bas droite****
If carte(x_detection(x,y)+1,y_detection(x,y)+1,0)=choix
detection1(x_detection(x,y)+1,y_detection(x,y)+1,choix)
EndIf
;****bas gauche****
If carte(x_detection(x,y)-1,y_detection(x,y)+1,0)=choix
detection1(x_detection(x,y)-1,y_detection(x,y)+1,choix)
EndIf
;**** haut gauche****
If carte(x_detection(x,y)-1,y_detection(x,y)-1,0)=choix
detection1(x_detection(x,y)-1,y_detection(x,y)-1,choix)
EndIf
EndIf
EndProcedure
;****************procedure detection1********************************
Procedure.b detection1(x,y,choix)
x_detection(x,y)=x
y_detection(x,y)=y
carte(x_detection(x,y),y_detection(x,y),0)=#case_visite
If choix=#case_terre
carte(x_detection(x,y),y_detection(x,y),1)=inc_ile
EndIf
If choix=#case_mer Or choix=#case_terre
;****haut****
If carte(x_detection(x,y),y_detection(x,y)-1,0)=choix
detection0(x_detection(x,y),y_detection(x,y)-1,choix)
EndIf
;****droite****
If carte(x_detection(x,y)+1,y_detection(x,y),0)=choix
detection0(x_detection(x,y)+1,y_detection(x,y),choix)
EndIf
;****bas****
If carte(x_detection(x,y),y_detection(x,y)+1,0)=choix
detection0(x_detection(x,y),y_detection(x,y)+1,choix)
EndIf
;****gauche****
If carte(x_detection(x,y)-1,y_detection(x,y),0)=choix
detection0(x_detection(x,y)-1,y_detection(x,y),choix)
EndIf
EndIf
If choix=#case_terre
;****haut droite****
If carte(x_detection(x,y)+1,y_detection(x,y)-1,0)=choix
detection0(x_detection(x,y)+1,y_detection(x,y)-1,choix)
EndIf
;**** bas droite****
If carte(x_detection(x,y)+1,y_detection(x,y)+1,0)=choix
detection0(x_detection(x,y)+1,y_detection(x,y)+1,choix)
EndIf
;****bas gauche****
If carte(x_detection(x,y)-1,y_detection(x,y)+1,0)=choix
detection0(x_detection(x,y)-1,y_detection(x,y)+1,choix)
EndIf
;**** haut gauche****
If carte(x_detection(x,y)-1,y_detection(x,y)-1,0)=choix
detection0(x_detection(x,y)-1,y_detection(x,y)-1,choix)
EndIf
EndIf
EndProcedure
;******** choix des grandes cases terre/mer parmi les 8*6 cases ***********
For y_carte=0 To 47 Step 8
; tirage = nombre binaire aléatoire complété à 8 chiffres par LSet
tirage=LSet(Bin(Random(255)) ,8,"0")
inc_tirage=0
; attribution des valeurs aux cases situées en haut à gauche des grandes cases
For x_carte =0 To 63 Step 8
inc_tirage=inc_tirage+1
carte(x_carte,y_carte,0)=Val(Mid(tirage ,inc_tirage,1))
Next x_carte
Next y_carte
; remplissage du tableau en fonction des index des grandes cases
For y_carte=0 To 47 Step 8
For x_carte=0 To 63 Step 8
If carte(x_carte,y_carte,0)=1;en fonction de la valeur de l'index des cases, on remplie
For j=0 To 7
tirage=LSet(Bin(Random(255)) ,8,"0")
inc_tirage=0
For i=0 To 7
inc_tirage=inc_tirage+1
If Val(Mid(tirage ,inc_tirage,1))=1
carte(x_carte+i,y_carte+j,0)=#case_terre
Else
carte(x_carte+i,y_carte+j,0)=#case_mer
EndIf
Next i
Next j
Else
For j=0 To 7
For i=0 To 7
carte(x_carte+i,y_carte+j,0)=#case_mer
Next i
Next j
EndIf
Next x_carte
Next y_carte
;************création des bordures*************
For y_carte=0 To 47
For x_carte=0 To 63
If x_carte=0 Or x_carte=63 Or y_carte=0 Or y_carte=47
carte(x_carte,y_carte,0)=#case_bordure
EndIf
Next x_carte
Next y_carte
;************légères modifications de la matrice(éviter les alignements trop importants***
For y_carte=1 To 44
For x_carte=1 To 60
;**********éviter les alignements verticaux**********
If carte(x_carte,y_carte,0)+carte(x_carte,y_carte+1,0)+carte(x_carte,y_carte+2,0)=3*#case_terre And carte(x_carte+1,y_carte,0)+carte(x_carte+1,y_carte+1,0)+carte(x_carte+1,y_carte+2,0)=3*#case_mer
carte(x_carte+1,y_carte+Random(2),0)=#case_terre
EndIf
If carte(x_carte,y_carte,0)+carte(x_carte,y_carte+1,0)+carte(x_carte,y_carte+2,0)=3*#case_mer And carte(x_carte+1,y_carte,0)+carte(x_carte+1,y_carte+1,0)+carte(x_carte+1,y_carte+2,0)=3*#case_terre
carte(x_carte,y_carte+Random(2),0)=#case_terre
EndIf
;**********éviter les alignements horizontaux*********
If carte(x_carte,y_carte,0)+carte(x_carte+1,y_carte,0)+carte(x_carte+2,y_carte,0)=3*#case_terre And carte(x_carte,y_carte+1,0)+carte(x_carte+1,y_carte+1,0)+carte(x_carte+2,y_carte+1,0)=3*#case_mer
carte(x_carte+Random(2),y_carte+1,0)=#case_terre
EndIf
If carte(x_carte,y_carte,0)+carte(x_carte+1,y_carte,0)+carte(x_carte+2,y_carte,0)=3*#case_mer And carte(x_carte,y_carte+1,0)+carte(x_carte+1,y_carte+1,0)+carte(x_carte+2,y_carte+1,0)=3*#case_terre
carte(x_carte+Random(2),y_carte,0)=#case_terre
EndIf
Next x_carte
Next y_carte
;**********bouchage des trous******************
y_carte=1
For x_carte=1 To 62
If carte(x_carte,y_carte,0)=#case_mer
detection0(x_carte,y_carte,#case_mer)
EndIf
Next x_carte
y_carte=46
For x_carte=1 To 62
If carte(x_carte,y_carte,0)=#case_mer
detection0(x_carte,y_carte,#case_mer)
EndIf
Next x_carte
x_carte=1
For y_carte=1 To 46
If carte(x_carte,y_carte,0)=#case_mer
detection0(x_carte,y_carte,#case_mer)
EndIf
Next y_carte
x_carte=62
For y_carte=1 To 46
If carte(x_carte,y_carte,0)=#case_mer
detection0(x_carte,y_carte,#case_mer)
EndIf
Next y_carte
For y_carte=1 To 46 ;on remplace les cases visitées par des cases mer
For x_carte=1 To 62 ;et les cases non visitées par des cases terres
If carte(x_carte,y_carte,0)=#case_mer
carte(x_carte,y_carte,0)=#case_terre
Else
If carte(x_carte,y_carte,0)=#case_visite
carte(x_carte,y_carte,0)=#case_mer
EndIf
EndIf
Next x_carte
Next y_carte
;**********identification des îles******************
For y_carte=1 To 46
For x_carte=1 To 62
If carte(x_carte,y_carte,0)=#case_terre
inc_ile=inc_ile+1
carte(x_carte,y_carte,1)=inc_ile
detection0(x_carte,y_carte,#case_terre)
EndIf
Next x_carte
Next y_carte
For y_carte=1 To 46
For x_carte=1 To 62
If carte(x_carte,y_carte,0)=#case_visite
carte(x_carte,y_carte,0)=#case_terre
EndIf
Next x_carte
Next y_carte
;*****************initialisation**************************
InitMouse()
InitSprite()
InitSprite3D()
;*****************écrans*********************************
OpenScreen(1024,768,32,"micro_wargame") ;ouverture d'un écran de profondeur 32
UsePNGImageDecoder()
LoadFont(1,"arial",9,#PB_Font_Bold)
TransparentSpriteColor(-1,255,255,255);couleur de transparence : blanc(par défaut)
;***********************sprites********************
LoadSprite(#spr_bordure,"bordure.png")
LoadSprite(#spr_rivage,"octogone_rivage.png")
LoadSprite(#spr_terre,"octogone_terre.png")
LoadSprite(#spr_rustine,"rustine.png")
LoadSprite(#spr_curseur,"curseur.png")
Repeat ; boucle principale
Delay(20)
ClearScreen(22,49,235); fond d'écran bleu
For y_carte=0 To 47 ;affichage des bordures(sprite 24*24)
For x_carte=0 To 63
If carte(x_carte,y_carte,0)=#case_terre
DisplayTransparentSprite(#spr_rivage,x_carte*16-4,y_carte*16-4)
EndIf
Next x_carte
Next y_carte
For y_carte=0 To 47;affichage de la terre(sprite 16*16)
For x_carte=0 To 63
If carte(x_carte,y_carte,0)=#case_terre
DisplayTransparentSprite(#spr_terre,x_carte*16,y_carte*16)
EndIf
If carte(x_carte,y_carte,0)=#case_bordure; affichage de la bordure(sprite 16*16)
DisplaySprite(#spr_bordure,x_carte*16,y_carte*16)
EndIf
Next x_carte
Next y_carte
For y_carte=1 To 45; bouchage des trous avec rustine(sprite 8*8)
For x_carte=1 To 62
If carte(x_carte,y_carte,0)+carte(x_carte+1,y_carte,0)+carte(x_carte+1,y_carte+1,0)+carte(x_carte,y_carte+1,0)=4*#case_terre
DisplayTransparentSprite(#spr_rustine,x_carte*16+12,y_carte*16+12)
EndIf
Next x_carte
Next y_carte
;************évenements souris*************************
ExamineMouse()
x_souris=Int(MouseX()/16);correspondance entre pixels et cases du tableau
y_souris=Int(MouseY()/16)
StartDrawing(ScreenOutput())
DrawingFont(FontID ())
DrawingMode(4)
FrontColor(255,255,0)
BackColor(255,0,0)
Locate(324,0)
DrawText(" [Click droit] pour fermer | [Click gauche] pour connaître la surface de l'île ")
FrontColor(255,255,255)
Locate(MouseX()+24,MouseY())
If carte(x_souris,y_souris,1)<>0
DrawText("Île n° " + Str(carte(x_souris,y_souris,1))+" (sur "+Str(inc_ile)+" îles).")
EndIf
If MouseButton(1)<>0
surface_ile=0 ; calcul de la surface des îles
numero_ile=carte(x_souris,y_souris,1)
For y_carte=1 To 46
For x_carte=1 To 62
If carte(x_carte,y_carte,1)=numero_ile
surface_ile=surface_ile+1
EndIf
Next x_carte
Next y_carte
Locate(MouseX()+24,MouseY()+24)
DrawText("Surface = "+Str(surface_ile)+" km²")
EndIf
StopDrawing()
DisplayTransparentSprite(#spr_curseur, MouseX()-10,MouseY()-10); sprite de la souris(30*31)
;******************************************************************
FlipBuffers ()
Until MouseButton(2)<>0; on ferme si click du droit
CloseScreen()
End
une carte se créée(étape n°1)
on construit sa forteresse
on place son armée et ses armes
on massacre son voisin!!!
Et tout ça avec un minimum de gestion des ressources(récolter des potirons pendant 2h pour construire une étable ça m'énerve

J'avais commencé qquechose sur les archipels il y a quelques temps, j'ai tout repris à zéro proprement:
maintenant il n'y a que trois matrices
j'utilise le convertisseur DEC-BIN de Pure Basic
on peut identifier une île et connaître sa surface(ça veut dire que je peux envoyer les soldats sur une île, diviser la carte en plusieurs pays....)
Pour remplir une carte aléatoirement, je procède en deux étapes:
je découpe la carte en grandes zones puis je les découpe en petites zones(tout ça avec des chaînes de caractères et les nombres binaires)
Ensuite je corrige les anomalies(trous, alignements trop importants...)
Et pour finir j'identifie toutes les zones créées
Questions
mon ordinateur refuse de passer en mode 16 couleurs

j'aurais pû travailler avec une seule matrice, mais ai-je le droit d'écrire:
carte(carte(x,y,0),carte(x,y,0),1) c'est à dire travailler avec deux couches différentes de la matrice?
Est-ce que travailler avec des sprites en 16 couleurs économise les capacités de l'ordi(comme ça, il peut tout mettre sur l'IA)?
Est-ce que le nombre de dimensions des matrices ralenti l'ordi(si c'est le cas, après la création de la carte, je peux tout envoyer dans une autre matrice)?
comment se superposent les sprites?
Exemple, dans les jeu en pseudo 3D, les perso peuvent passer devant ou derrière un obstacle.
où peut-on trouver des sprites de soldats, catapultes, .... vus d'en haut(c'est très rare!!!)
exemple( sprite 256 couleurs d'un jeu MSX2, retouché avec paint)
Comme ça ce n'est pas très parlant, animez-le vous verrez!
Merci d'avance!
.. et merci tout court! Sans le forum j'aurai jamais réussi à commencer!
Voilà, ça fait beaucoup de questions(j'en ai plein d'autres
