- Mara-des-bois a écrit:
- coco! a écrit:
Mab tu voulais dire un migrant canadien ?
pour être plus précis un kébé quoi !!!!!!!
Nonon, les quebecois ont des accents sur leurs claviers.
Et puis c'est un admin, donc, forcement quelqu'un qui a les codes.
Quantat a raison, ça ne sent pas bon c't'histoire.
Mab
Mab Koganwel ......est un spécialiste des codes donc cela n'a pas du lui être difficile d'obtenir le code de LP
coco!
PS: la preuve :
Koganwel
Sujet du message:
MessagePosté: Jeu 27/Aoû/2009 17:22
Hors ligne
Inscription: Jeu 27/Aoû/2009 15:13
Messages: 11
C'est une adaptation PureBasic d'un code DBPro de Phaelax(2005)
Code:
XIncludeFile "d:\PureBasic\Include\keys.pbi"
Enumeration
#Void #Mur #ScrollUp ; *** > sprites utilisés pour étudier le scrolling
#ScrollDown #ScrollBoth #StopDown #StopUp #StopRight #StopLeft ; < ***
#Sol = 50 ; espace laissé pour des objets de collision
#PlayerR
#PlayerL
#MsgBox
#HUDbox
EndEnumeration
Read.i Bloc : Read.i MapW : Read.i MapH : Dim Allmap(MapH, MapW)
InitSprite() : InitMouse() : InitKeyboard() : UsePNGImageDecoder()
scrW = 1024 : scrH = 768 : OpenScreen( scrW, scrH, 32, "")
DisplayW = scrW / Bloc : DisplayH = scrH / Bloc : MsgBox = Bloc * 3 : HUDbox = Bloc * 4
StopScrollRight = ((MapW * Bloc) - (DisplayW - 1) * Bloc) + HUDbox
StopScrollDown = ((MapH * Bloc) - (DisplayH - 1) * Bloc) + MsgBox : GoScroll = Bloc * 4
ScrollRight = (scrW - HUDbox - PlayerSize) - GoScroll : ScrollDown = (scrH - MsgBox - PlayerSize) - GoScroll
MsgTexte = (DisplayH - 3) * Bloc : MX = Bloc : MY = Bloc
PlayerX = Bloc : PlayerY = Bloc : PlayerSpd = 3
MsgTexteX = scrH - MsgBox : HudX = scrW - HUDbox ; positionner les deux HUD
LoadSprite(#Void, "d:\aaa\64\Void64.png") : LoadSprite(#Mur, "d:\aaa\64\Wall64_I.png") : LoadSprite(#ScrollUp, "d:\aaa\64\ScrollUp.png") : LoadSprite(#ScrollDown, "d:\aaa\64\ScrollDown.png") : LoadSprite(#ScrollBoth, "d:\aaa\64\ScrollBoth.png")
LoadSprite(#StopDown, "d:\aaa\64\StopDown.png") : LoadSprite(#StopUp, "d:\aaa\64\StopUp.png") : LoadSprite(#StopRight, "d:\aaa\64\StopRight.png") : LoadSprite(#StopLeft, "d:\aaa\64\StopLeft.png")
LoadSprite(#Sol, "d:\aaa\64\Ground64_C.png") : LoadSprite(#PlayerR,"d:\aaa\32\RHeros32.png") : LoadSprite(#PlayerL,"d:\aaa\32\LHeros32.png")
;LoadSprite(#MsgBox,"d:\aaa\64\HUDhoriz.png")
LoadSprite(#HUDbox,"d:\aaa\64\HUDvert.png") :
PlayerSize = SpriteHeight(#PlayerL)
CreateSprite(#MsgBox, scrW - HUDbox, scrH - MsgBox)
StartDrawing(SpriteOutput(#MsgBox))
Box(0,scrH - MsgBox, scrW - HUDbox, scrH, RGB(80,80,50))
For i = 0 To 7 : LineXY(0,0+i,768, 0+i, RGB(50,50,255)) : Next i
StopDrawing()
CreateSprite(#HUDbox, 256, scrH)
StartDrawing(SpriteOutput(#HUDbox))
Box(scrW - HUDbox, 0, scrW , scrH, RGB(80,80,50))
For i = 0 To 7 : LineXY(0+i,0, 0+i, scrH, RGB(50,50,255)) : Next i
StopDrawing()
;{ préparer Allmap(17, 16)
Restore Item
For y = 1 To MapH
For x = 1 To MapW
Read.i Item
Allmap(y, x) = Item
Next x
Next y
;}
Repeat
;{ keyboard et scroll
ExamineKeyboard() : ExamineMouse()
oldPlayerX = PlayerX : oldPlayerY = PlayerY
If KeyUp : PlayerY - PlayerSpd : EndIf
If KeyLeft : Compas = 1 : PlayerX - PlayerSpd : EndIf
If KeyDown : PlayerY + PlayerSpd : EndIf
If KeyRight : Compas = 0 : PlayerX + PlayerSpd : EndIf
posX = PlayerX : posY = PlayerY
posX + (MX - Bloc) : posY + (MY - Bloc)
MapX1 = posX / Bloc + 1 : MapY1 = posY / Bloc + 1
MapX2 = (posX + PlayerSize) / Bloc + 1 : MapY2 = posY / Bloc + 1
MapX3 = posX / Bloc + 1 : MapY3 = (posY + PlayerSize) / Bloc + 1
MapX4 = (posX + PlayerSize) / Bloc + 1 : MapY4 = (posY + PlayerSize) / Bloc + 1
If Allmap(MapY1, MapX1) = 1 Or Allmap(MapY2, MapX2) = 1 Or Allmap(MapY3, MapX3) = 1 Or Allmap(MapY4, MapX4) = 1
PlayerX = oldPlayerX : PlayerY = oldPlayerY
EndIf
; ****** SCROLL
; LEFT
If PlayerX < GoScroll
If MX > Bloc
PlayerX = GoScroll : MX - PlayerSpd
Else
MX = Bloc
EndIf
EndIf
; RIGHT
If PlayerX > ScrollRight
If MX < StopScrollRight
PlayerX = ScrollRight
MX + PlayerSpd
Else
MX = StopScrollRight
EndIf
EndIf
; DOWN
If PlayerY > ScrollDown
If MY < StopScrollDown
PlayerY = ScrollDown
MY + PlayerSpd
Else
MY = StopScrollDown
EndIf
EndIf
; UP
If PlayerY < GoScroll
If MY > Bloc
PlayerY = GoScroll : MY - PlayerSpd
Else
MY = Bloc
EndIf
EndIf
mapX = MX / Bloc : mapY = MY / Bloc
OffsetBlocX = MX - mapX * Bloc : OffsetBlocY = MY - mapY * Bloc
;}
;{ afficher les sprites d'Allmap()
For x = 0 To DisplayW
For y = 0 To DisplayH
a = mapX + x : b = mapY + y
If a >= 0 And a <= MapW And b >= 0 And b <= MapH ; pas de débordement d'index du Tableau
Tuile = Allmap(b, a) ; lidentification des sprites
EndIf
If Tuile => 0 : DisplaySprite(Tuile, x * Bloc - OffsetBlocX, y * Bloc - OffsetBlocY) : EndIf ; actualiser l'objet découvert
Next y
Next x
;}
;{ DisplaySprite et DrawText
If Compas
DisplayTransparentSprite(
#PlayerL, PlayerX, PlayerY)
Else
DisplayTransparentSprite(
#PlayerR, PlayerX, PlayerY)
EndIf
DisplaySprite(
#MsgBox, 0, MsgTexteX) : DisplaySprite(
#HUDbox, HudX, 0)
StartDrawing(SpriteOutput(
#MsgBox))
FrontColor(RGB(255,255,255)) : BackColor(couleur2)
DrawText(10, 30,"posX_Y : " + Str(posX) + ", " + Str(posY) + " ")
DrawText(10, 50,"playerX_Y : " + Str(playerX) + ", " + Str(playerY) + " ")
StopDrawing()
FlipBuffers()
Delay(1)
;}
Until KeyEscape Or MouseButton(2)
;{ datasection
DataSection
Data.i 64, 17, 16
Item:
Data.i 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
Data.i 1,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50, 1
Data.i 1,50,50, 7,50,50,50,50, 4,50,50,50,50, 8,50,50, 1
Data.i 1,50, 6,50,50,50,50,50,50,50,50,50,50,50, 6,50, 1
Data.i 1,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50, 1
Data.i 1,50, 50,3,50, 1, 1, 1,50, 1, 1, 1,50, 3,50,50, 1
Data.i 1,50,50,50,50, 1, 0, 1,50, 1, 0, 1,50,50,50,50, 1
Data.i 1,50,50,50,50, 1, 0, 1,50, 1, 0, 1,50,50,50,50, 1
Data.i 1,50,50,50,50, 1, 0, 1,50, 1, 0, 1,50,50,50,50, 1
Data.i 1,50,50,50,50, 1, 0, 1,50, 1, 0, 1,50,50,50,50, 1
Data.i 1,50, 50,2,50, 1, 1, 1,50, 1, 1, 1,50, 2,50,50, 1
Data.i 1,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50, 1
Data.i 1,50, 5,50,50,50,50,50,50,50,50,50,50,50, 5,50, 1
Data.i 1,50,50, 7,50,50,50,50, 4,50,50,50,50, 8,50,50, 1
Data.i 1,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50, 1
Data.i 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
EndDataSection
;}
En utilisant des Box dans StartDrawing(ScreenOuput()) plutôt que des sprites, tout fonctionne très bien avec DrawText(), c'est le DrawText sur SpriteOutput() qui efface la couleur de fond. Toutefois, sur un petit programme d'essai affichant simplement MsgBox et le texte écrit dans le sprite, là de nouveau, c'était nickel. Mais il n'y avait rien à cacher, comme dans le cas du gros programme : les deux HUD cachent 256 et 192 px de l'écran en cours, camouflant le scrolling à venir.
Je vous offre ici le code non commenté, donc le plus court. Est-il possible d'ajouter un ZIP contenant le tout ? Si non, pour compiler, il suffit essentiellement de prévoir des sprites pour
#Mur,
#Sol et
#Player L et R si nécessaire, le reste sera noir. Dans le code étendu, je prévois une collision avec tout sprite en-dessous d'une valeur (théoriquement fixée à 49 - cf Enumeration,
#Sol = 50)
Haut