Editeur de carte
Publié : lun. 18/oct./2004 17:52

Code : Tout sélectionner
;Comtois
;Le 18/07/04
;PB 3.91 V0.0
#ScreenWidth = 1024
#ScreenHeight = 768
#ScreenDepth = 32
#MaxX = 25
#MaxY = 17
#SizeX = 32
#SizeY = 32
#OffSetX = 16
#OffSetY = 16
#NbBrique = 13
#Maison = #NbBrique + 1
;{- Initialisation
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester( "Erreur" , "Impossible d'initialiser DirectX 7 Ou plus" , 0 )
End
ElseIf OpenScreen( #ScreenWidth , #ScreenHeight , #ScreenDepth , "M3D_Matrix3D" ) = 0
MessageRequester( "Erreur" , "Impossible d'ouvrir l'écran " , 0 )
End
EndIf
;}
UsePNGImageDecoder()
Structure Brique
x.l
y.l
EndStructure
Dim BriqueCollision(#NbBrique)
Dim Map(#MaxX, #MaxY)
Dim Maison.Brique(1)
Global Niveau
;Charge les sprites
For a = 1 To #NbBrique
LoadSprite(a, "images\img" + Str(a) + "a.png")
Next
LoadSprite(#Maison, "images\maison1.png")
;- Procedures
Procedure SaveNiveau()
If OpenFile(0, "Niveaux\Niveau" + Str(Niveau) + ".map")
WriteLong(Maison(0)\x)
WriteLong(Maison(0)\y)
WriteLong(Maison(1)\x)
WriteLong(Maison(1)\y)
For y = 0 To #MaxY - 1
For x = 0 To #MaxX - 1
WriteLong(Map(x, y))
Next x
Next y
CloseFile(0)
EndIf
EndProcedure
Procedure LoadNiveau()
If OpenFile(0, "Niveaux\Niveau" + Str(Niveau) + ".map")
Maison(0)\x = ReadLong()
Maison(0)\y = ReadLong()
Maison(1)\x = ReadLong()
Maison(1)\y = ReadLong()
For y = 0 To #MaxY - 1
For x = 0 To #MaxX - 1
Map(x, y) = ReadLong()
Next x
Next y
CloseFile(0)
EndIf
EndProcedure
Procedure FillMap(Brique.l)
For y = 0 To #MaxY - 1
For x = 0 To #MaxX - 1
If Map(x, y) = 0
Map(x,y) = Brique
EndIf
Next x
Next y
EndProcedure
Procedure AfficheNiveau()
For y = 0 To #MaxY - 1
For x = 0 To #MaxX - 1
If Map(x, y)
DisplayTransparentSprite(Map(x, y), x * #SizeX, y * #SizeY)
EndIf
Next x
Next y
DisplayTransparentSprite(#Maison,Maison(0)\x * #SizeX, Maison(0)\y * #SizeY)
DisplayTransparentSprite(#Maison,Maison(1)\x * #SizeX, Maison(1)\y * #SizeY)
EndProcedure
Procedure Affaide()
StartDrawing(ScreenOutput())
FrontColor(255,255,255)
DrawingMode(1)
Locate(10,580)
DrawText("Niveau => " + Str(Niveau))
StopDrawing()
EndProcedure
;- Boucle principale
NoBrique = 1
Niveau = 1
Repeat
ClearScreen(0, 0, 0)
;Affiche les briques
For a = 1 To #NbBrique
DisplaySprite(a,#ScreenWidth - #SizeX, a * #SizeY)
Next a
DisplaySprite(#Maison,#ScreenWidth - #SizeX, #NbBrique * #SizeY + #SizeY)
AfficheNiveau()
;Affiche la souris
DisplayTransparentSprite(NoBrique,MouseX() - #OffSetX,MouseY() - #OffSetY)
StartDrawing(ScreenOutput())
DrawingMode(4)
Box(MouseX()- #OffSetX, MouseY()- #OffSetY, #SizeX, #SizeY, RGB(255,255,255))
StopDrawing()
;Test la souris
If ExamineMouse()
If MouseButton(1)
Mx = MouseX()
My = MouseY()
If Mx > #ScreenWidth - #SizeX And Mx < #ScreenWidth
If My > #SizeY And My < #Maison * #SizeY + #SizeY
NoBrique = My / #SizeY
EndIf
EndIf
If Mx > 0 And Mx < #MaxX * #SizeX + #SizeX
If My > 0 And My < #MaxY * #SizeY + #SizeY
x = Mx / #SizeX
y = My / #SizeY
If NoBrique = #Maison
Maison(0)\x = x
Maison(0)\y = y
Else
Map(x, y) = NoBrique
EndIf
EndIf
EndIf
EndIf
If MouseButton(2)
Mx = MouseX()
My = MouseY()
If Mx > 0 And Mx < #MaxX * #SizeX + #SizeX
If My > 0 And My < #MaxY * #SizeY + #SizeY
x = Mx / #SizeX
y = My / #SizeY
If NoBrique = #Maison
Maison(1)\x = x
Maison(1)\y = y
Else
FillMap(NoBrique)
EndIf
EndIf
EndIf
EndIf
EndIf
;Test le clavier
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_F1)
SaveNiveau()
EndIf
If KeyboardReleased(#PB_Key_F2)
LoadNiveau()
AfficheNiveau()
EndIf
If KeyboardReleased(#PB_Key_F5) And Niveau > 1
Niveau - 1
EndIf
If KeyboardReleased(#PB_Key_F6)
Niveau + 1
EndIf
EndIf
Affaide()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Code : Tout sélectionner
If MouseButton(1)
Mx = MouseX()
My = MouseY()
If Mx > #ScreenWidth - #SizeX And Mx < #ScreenWidth
If My > #SizeY And My < #Maison * #SizeY + #SizeY
NoBrique = My / #SizeY
EndIf
EndIf
If Mx > 0 And Mx < #MaxX * #SizeX + #SizeX
If My > 0 And My < #MaxY * #SizeY + #SizeY
x = Mx / #SizeX
y = My / #SizeY
If NoBrique = #Maison
Maison(0)\x = x
Maison(0)\y = y
Else
Map(x, y) = NoBrique
EndIf
EndIf
EndIf
EndIf
If MouseButton(2)
Mx = MouseX()
My = MouseY()
If Mx > 0 And Mx < #MaxX * #SizeX + #SizeX
If My > 0 And My < #MaxY * #SizeY + #SizeY
x = Mx / #SizeX
y = My / #SizeY
If NoBrique = #Maison
Maison(1)\x = x
Maison(1)\y = y
Else
FillMap(NoBrique)
EndIf
EndIf
EndIf
EndIf
Code : Tout sélectionner
If AffichPointeur = 0
DisplayTransparentSprite(#Pointeur,x-SpriteWidth(0)/100, y-SpriteHeight(0)/100)
TransparentSpriteColor(#Pointeur, $0,$0,$0)
EndIf
If x > 950 And y > 150 And y < 173 And x < 973 And MouseButton(1)
AffichHerbe = 1
AffichPointeur = 1
AffichMur = 0
EndIf
If x > 950 And y > 200 And y < 250 And x < 973 And MouseButton(1)
AffichPointeur = 0
AffichSelection = 0
AffichSelectionMur = 0
AffichSelectionHerbe = 0
EndIf
If x > 950 And y > 100 And y < 133 And x < 973 And MouseButton(1)
AffichPointeur = 1
AffichMur = 1
AffichHerbe = 0
EndIf
If AffichPointeur = 1 And AffichMur = 1
DisplayTransparentSprite(#Mur, x-SpriteWidth(0)/100, y-SpriteHeight(0)/100)
AffichSelection = 1
AffichSelectionHerbe = 0
EndIf
If AffichHerbe = 1 And AffichPointeur = 1
DisplayTransparentSprite(#herbe, x-SpriteWidth(0)/100, y-SpriteHeight(0)/100)
AffichSelection = 2
AffichSelectionHerbe = 1
EndIf
If AffichSelection = 0
AffichSelectionPointeur = 1
EndIf
If AffichSelectionPointeur = 1
DisplaySprite(#Pointeur,11 , 13)
EndIf
If AffichSelection = 1
AffichSelectionMur = 1
EndIf
If AffichSelectionMur = 1
DisplaySprite(#Mur,1 , 1)
EndIf
If AffichSelection = 2
AffichSelectionHerbe = 1
EndIf
If AffichSelectionHerbe = 1
DisplaySprite(#herbe,1 , 1)
EndIf
EndIf
Code : Tout sélectionner
InitKeyboard()
InitSprite()
InitMouse()
OpenScreen(1024,768,32,"")
Enumeration
#Mur
#herbe
#Pointeur
#Selection
EndEnumeration
;On charge le sprite du pointeur de la souris et le fond
LoadSprite(#Pointeur, "Pointeur.bmp")
AffichPointeur = 0
AffichHerbe = 0
AffichMur = 0
AffichSelection = 0
AffichSelectionPointeur = 0
AffichSelectionMur = 0
AffichSelectionHerbe = 0
;Sprite Mur
CreateSprite(#Mur,32,32)
StartDrawing(SpriteOutput(#Mur))
Box(0,0,32,32,RGB($41,$61,$F5))
For i = 0 To 100
Line(Random(32) , Random(32) , 10, 10, RGB($5E,$C4,$D9))
Next
StopDrawing()
;Sprite Herbe
CreateSprite(#herbe,32,32)
StartDrawing(SpriteOutput(#herbe))
Box(0,0,32,32,RGB($FA,$3D,$3D))
For i = 0 To 100
Plot(Random(32) , Random(32) , RGB($F9,$FF,$AE))
Next
StopDrawing()
CreateSprite(#Selection,34,34)
StartDrawing(SpriteOutput(#Selection))
DrawingMode(4)
Box(0,0,34 ,34 ,RGB($54,$F5,$50))
StopDrawing()
Repeat
ClearScreen(0,0,0)
ExamineKeyboard()
DisplaySprite(#Mur,950 , 100)
DisplaySprite(#herbe,950 , 150)
DisplaySprite(#Pointeur,960 , 200)
DisplaySprite(#Selection,0 , 0)
ExamineMouse()
x = MouseX()
y = MouseY()
If AffichPointeur = 0
DisplayTransparentSprite(#Pointeur,x-SpriteWidth(0)/100, y-SpriteHeight(0)/100)
TransparentSpriteColor(#Pointeur, $0,$0,$0)
EndIf
If x > 950 And y > 150 And y < 173 And x < 973 And MouseButton(1)
AffichHerbe = 1
AffichPointeur = 1
AffichMur = 0
EndIf
If x > 950 And y > 200 And y < 250 And x < 973 And MouseButton(1)
AffichPointeur = 0
AffichSelection = 0
AffichSelectionMur = 0
AffichSelectionHerbe = 0
EndIf
If x > 950 And y > 100 And y < 133 And x < 973 And MouseButton(1)
AffichPointeur = 1
AffichMur = 1
AffichHerbe = 0
EndIf
If AffichPointeur = 1 And AffichMur = 1
DisplayTransparentSprite(#Mur, x-SpriteWidth(0)/100, y-SpriteHeight(0)/100)
AffichSelection = 1
AffichSelectionHerbe = 0
EndIf
If AffichHerbe = 1 And AffichPointeur = 1
DisplayTransparentSprite(#herbe, x-SpriteWidth(0)/100, y-SpriteHeight(0)/100)
AffichSelection = 2
AffichSelectionHerbe = 1
EndIf
If AffichSelection = 0
AffichSelectionPointeur = 1
EndIf
If AffichSelectionPointeur = 1
DisplaySprite(#Pointeur,11 , 13)
EndIf
If AffichSelection = 1
AffichSelectionMur = 1
EndIf
If AffichSelectionMur = 1
DisplaySprite(#Mur,1 , 1)
EndIf
If AffichSelection = 2
AffichSelectionHerbe = 1
EndIf
If AffichSelectionHerbe = 1
DisplaySprite(#herbe,1 , 1)
EndIf
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
Code : Tout sélectionner
;Affiche les briques
For a = 1 To #NbBrique
DisplaySprite(a,#ScreenWidth - #SizeX, a * #SizeY)
Next a
Code : Tout sélectionner
for i=1 to 4
DisplaySprite(i, MiniX + ((i-1) * 32),miniY)
next i
Code : Tout sélectionner
If MouseButton(1)
Mx = MouseX()
My = MouseY()
If Mx > miniX And Mx < MaxiX
If My > MiniY And My < MaxiY
;Calcul le No du tile
NoTile =' (Mx-miniX) /32)+1
EndIf
EndIf
endif
Code : Tout sélectionner
InitKeyboard()
InitSprite()
InitMouse()
OpenScreen(1024,768,32,"")
Enumeration
#efface
#Mur
#herbe
#Pointeur
#Selection
EndEnumeration
AffichPointeur = 0
AffichHerbe = 0
AffichMur = 0
AffichSelection = 0
AffichSelectionPointeur = 0
AffichSelectionMur = 0
AffichSelectionHerbe = 0
Dim Map(20,15)
;Sprite Efface
CreateSprite(#efface,32,32)
;Sprite Mur
CreateSprite(#Mur,32,32)
StartDrawing(SpriteOutput(#Mur))
Box(0,0,32,32,RGB($41,$61,$F5))
For i = 0 To 100
Line(Random(32) , Random(32) , 10, 10, RGB($5E,$C4,$D9))
Next
StopDrawing()
;Sprite Herbe
CreateSprite(#herbe,32,32)
StartDrawing(SpriteOutput(#herbe))
Box(0,0,32,32,RGB($FA,$3D,$3D))
For i = 0 To 100
Plot(Random(32) , Random(32) , RGB($F9,$FF,$AE))
Next
StopDrawing()
CreateSprite(#Selection,34,34)
StartDrawing(SpriteOutput(#Selection))
DrawingMode(4)
Box(0,0,34 ,34 ,RGB($54,$F5,$50))
StopDrawing()
CreateSprite(#Pointeur,34,34)
StartDrawing(SpriteOutput(#Pointeur))
DrawingMode(4)
Box(0,0,4 ,34 ,RGB(255,255,255))
StopDrawing()
Repeat
ClearScreen(0,0,0)
;affiche la map
For v=0 To 14
For u=0 To 19
DisplaySprite(Map(u,v),u*32,v*32)
Next u
Next v
ExamineKeyboard()
DisplaySprite(#Mur,950 , 100)
DisplaySprite(#herbe,950 , 150)
DisplaySprite(#Pointeur,960 , 200)
DisplaySprite(#Selection,0 , 0)
ExamineMouse()
x = MouseX()
y = MouseY()
If AffichPointeur = 0
DisplayTransparentSprite(#Pointeur,x-SpriteWidth(0)/100, y-SpriteHeight(0)/100)
TransparentSpriteColor(#Pointeur, $0,$0,$0)
EndIf
If MouseButton(1)
If x > 950 And y > 150 And y < 173 And x < 973
AffichHerbe = 1
AffichPointeur = 1
AffichMur = 0
EndIf
If x > 950 And y > 200 And y < 250 And x < 973
AffichPointeur = 0
AffichSelection = 0
AffichSelectionMur = 0
AffichSelectionHerbe = 0
EndIf
If x > 950 And y > 100 And y < 133 And x < 973
AffichPointeur = 1
AffichMur = 1
AffichHerbe = 0
EndIf
; test si dans la map
If x<20*32 And y<15*32
tx=x/32 ; il faut que chaque Tile fasse 32x32
ty=y/32
If AffichHerbe
Map(tx,ty)=#herbe
ElseIf AffichMur
Map(tx,ty)=#Mur
EndIf
EndIf
EndIf
;Si bouton droit , on efface
If MouseButton(2)
; test si dans la map
If x<20*32 And y<15*32
tx=x/32 ; il faut que chaque Tile fasse 32x32
ty=y/32
Map(tx,ty)=#efface
EndIf
EndIf
If AffichPointeur = 1 And AffichMur = 1
DisplayTransparentSprite(#Mur, x-SpriteWidth(0)/100, y-SpriteHeight(0)/100)
AffichSelection = 1
AffichSelectionHerbe = 0
EndIf
If AffichHerbe = 1 And AffichPointeur = 1
DisplayTransparentSprite(#herbe, x-SpriteWidth(0)/100, y-SpriteHeight(0)/100)
AffichSelection = 2
AffichSelectionHerbe = 1
EndIf
If AffichSelection = 0
AffichSelectionPointeur = 1
EndIf
If AffichSelectionPointeur = 1
DisplaySprite(#Pointeur,11 , 13)
EndIf
If AffichSelection = 1
AffichSelectionMur = 1
EndIf
If AffichSelectionMur = 1
DisplaySprite(#Mur,1 , 1)
EndIf
If AffichSelection = 2
AffichSelectionHerbe = 1
EndIf
If AffichSelectionHerbe = 1
DisplaySprite(#herbe,1 , 1)
EndIf
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
Code : Tout sélectionner
For V=0 To 17
For u=0 To 24
DisplaySprite(Map(u,V),u*32,138 + V*32)
Next u
Next V
Code : Tout sélectionner
; test si dans la map
If x<20*32 And y<15*32
tx=x/32 ; il faut que chaque Tile fasse 32x32
ty=y/32
If AffichHerbe
Map(tx,ty)=#herbe
ElseIf AffichMur
Map(tx,ty)=#Mur
EndIf
EndIf