J'ai fait une copie no-media du programme.
Code : Tout sélectionner
Enumeration
#Void
#Mur
#Sol
#Player
#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
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()
CreateSprite(#Void, 64, 64)
StartDrawing(SpriteOutput(#Void))
Box(0, 0, 64, 64, RGB(0,0,0))
StopDrawing()
CreateSprite(#Mur, 64, 64)
StartDrawing(SpriteOutput(#Mur))
Box(0, 0, 64, 64, RGB(80,80,50))
StopDrawing()
CreateSprite(#Sol, 64, 64)
StartDrawing(SpriteOutput(#Sol))
Box(0, 0, 64, 64, RGB(70, 255, 170))
StopDrawing()
CreateSprite(#Player, 32, 32)
StartDrawing(SpriteOutput(#Player))
Circle(15,15, 16, RGB(155,155,255))
Circle(15,15, 10, RGB(255,0,255))
StopDrawing()
PlayerSize = SpriteHeight(#Player)
Restore Item
For y = 1 To MapH
For x = 1 To MapW
Read.i Item
Allmap(y, x) = Item
Next x
Next y
Repeat
ExamineKeyboard() : ExamineMouse() : ClearScreen(0)
oldPlayerX = PlayerX : oldPlayerY = PlayerY
If KeyboardPushed(#PB_Key_Up) : PlayerY - PlayerSpd : EndIf
If KeyboardPushed(#PB_Key_Left) : PlayerX - PlayerSpd : EndIf
If KeyboardPushed(#PB_Key_Down) : PlayerY + PlayerSpd : EndIf
If KeyboardPushed(#PB_Key_Right) : 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
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
Tuile = Allmap(b, a)
EndIf
If Tuile => 0 : DisplaySprite(Tuile, x * Bloc - OffsetBlocX, y * Bloc - OffsetBlocY) : EndIf
Next y
Next x
DisplayTransparentSprite(#Player, PlayerX, PlayerY)
DisplaySprite(#MsgBox, 0, MsgTexteX) : DisplaySprite(#HUDbox, HudX, 0)
StartDrawing(SpriteOutput(#MsgBox))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 30,"posX_Y",RGB(255,255,255))
DrawText(10, 50,"playerX_Y",RGB(255,255,0))
StopDrawing()
FlipBuffers()
Delay(1)
Until KeyboardPushed(#PB_Key_Escape) Or MouseButton(2)
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,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data.i 1,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,1
Data.i 1,2,1,2,2,2,2,2,2,2,2,2,2,2,1,2,1
Data.i 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data.i 1,2,2,1,2,1,1,1,1,1,1,1,2,1,2,2,1
Data.i 1,2,2,2,2,1,0,1,2,1,0,1,2,2,2,2,1
Data.i 1,2,2,2,2,1,0,1,2,1,0,1,2,2,2,2,1
Data.i 1,2,2,2,2,1,0,1,2,1,0,1,2,2,2,2,1
Data.i 1,2,2,2,2,1,0,1,2,1,0,1,2,2,2,2,1
Data.i 1,2,2,2,2,1,1,1,2,1,1,1,2,2,2,2,1
Data.i 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data.i 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data.i 1,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,1
Data.i 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data.i 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
EndDataSection
@Caporal : j'ai incorporé tes corrections, mais MsgBox est déjà noir de fond à l'application, ce n'est pas l'ajout du texte qui est en cause - facile à vérifier en « commentant » le StartDrawing().