wie kann ich ein Gitter über das Feld spannen damit es leichter ist?
(Also von links nach rechts und oben nach unten)
Danke für Hilfe.
Code: Alles auswählen
#Field = 0
#Field2 = 1
#Stone = 2
#Button = 3
#Text = 4
#Exit = 5
Structure Colum
Y.b[4]
EndStructure
Structure Types
X.Colum[4]
EndStructure
Structure StoneInfo
Mode.Types[4]
Color.l
pX.b
pY.b
pStart.b
EndStructure
Structure Row
X.b[10]
EndStructure
Structure FieldInfo
Y.Row[27]
EndStructure
Declare LineFull()
Declare EraseStone()
Declare DrawStone()
Declare DrawPre()
Declare Collision(xX.l, xY.l, xMode.l)
Declare XBox(sX.l, sY.l, Color.l)
CreateImage(#Field, 200, 460)
StartDrawing(ImageOutput()): Box(0, 0, 200, 460, $FFFFFF): StopDrawing()
CreateImage(#Stone,100, 100)
StartDrawing(ImageOutput()): Box(0, 0, 100, 100, $FFFFFF): StopDrawing()
OpenWindow(0, 0, 0, 340, 475, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_Screencentered, "Tetris")
CreateGadgetList(WindowID())
ImageGadget(#Field, 5, 5, 150, 460, UseImage(#Field), #PB_Image_Border)
ImageGadget(#Stone, 225, 20, 100, 100, UseImage(#Stone), #PB_Image_Border)
TextGadget(#Text, 225, 150, 100, 100, "Zeilen: 0"+Chr(13)+Chr(13)+Chr(13)+"Punkte: 0", #PB_Text_Center)
ButtonGadget(#Button, 235, 390, 80, 25, "Neues Spiel")
ButtonGadget(#Exit, 235, 420, 80, 25, "Ende")
ActivateGadget(#Button)
UseImage(#Field)
StartDrawing(ImageOutput())
For xX = 0 To 180 Step 20
For xY = 0 To 440 Step 20
XBox(xX, xY, PeekL(?StoneBase+64+Random(6)*SizeOf(StoneInfo)))
Next xY
Next xX
StopDrawing()
SetGadgetState(#Field, ImageID())
UseImage(#Stone)
StartDrawing(ImageOutput())
For xX = 0 To 100 Step 20
For xY = 0 To 100 Step 20
XBox(xX, xY, PeekL(?StoneBase+64+Random(6)*SizeOf(StoneInfo)))
Next xY
Next xX
StopDrawing()
SetGadgetState(#Stone, ImageID())
Global Speed, Count, Time, Lines, Points, X,Y,Type, Mode, nType, nMode, SpeedPlus
Global *Stone.StoneInfo
Global Field.FieldInfo
Count = 1
Repeat
Select WindowEvent()
Case #WM_KEYDOWN
If Speed > 0
key.l = EventwParam()
If key = #VK_ESCAPE: End
ElseIf key = $50
Speed = -Speed
ElseIf key = #VK_LEFT Or key = #VK_NUMPAD4
If Collision(X-1, Y, Mode)=#False
UseImage(#Field)
StartDrawing(ImageOutput())
EraseStone()
X - 1
DrawStone()
StopDrawing()
SetGadgetState(#Field, ImageID())
EndIf
ElseIf key = #VK_RIGHT Or key = #VK_NUMPAD6
If Collision(X+1, Y, Mode)=#False
UseImage(#Field)
StartDrawing(ImageOutput())
EraseStone()
X + 1
DrawStone()
StopDrawing()
SetGadgetState(#Field, ImageID())
EndIf
ElseIf key = #VK_NUMPAD5 Or key = #VK_UP Or key = #VK_NUMPAD8 ; Stein drehen
Mode2 = Mode + 1
If Mode2 = 4: Mode2 = 0: EndIf
If Collision(X, Y, Mode2)=#False
UseImage(#Field)
StartDrawing(ImageOutput())
EraseStone()
Mode = Mode2
DrawStone()
StopDrawing()
SetGadgetState(#Field, ImageID())
EndIf
ElseIf key = #VK_DOWN Or key = #VK_NUMPAD2
SpeedPlus + 100
ElseIf key = #VK_SPACE Or key = #VK_NUMPAD2
UseImage(#Field)
StartDrawing(ImageOutput())
EraseStone()
Repeat
Y + 1
Until Collision(X, Y+1, Mode)
DrawStone()
StopDrawing()
SetGadgetState(#Field, ImageID())
Goto StoneMove
EndIf
ElseIf Speed < 0
If EventwParam() = $50 ; P-Taste
Speed = -Speed
EndIf
EndIf
Case #PB_Eventgadget
If EventGadgetID() = #Exit: End: EndIf
Time = GetTickCount_()
Speed = 500
SpeedPlus = 0
Count = GetTickCount_()
Lines = 0
Points = 0
Type = Random(6)
Mode = Random(3)
nType = Random(6)
nMode = Random(3)
UseImage(#Field)
StartDrawing(ImageOutput()): Box(0, 0, 200, 460, $FFFFFF): StopDrawing()
SetGadgetState(#Field, ImageID())
For i = @Field To @Field + SizeOf(FieldInfo)-1
PokeB(i,0)
Next i
DrawPre()
X = 3
Y=*Stone\pStart
SetGadgetText(#Text, "Zeilen: "+Str(Lines)+Chr(13)+Chr(13)+Chr(13)+"Punkte: "+Str(Points))
ActivateGadget(#Field)
Case #PB_EventCloseWindow: End
EndSelect
If Speed > 0 And GetTickCount_()-Count > Speed-SpeedPlus
StoneMove:
Count = GetTickCount_()
If Speed > 5 And GetTickCount_()-Time > 30000
Time = GetTickCount_()
Speed - 50
EndIf
If Collision(X, Y+1, Mode)
For iX = 0 To 3
For iY = 0 To 3
If *Stone\Mode[Mode]\X[iX]\Y[iY] = 1
Field\Y[Y+iY]\X[X+iX] = 1
EndIf
Next iY
Next iX
pLine = 0
While LineFull(): pLine + 1:Wend
Lines + pLine
Points + 1
If pLine = 1: Points + 10
ElseIf pLine = 2: Points + 30
ElseIf pLine = 3: Points + 50
ElseIf pLine = 4: Points + 100
EndIf
SetGadgetText(#Text, "Zeilen: "+Str(Lines)+Chr(13)+Chr(13)+Chr(13)+"Punkte: "+Str(Points))
SpeedPlus = 0
Type = nType
Mode = nMode
nType = Random(6)
nMode = Random(3)
DrawPre()
X=3
Y=*Stone\pStart
If Collision(X,Y,Mode)
UseImage(#Field)
StartDrawing(ImageOutput())
For xX = 0 To 180 Step 20
For xY = 0 To 440 Step 20
XBox(xX, xY, PeekL(?StoneBase+64+Random(6)*SizeOf(StoneInfo)))
Next xY
Next xX
StopDrawing()
SetGadgetState(#Field, ImageID())
UseImage(#Stone)
StartDrawing(ImageOutput())
For xX = 0 To 100 Step 20
For xY = 0 To 100 Step 20
XBox(xX, xY, PeekL(?StoneBase+64+Random(6)*SizeOf(StoneInfo)))
Next xY
Next xX
StopDrawing()
SetGadgetState(#Stone, ImageID())
MessageRequester("Tetris","Game Over!",0)
ActivateGadget(#Button)
Speed = 0
EndIf
Else
UseImage(#Field)
StartDrawing(ImageOutput())
EraseStone()
Y + 1
DrawStone()
StopDrawing()
SetGadgetState(#Field, ImageID())
EndIf
EndIf
Delay(1)
ForEver
Procedure LineFull()
For iY = 0 To 26
full.l = 0
For iX = 0 To 9
full + Field\Y[iY]\X[iX]
Next iX
If full = 10
CopyMemory(@Field, @Field+10, iY*10)
For i = 0 To 10: PokeB(@Field+i, 0): Next i
GrabImage(#Field, #Field2, 0, 0, 200, (iY-4)*20)
UseImage(#Field)
StartDrawing(ImageOutput())
DrawImage(UseImage(#Field2), 0, 20)
Box(0,0,200,20,$FFFFFF)
StopDrawing()
FreeImage(#Field2)
SetGadgetState(#Field, UseImage(#Field))
ProcedureReturn #True
EndIf
Next iY
ProcedureReturn #False
EndProcedure
Procedure EraseStone()
For iX = 0 To 3
For iY = 0 To 3
If Y+iY > 3 And *Stone\Mode[Mode]\X[iX]\Y[iY] = 1
Box((X+iX)*20, (Y+iY-4)*20, 20, 20, $FFFFFF)
EndIf
Next iY
Next iX
EndProcedure
Procedure DrawStone()
For iX = 0 To 3
For iY = 0 To 3
If Y+iY > 3 And *Stone\Mode[Mode]\X[iX]\Y[iY] = 1
XBox((X+iX)*20, (Y+iY-4)*20, *Stone\Color)
EndIf
Next iY
Next iX
EndProcedure
Procedure DrawPre()
*Stone = ?StoneBase + nType * SizeOf(StoneInfo)
UseImage(#Stone)
StartDrawing(ImageOutput())
DrawingMode(0)
Box(0, 0, 100, 100, $FFFFFF)
For iX = 0 To 3
For iY = 0 To 3
If *Stone\Mode[Mode]\X[iX]\Y[iY] = 1
XBox(*Stone\pX+iX*20, *Stone\pY+iY*20, *Stone\Color)
EndIf
Next iY
Next iX
StopDrawing()
SetGadgetState(#Stone, ImageID())
*Stone = ?StoneBase + Type * SizeOf(StoneInfo)
EndProcedure
Procedure XBox(sX.l, sY.l, Color.l)
Box(sX, sY, 20, 20, Color)
Line(sX + 1, sY + 1, 18, 0, $FFFFFF)
Line(sX + 1, sY + 2, 0, 16, $FFFFFF)
Line(sX + 1, sY + 18, 18, 0, $888888)
Line(sX + 18, sY + 2, 0, 16, $888888)
EndProcedure
Procedure Collision(xX.l,xY.l,xMode.l)
For iX = 0 To 3
For iY = 0 To 3
If *Stone\Mode[xMode]\X[iX]\Y[iY] = 1
If iX+xX > 9 Or iX+xX < 0
ProcedureReturn #True
ElseIf iY+xY > 26
ProcedureReturn #True
ElseIf Field\Y[iY+xY]\X[iX+xX] = 1
ProcedureReturn #True
EndIf
EndIf
Next iY
Next iX
ProcedureReturn #False
EndProcedure
DataSection
StoneBase:
Data.b 0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0
Data.b 0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0
Data.b 0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0
Data.b 0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0
Data.l $FF0000
Data.b 10,10,1
Data.b 1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0
Data.b 1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0
Data.b 1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0
Data.b 1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0
Data.l $0000F3
Data.b 30,30,2
Data.b 0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0
Data.b 0,0,0,0,0,1,0,0,1,1,1,0,0,0,0,0
Data.b 0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,0
Data.b 0,0,0,0,1,1,1,0,0,1,0,0,0,0,0,0
Data.l $15ECFF
Data.b 20,20,2
Data.b 0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0
Data.b 1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0
Data.b 0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0
Data.b 1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0
Data.l $FFDF15
Data.b 20,20,2
Data.b 0,1,0,0,0,1,1,0,0,0,1,0,0,0,0,0
Data.b 0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0
Data.b 0,1,0,0,0,1,1,0,0,0,1,0,0,0,0,0
Data.b 0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0
Data.l $009EFF
Data.b 20,20,2
Data.b 1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0
Data.b 0,0,1,0,0,0,1,0,0,1,1,0,0,0,0,0
Data.b 0,0,0,0,1,0,0,0,1,1,1,0,0,0,0,0
Data.b 1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0
Data.l $00C900
Data.b 20,20,1
Data.b 0,0,0,0,0,0,1,0,1,1,1,0,0,0,0,0
Data.b 1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0
Data.b 1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0
Data.b 1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0
Data.l $000000
Data.b 20,20,1
EndDataSection