Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Global Score,FallTime=400, FallTimeStandard = 400,lastfall,movetime=50, lastmove, GameMode =1, NextShape, CurrentShape
- Global Level = 1, NextScore = 100
- Global Korobeiniki,Background, Screen
- Const GSW = 11, GSH = 20
- Dim Blocks( GSW - 1 ,GSH - 1 )
- Dim Shape(4,2) ; 4 кирпича, 2 координаты: 1 = x, 2 = y
- Function CreateShape(fig, x=GSW/2-2,y=0)
- Select fig
- Case 1
- ; []
- ; []
- ; []
- ; []
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 1+x
- Shape(2,2) = 0+y
- Shape(3,1) = 2+x
- Shape(3,2) = 0+y
- Shape(4,1) = 3+x
- Shape(4,2) = 0+y
- Case 2
- ; [][][][]
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 0+x
- Shape(2,2) = 1+y
- Shape(3,1) = 0+x
- Shape(3,2) = 2+y
- Shape(4,1) = 0+x
- Shape(4,2) = 3+y
- Case 3
- ; []
- ; []
- ; [][]
- Shape(1,1) = 1+x
- Shape(1,2) = 0+y
- Shape(2,1) = 1+x
- Shape(2,2) = 1+y
- Shape(3,1) = 1+x
- Shape(3,2) = 2+y
- Shape(4,1) = 0+x
- Shape(4,2) = 2+y
- Case 4
- ; []
- ; [][][]
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 0+x
- Shape(2,2) = 1+y
- Shape(3,1) = 1+x
- Shape(3,2) = 1+y
- Shape(4,1) = 2+x
- Shape(4,2) = 1+y
- Case 5
- ; [][]
- ; []
- ; []
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 0+x
- Shape(2,2) = 1+y
- Shape(3,1) = 0+x
- Shape(3,2) = 2+y
- Shape(4,1) = 1+x
- Shape(4,2) = 0+y
- Case 6
- ; [][][]
- ; []
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 1+x
- Shape(2,2) = 0+y
- Shape(3,1) = 2+x
- Shape(3,2) = 0+y
- Shape(4,1) = 2+x
- Shape(4,2) = 1+y
- Case 7
- ; []
- ; []
- ; [][]
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 0+x
- Shape(2,2) = 1+y
- Shape(3,1) = 0+x
- Shape(3,2) = 2+y
- Shape(4,1) = 1+x
- Shape(4,2) = 2+y
- Case 8
- ; [][][]
- ; []
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 0+x
- Shape(2,2) = 1+y
- Shape(3,1) = 1+x
- Shape(3,2) = 0+y
- Shape(4,1) = 2+x
- Shape(4,2) = 0+y
- Case 9
- ; [][]
- ; []
- ; []
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 1+x
- Shape(2,2) = 0+y
- Shape(3,1) = 1+x
- Shape(3,2) = 1+y
- Shape(4,1) = 1+x
- Shape(4,2) = 2+y
- Case 10
- ; []
- ; [][][]
- Shape(1,1) = 0+x
- Shape(1,2) = 1+y
- Shape(2,1) = 1+x
- Shape(2,2) = 1+y
- Shape(3,1) = 2+x
- Shape(3,2) = 1+y
- Shape(4,1) = 2+x
- Shape(4,2) = 0+y
- Case 11
- ; [][]
- ; [][]
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 1+x
- Shape(2,2) = 0+y
- Shape(3,1) = 0+x
- Shape(3,2) = 1+y
- Shape(4,1) = 1+x
- Shape(4,2) = 1+y
- Case 12
- ; [][]
- ; [][]
- Shape(1,1) = 0+x
- Shape(1,2) = 1+y
- Shape(2,1) = 1+x
- Shape(2,2) = 0+y
- Shape(3,1) = 1+x
- Shape(3,2) = 1+y
- Shape(4,1) = 2+x
- Shape(4,2) = 0+y
- Case 13
- ; []
- ; [][]
- ; []
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 0+x
- Shape(2,2) = 1+y
- Shape(3,1) = 1+x
- Shape(3,2) = 1+y
- Shape(4,1) = 1+x
- Shape(4,2) = 2+y
- Case 14
- ; []
- ; [][]
- ; []
- Shape(1,1) = 1+x
- Shape(1,2) = 0+y
- Shape(2,1) = 0+x
- Shape(2,2) = 1+y
- Shape(3,1) = 1+x
- Shape(3,2) = 1+y
- Shape(4,1) = 0+x
- Shape(4,2) = 2+y
- Case 15
- ; [][]
- ; [][]
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 1+x
- Shape(2,2) = 0+y
- Shape(3,1) = 1+x
- Shape(3,2) = 1+y
- Shape(4,1) = 2+x
- Shape(4,2) = 1+y
- Case 16
- ; []
- ; [][][]
- Shape(1,1) = 0+x
- Shape(1,2) = 1+y
- Shape(2,1) = 1+x
- Shape(2,2) = 1+y
- Shape(3,1) = 2+x
- Shape(3,2) = 1+y
- Shape(4,1) = 1+x
- Shape(4,2) = 0+y
- Case 17
- ; []
- ; [][]
- ; []
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 0+x
- Shape(2,2) = 1+y
- Shape(3,1) = 0+x
- Shape(3,2) = 2+y
- Shape(4,1) = 1+x
- Shape(4,2) = 1+y
- Case 18
- ; [][][]
- ; []
- Shape(1,1) = 0+x
- Shape(1,2) = 0+y
- Shape(2,1) = 1+x
- Shape(2,2) = 0+y
- Shape(3,1) = 2+x
- Shape(3,2) = 0+y
- Shape(4,1) = 1+x
- Shape(4,2) = 1+y
- Case 19
- ; []
- ; [][]
- ; []
- Shape(1,1) = 1+x
- Shape(1,2) = 0+y
- Shape(2,1) = 1+x
- Shape(2,2) = 1+y
- Shape(3,1) = 1+x
- Shape(3,2) = 2+y
- Shape(4,1) = 0+x
- Shape(4,2) = 1+y
- End Select
- ;lastFall = MilliSecs()
- CurrentShape = fig
- End Function
- Function CheckShape()
- For i = 1 To 4
- x = Shape(i,1)
- y = Shape(i,2)
- If Shape(i,1) >= 0 And Shape(i,1) =< (GSW - 1) And Shape(i,2) >= 0 And Shape(i,2) =< (GSH - 1) Then
- If Blocks (Shape(i,1),Shape(i,2)) = 1 Then achtung = 1
- Else
- achtung = 1
- End If
- Next
- If Achtung Then Return 0 Else Return 1
- End Function
- Function GameOver()
- CopyRect 0,0,GraphicsWidth(), GraphicsHeight(), 0,0,FrontBuffer(),ImageBuffer(Screen)
- GameMode = 0
- End Function
- Function MoveShape(x)
- ; проверка
- For i = 1 To 4
- If Shape(i,1)+x > GSW - 1 Or Shape(i,1)+x < 0
- Achtung = 1
- Else
- If Blocks(Shape(i,1)+x,shape(i,2)) = 1
- Achtung = 1
- End If
- End If
- Next
- If Achtung = 0
- ; сдвиг в сторону
- For i = 1 To 4
- Shape(i,1) = Shape(i,1) +x
- Next
- End If
- End Function
- Function RotateShape()
- Select CurrentShape
- ; палка
- Case 1
- CreateShape(2,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(1,Shape(1,1),Shape(1,2))
- End If
- Case 2
- CreateShape(1,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(2,Shape(1,1),Shape(1,2))
- End If
- ; Г
- Case 3
- CreateShape(4,Shape(1,1)-1,Shape(1,2))
- If Not CheckShape() Then
- CreateShape(3,Shape(1,1),Shape(1,2))
- End If
- Case 4
- CreateShape(5,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(4,Shape(1,1),Shape(1,2))
- End If
- Case 5
- CreateShape(6,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(5,Shape(1,1),Shape(1,2))
- End If
- Case 6
- CreateShape(3,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(6,Shape(1,1)-1,Shape(1,2))
- End If
- ; L
- Case 7
- CreateShape(8,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(7,Shape(1,1),Shape(1,2))
- End If
- Case 8
- CreateShape(9,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(8,Shape(1,1),Shape(1,2))
- End If
- Case 9
- CreateShape(10,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(9,Shape(1,1),Shape(1,2)-1)
- End If
- Case 10
- CreateShape(7,Shape(1,1),Shape(1,2)-1)
- If Not CheckShape() Then
- CreateShape(10,Shape(1,1)-1,Shape(1,2))
- End If
- ; S
- Case 12
- CreateShape(13,Shape(1,1),Shape(1,2)-1)
- If Not CheckShape() Then
- CreateShape(12,Shape(1,1),Shape(1,2))
- End If
- Case 13
- CreateShape(12,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(13,Shape(1,1),Shape(1,2)-1)
- End If
- ; Z
- Case 14
- CreateShape(15,Shape(1,1)-1,Shape(1,2))
- If Not CheckShape() Then
- CreateShape(14,Shape(1,1),Shape(1,2))
- End If
- Case 15
- CreateShape(14,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(15,Shape(1,1)-1,Shape(1,2))
- End If
- ; фигурка с пиписькой :)
- Case 16
- CreateShape(17,Shape(1,1),Shape(1,2)-1)
- If Not CheckShape() Then
- CreateShape(16,Shape(1,1),Shape(1,2))
- End If
- Case 17
- CreateShape(18,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(17,Shape(1,1),Shape(1,2))
- End If
- Case 18
- CreateShape(19,Shape(1,1),Shape(1,2))
- If Not CheckShape() Then
- CreateShape(18,Shape(1,1)-1,Shape(1,2))
- End If
- Case 19
- CreateShape(16,Shape(1,1)-1,Shape(1,2))
- If Not CheckShape() Then
- CreateShape(19,Shape(1,1),Shape(1,2)-1)
- End If
- End Select
- End Function
- Function UpdateBlocks()
- For y = 0 To GSH - 1
- Achtung = 0
- For x = 0 To GSW - 1
- If Blocks(x,y) <> 1 Then Achtung = 1
- Next
- If Achtung = 0
- For i = 0 To GSW - 1
- For j = y-1 To 0 Step -1
- Blocks(i,j+1)=Blocks(i,j)
- Next
- Next
- CountLines = CountLines + 1
- End If
- Next
- If Countlines <> 0 Then Score = Score + 30*CountLines*level + (2*level)^CountLines
- If Score >= NextScore Then
- level = level +1
- NextScore = (level^2)*200
- FallTimeStandard = 800/Sqr(level)
- End If
- End Function
- Function UpdateShape()
- If MilliSecs() - LastFall > FallTime Then
- LastFall = MilliSecs()
- ; проверка
- For i = 1 To 4
- If Shape(i,2)+1 > GSH - 1
- Achtung = 1
- Else
- If Blocks(Shape(i,1),Shape(i,2)+1) = 1
- Achtung = 1
- End If
- End If
- Next
- If Achtung = 0
- ; сдвиг вниз + отрисовка
- For i = 1 To 4
- Shape(i,2) = Shape(i,2) +1
- Text Shape(i,1)*20+20,Shape(i,2)*20+20, "[]"
- Next
- Else
- ; удаление фигуры в игровое поле
- For i = 1 To 4
- Blocks(Shape(i,1),Shape(i,2)) = 1
- Next
- CreateShape(NextShape)
- If Not CheckShape() Then GameOver()
- CurrentShape = NextShape
- NextShape = Rnd(1,19)
- End If
- Else
- For i = 1 To 4
- Text Shape(i,1)*20+20,Shape(i,2)*20+20, "[]"
- Next
- End If
- End Function
- Function DrawGameScreen()
- DrawImage Background, 0,0
- Rect 20,20,220,400,0
- Text 20,430,"Уровень "+Level;+" Следующий уровень: "+NextScore+" очков"
- Text 20,450,"Набрано очков: "+Score
- For i = 0 To GSW - 1
- For j = 0 To GSH -1
- If Blocks(i , j) = 1
- Text i*20+20,j*20+20,"[]"
- End If
- Next
- Next
- Text 450,430,"Программист: Дмитрий Маслов aka ABTOMAT",1
- Text 450,450,"РСФСР, Ленинград 2008",1
- End Function
- Function DrawGameOverScreen()
- DrawImage (Screen,0,0)
- Color 255,255,255
- Rect 10,200,240,80,0
- Color 0,0,0
- Rect 11,201,238,78
- Color 255,255,255
- Text 125,215,"Вы проиграли!",1
- Text 125,235,"Вы набрали "+score+" очков",1
- Text 125,255,"Escape - выход из программы",1
- End Function
- Function LoadImages()
- Background = LoadImage ("Background.bmp")
- End Function
- Function LoadFonts()
- FixedFont = LoadFont("FixedSys",10)
- SetFont FixedFont
- End Function
- Function LoadSounds()
- PlayMusic("Music1.mid");("01 - Du hast (Single Ver).mp3")
- End Function
- Graphics3D 640,480,32,1
- SetBuffer BackBuffer()
- SeedRnd(MilliSecs())
- Screen = CreateImage (GraphicsWidth(), GraphicsHeight())
- nextshape = Rnd(1,2)
- CurrentShape = Rnd(1,2)
- CreateShape(CurrentShape)
- LoadFonts()
- LoadImages()
- LoadSounds()
- GameMode = 1
- Repeat
- Cls()
- Select GameMode
- Case 1
- If KeyHit(32) Or KeyDown(32) Or KeyHit(205) Or KeyDown(205)Then
- If MilliSecs() - Lastmove > Movetime
- MoveShape(1)
- LastMove = MilliSecs()
- End If
- End If
- If KeyHit(30) Or KeyDown(30) Or KeyHit(203) Or KeyDown(203) Then
- If MilliSecs() - Lastmove > Movetime
- MoveShape(-1)
- LastMove = MilliSecs()
- End If
- End If
- If KeyDown(31) Or KeyHit (31) Or KeyHit(208) Or KeyDown(208) Then
- If FallTimeStandard > 50 Then Falltime = 50 Else Falltime = FallTimeStandard/2
- Else
- FallTime = FallTimeStandard
- End If
- If KeyHit(57) Or KeyHit(82) Then RotateShape()
- UpdateBlocks()
- UpdateShape()
- DrawGameScreen()
- Flip
- Case 0
- DrawGameOverScreen()
- Flip
- End Select
- Until KeyHit(1)
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement