1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| ;Comtois 01/12/2008
InitSprite()
InitKeyboard()
OpenScreen(1024,768,32,"Map")
Enumeration
#Herbe
#Eau
#Bord
EndEnumeration
Structure S_Box
x.i
y.i
w.i
h.i
EndStructure
CreateSprite(#Bord,32,32)
CreateSprite(#Herbe,32,32)
CreateSprite(#Eau,32,32)
Declare DessineSprite(Sprite, Couleur)
Declare RandomMap()
Declare AfficheMap()
Declare AfficheBox()
Global Offset.POINT
Global ScreenBox.S_Box
ScreenBox\x=120
ScreenBox\y=100
ScreenBox\w=400
ScreenBox\h=400
DessineSprite(#Bord, #Red)
DessineSprite(#Herbe, #Green)
DessineSprite(#Eau, #Blue)
#Tx=20
#Ty=20
#Taille=32
Global Dim Map(#Tx,#Ty)
RandomMap()
Repeat
ClearScreen(0)
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Right) And Offset\x<(#Tx+1)*#Taille-ScreenBox\w
Offset\x + 1
ElseIf KeyboardPushed(#PB_Key_Left) And Offset\x>0
Offset\x - 1
EndIf
If KeyboardPushed(#PB_Key_Down) And Offset\y<(#Ty+1)*#Taille-ScreenBox\h
Offset\y + 1
ElseIf KeyboardPushed(#PB_Key_Up) And Offset\y>0
Offset\y - 1
EndIf
EndIf
AfficheMap()
AfficheBox()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Procedure DessineSprite(Sprite, Couleur)
If StartDrawing(SpriteOutput(Sprite))
Box(0,0,SpriteWidth(Sprite),SpriteHeight(Sprite),Couleur)
StopDrawing()
ProcedureReturn #True
EndIf
EndProcedure
Procedure RandomMap()
For y=0 To #Ty
For x=0 To #Tx
If x=0 Or x=#Tx Or y=0 Or y=#Ty Or x=#Tx/2 Or y=#Ty/2
Map(x,y)=#Bord
Else
Map(x,y)=Random(1)
EndIf
Next x
Next y
EndProcedure
Procedure AfficheBox()
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Outlined)
Box(ScreenBox\x,ScreenBox\y,ScreenBox\w,ScreenBox\h,#White)
StopDrawing()
EndProcedure
Procedure AfficheMap()
Define Src.S_Box, Des.S_Box
Src\y=Offset\y%#Taille
Src\h=#Taille-Src\y
Py=ScreenBox\y
y=Offset\y/#Taille
While Py<ScreenBox\y+ScreenBox\h
Px=ScreenBox\x
x=Offset\x/#Taille
Src\x=Offset\x%#Taille
Src\w=#Taille-Src\x
While Px<ScreenBox\x+ScreenBox\w
ClipSprite(Map(x,y),Src\x,Src\y,Src\w,Src\h)
DisplaySprite(Map(x,y),Px,Py)
Px+Src\w
x+1
Src\x=0
Src\w=#Taille
If (Px+Src\w)>(ScreenBox\x+ScreenBox\w)
Src\w=ScreenBox\x+ScreenBox\w-Px
EndIf
Wend
Py+Src\h
y+1
Src\y=0
Src\h=#Taille
If Py+Src\h>ScreenBox\y+ScreenBox\h
Src\h=ScreenBox\y+ScreenBox\h-Py
EndIf
Wend
EndProcedure |
Partager