Need Help With Tetris Program

Shaq32
09-09-2009, 03:00 PM
I'm making a Tetris game for school, and I'm having a problem with stopping the shapes. Whenever I have a shape come down, I clear the form and repaint all the shapes back onto the form. Then I check boundaries around image1(image1.ubound) (the shape that is falling) by using GetPixel. Instead of just having one point on the bottom to check for a collision, I'm trying to loop through every pixel from the .left of the block to the .right of the block, and use the .top + .height for the Y value. I tried a couple different ways and I just can't get this working. I know something about this is wrong and I really need help.

Private Sub checkBoundaryColors()
With Image1(Image1.UBound)
For i = .Left To .Left + .Width - 2
shapeColorBottom = GetPixel(Me.hdc, i, .Top + .Height)
Select Case shapeColorBottom
Case DARK_GREY, LIGHT_GREY, GREY_LINES
'if the color around the shape is gray, it will move since it isn't
' touching a wall or another shape
.Top = .Top + MOVE_ONE_BLOCK
Case Else
'when a shape stops on another shape or the bottom, it changes to a darker color
Image1(Image1.UBound).Picture = LoadPicture(App.Path & "\Images\Dark Shapes\Dark " & shape & " " & shapeCounter & ".gif")
Call dropShape
End Select
Next i
End With
End Sub

I also uploaded the program itself if you want to see the whole thing and figure out what needs to be done.

Thanks :)

Cerian Knight
09-10-2009, 09:37 AM
It looks like a nice effort, so I thought I'd give you a hand:


Private Sub checkBoundaryColors()
Dim intLeft As Integer
Dim T1 As Single, T2 As Single
With Image1(Image1.UBound)
intLeft = .Left
i = intLeft
Do Until i > intLeft + .Width - 2
'For i = .Left To .Left + .Width - 2
shapeColorBottom = GetPixel(Me.hdc, i, .Top + .Height)
Select Case shapeColorBottom
Case DARK_GREY, LIGHT_GREY, GREY_LINES
'if the color around the shape is gray, it will move since it isn't
' touching a wall or another shape
.Top = .Top + MOVE_ONE_BLOCK
T1 = Timer
Do 'Start 1 second loop
If DoEvents = 0 Then Exit Sub 'prevent further object reference if form was unloaded
T2 = Timer
Loop While Abs(T2 - T1) < 1
If .Left <> intLeft Then i = .Left: intLeft = i 'resync object
Case Else
'when a shape stops on another shape or the bottom, it changes to a darker color
Image1(Image1.UBound).Picture = LoadPicture(App.Path & "\Images\Dark Shapes\Dark " & shape & " " & shapeCounter & ".gif")
Call dropShape
Exit Do 'Get out
End Select
'Next i
Loop
End With
End Sub
Not exactly fun to play quite yet, but it shows promise.

Also, remove the 'End' statements and put 'Unload {other forms name}' in 'Form Unload' event.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum