|
-
Jun 27th, 2001, 10:42 PM
#1
Thread Starter
New Member
Bet you cant figure this one out...
Well my other question was easy, but I have no clue how to do this one, and I tried asking elsewhere and noone bothered responding. So if you can figure it out - you are a genius.
Ill try to explain this as best I can, but to make seeing what I am doing eaiser goto http://games.swirve.com/ and click on cubix and play the game... this makes much more sence after having played it. As you can tell I am remaking Cubix in VB - for a school project.
Ok So far I have this, which selects a random color then fills the game area with random colored boxes. As you can see I have an array (Area()) which the sourceupperleftCorner that the color can be derived from.
Private Sub FillArea()
Do Until DestinationUpperLeftCornery = GameArea.Height - 20 And DestinationUpperLeftCornerx = GameArea.Width - 20
RandomNumber = Int((100 - 1 + 1) * Rnd) + 1
Call LevelDeterminer(RandomNumber)
Area(DestinationUpperLeftCornerx, DestinationUpperLeftCornery) = SourceUpperLeftCorner
Call DrawBox(DestinationUpperLeftCornerx, DestinationUpperLeftCornery, SourceUpperLeftCorner)
If Not DestinationUpperLeftCornerx >= GameArea.ScaleWidth Then
DestinationUpperLeftCornerx = DestinationUpperLeftCornerx + 20
Else
If Not DestinationUpperLeftCornery >= (GameArea.ScaleHeight) Then
DestinationUpperLeftCornery = (DestinationUpperLeftCornery + 20)
DestinationUpperLeftCornerx = 0
Else: Exit Sub
End If
End If
Loop
End Sub
Its kinof Laggy so I might go to direct draw, but Im kindof running out of time...
Anyway here is my problem, lets say you have:
red blue blue red
Blue Blue red red
I want the game to recognise when you click on a blue square that there are 4 of them tounching and then to delete the squares. So I will need the number touching and the coordinates of them.
I Figured I could do it with:
f Area(ClicklocationX, ClicklocationY) = Area((ClicklocationX + 20), ClicklocationY) Then
Right(RightIndex) = True
End If
If Area(ClicklocationX, ClicklocationY) = Area((ClicklocationX - 20), ClicklocationY) Then
Left(LeftIndex) = True
End If
If Area(ClicklocationX, ClicklocationY) = Area(ClicklocationX, (ClicklocationY + 20)) Then
Down(DownIndex) = True
End If
If Area(ClicklocationX, ClicklocationY) = Area(ClicklocationX, (ClicklocationY - 20)) Then
Up(UpIndex) = True
End If
and just loop it for every block found, but when there are squares you will end up with a infinite loop.... One solution I came up with was to temp change the value of the ones checked- but there are massive problems if they somehow dont get changed back and that only solves the loops- what do you do when there is more than 1 block togther...
Anyway play the game and it makes more sence.
Another problem is how to check if any 3 or more block combos exist anywhere in the field after each click
-
Jun 28th, 2001, 02:27 AM
#2
PowerPoster
Would you please use the [code] -keyword to post code? Or even better: Download one of the code formatting tools (like mine) ... just a hint
-
Jun 28th, 2001, 03:31 AM
#3
Thread Starter
New Member
Dont worry about finding a solution... I got a semi-working one with the changing values idea... It still needs some work but its 4 am here so Ill do it latter. I knew it possible to do- but it would be very long and probly laggy- so once I get it working Ill post it up (mabee with your tool) and you can see if there is any way to optimize it/ineffeciant code.
At least with code you will know what I am talking about...
-
Jun 28th, 2001, 03:43 PM
#4
Use Recursion. Create a 2D array of long values, and fill it with the colors, one space for each block. Then, write a recursion function to check if a block of the same color is touching the one you clicked.
Code:
Function RecursiveCheck(x as integer, y as integer, color as long)
if (Colors(x, y) = color) then
deleteBox(x, y)
RecursiveCheck(x - 1, y, color)
RecursiveCheck(x+1,y,color)
'// You get the idea
end if
end function
That should work, by checking where you clicked, and calling recursive function with the color, it will contine to check until there are no more blocks of color touching any other block.
Z.
-
Jun 28th, 2001, 10:32 PM
#5
Thread Starter
New Member
Thats what i did but it is way more bulky... I ll have to post it tommorow Im down to 2 small bugs but need to add in checking to make sure its 3 pices or more and make the pieces abouve move down...
-
Jun 29th, 2001, 04:00 AM
#6
Junior Member
unrelated topic: Ive played Earth 2025 for YEARS! Since it was Solaria.net! Im kickin booty now
-
Jun 30th, 2001, 01:26 AM
#7
Thread Starter
New Member
Yea Earth is cool
N E Way here is the code I came up with, its probly more than you need. Do you think there is anyway to make it run faster. And when you start clicking around the game field real fast you can get out of range subscripts... how do I make everything stop when you click on it once?
Code:
Private Sub Form_Load()
SourceUpperLeftCorner = 0
Lvl = 1
Call NewLevel
End Sub
Private Sub NewLevel()
GameArea.Cls
DestinationUpperLeftCornery = 0
DestinationUpperLeftCornerx = 0
Call FillArea
GameArea.Refresh
End Sub
Private Sub DrawBox(ByVal DestinationUpperLeftCornerx, ByVal DestinationUpperLeftCornery, SourceUpperLeftCorner)
Call BitBlt(GameArea.hDC, _
DestinationUpperLeftCornerx, _
DestinationUpperLeftCornery, _
20, _
20, _
picBlockStrip.hDC, _
0, _
SourceUpperLeftCorner, _
SRCCOPY)
GameArea.Refresh
End Sub
Private Sub LevelDeterminer(ByVal RandomNumber)
If Lvl <= 5 Then
If RandomNumber <= 33 Then
SourceUpperLeftCorner = 5
End If
If RandomNumber > 33 And RandomNumber <= 66 Then
SourceUpperLeftCorner = 45
End If
If RandomNumber > 66 Then
SourceUpperLeftCorner = 85
End If
End If
End Sub
Private Sub FillArea()
Do Until DestinationUpperLeftCornery = GameArea.Height - 20 And DestinationUpperLeftCornerx = GameArea.Width - 20
RandomNumber = Int((100 - 1 + 1) * Rnd) + 1
Call LevelDeterminer(RandomNumber)
Area((DestinationUpperLeftCornerx + 20), (DestinationUpperLeftCornery) + 20) = SourceUpperLeftCorner
Call DrawBox(DestinationUpperLeftCornerx, DestinationUpperLeftCornery, SourceUpperLeftCorner)
If Not DestinationUpperLeftCornerx >= (GameArea.ScaleWidth - 30) Then
DestinationUpperLeftCornerx = DestinationUpperLeftCornerx + 20
Else
If Not DestinationUpperLeftCornery >= (GameArea.ScaleHeight - 30) Then
DestinationUpperLeftCornery = (DestinationUpperLeftCornery + 20)
DestinationUpperLeftCornerx = 0
Else: Exit Sub
End If
End If
Loop
End Sub
Private Sub GameArea_Click()
Able = False
Dim ClickLocationX
Dim ClickLocationY
ClickLocationX = locationX
ClickLocationY = locationY
Dim CLF 'Stands for ColorLookingFor
Dim Endloop As Boolean
Endloop = False
Dim BoundBlocks
BoundBlocks = 0
ClickLocationX = (Int((ClickLocationX / 20) + 1) * 20)
ClickLocationY = (Int((ClickLocationY / 20) + 1) * 20)
CLF = Area(ClickLocationX, ClickLocationY)
Line1:
Do While Endloop = False ' Needs to run through one time- remeber how
If Area((ClickLocationX + 20), ClickLocationY) = CLF Then
Area((ClickLocationX + 20), ClickLocationY) = 1000
End If
If Area((ClickLocationX - 20), ClickLocationY) = CLF Then
Area((ClickLocationX - 20), ClickLocationY) = 1000
End If
If Area(ClickLocationX, (ClickLocationY + 20)) = CLF Then
Area(ClickLocationX, (ClickLocationY + 20)) = 1000
End If
If Area(ClickLocationX, (ClickLocationY - 20)) = CLF Then
Area(ClickLocationX, (ClickLocationY - 20)) = 1000
End If
'1000 = verified as part of chain
'1050 = verified and all surronding pieces checked
If Area(ClickLocationX, (ClickLocationY - 20)) = 1000 Then
Area(ClickLocationX, ClickLocationY) = 1050
BoundBlocks = BoundBlocks + 1
DeleteBlockx(BoundBlocks) = ClickLocationX
DeleteBlocky(BoundBlocks) = ClickLocationY
ClickLocationY = (ClickLocationY - 20) 'set so you check block
Area(ClickLocationX, ClickLocationY) = CLF
GoTo Line1
End If
If Area(ClickLocationX, (ClickLocationY + 20)) = 1000 Then
Area(ClickLocationX, ClickLocationY) = 1050
BoundBlocks = BoundBlocks + 1
DeleteBlockx(BoundBlocks) = ClickLocationX
DeleteBlocky(BoundBlocks) = ClickLocationY
ClickLocationY = (ClickLocationY + 20) 'set so you check block
Area(ClickLocationX, ClickLocationY) = CLF
GoTo Line1
End If
If Area((ClickLocationX + 20), ClickLocationY) = 1000 Then
Area(ClickLocationX, ClickLocationY) = 1050
BoundBlocks = BoundBlocks + 1
DeleteBlockx(BoundBlocks) = ClickLocationX
DeleteBlocky(BoundBlocks) = ClickLocationY
ClickLocationX = (ClickLocationX + 20) 'set so you check block
Area(ClickLocationX, ClickLocationY) = CLF
GoTo Line1
End If
If Area((ClickLocationX - 20), ClickLocationY) = 1000 Then
Area(ClickLocationX, ClickLocationY) = 1050
BoundBlocks = BoundBlocks + 1
DeleteBlockx(BoundBlocks) = ClickLocationX
DeleteBlocky(BoundBlocks) = ClickLocationY
ClickLocationX = (ClickLocationX - 20) 'set so you check block
Area(ClickLocationX, ClickLocationY) = CLF 'set back to original color to test blocks around it
GoTo Line1
Else: Endloop = True
End If
Area(ClickLocationX, ClickLocationY) = 1050
BoundBlocks = BoundBlocks + 1
DeleteBlockx(BoundBlocks) = ClickLocationX
DeleteBlocky(BoundBlocks) = ClickLocationY
Call GameBoardCheck(ClickLocationX, ClickLocationY, Endloop, CLF)
Loop
Call DeleteSquares(Endloop, BoundBlocks, CLF) 'Deletes squares or sets them back to normal
Call DropBoxes(ClickLocationX, ClickLocationY)
Able = True
End Sub
Private Sub GameArea_MouseMove(Button As Integer, _
Shift As Integer, x As Single, y As Single)
Text1.Text = x & " " & y
locationX = x
locationY = y
Call Commad1(locationX, locationY)
End Sub
Private Sub GameBoardCheck(ByRef ClickLocationX, ByRef ClickLocationY, ByRef Endloop As Boolean, ByVal CLF)
Dim GAX, GAY
GAX = 20 'GAX = GameAreaX start with 0
GAY = 20 'Start with 0
Do While Endloop = True
If Area(GAX, GAY) = 1000 Then
ClickLocationX = GAX
ClickLocationY = GAY
Area(ClickLocationX, ClickLocationY) = CLF
Endloop = False
Else:
If GAX < 300 Then
GAX = (GAX + 20)
Else
GAX = 0
If GAY < 200 Then
GAY = (GAY + 20)
Else
Exit Sub
End If
End If
End If
Loop
End Sub
Private Sub DeleteSquares(ByVal Endloop As Boolean, ByVal BoundBlocks, ByVal CLF)
Dim GAX, GAY
Dim BoundBlockIndex
BoundBlockIndex = BoundBlocks
If BoundBlocks >= 3 Then
Do Until BoundBlockIndex = 0
Call BitBlt(GameArea.hDC, (DeleteBlockx(BoundBlockIndex) - 20), _
(DeleteBlocky(BoundBlockIndex) - 20), 20, 20, picBlockStrip.hDC, 0, 205, BLACKNESS)
Area(DeleteBlockx(BoundBlockIndex), DeleteBlocky(BoundBlockIndex)) = 5000
BoundBlockIndex = (BoundBlockIndex - 1)
Loop
GameArea.Refresh
Else
Do Until BoundBlockIndex = 0
Area(DeleteBlockx(BoundBlockIndex), DeleteBlocky(BoundBlockIndex)) = CLF
BoundBlockIndex = (BoundBlockIndex - 1)
Loop
End If
End Sub
Private Sub DropBoxes(ByVal ClickLocationX, ByVal ClickLocationY)
End Sub
I still need to do the dropboxes code and the mouse over highlighting... the dropboxes shouldnt be too hard.. just take some logic, but how should I do it - set a timer and drop the blocks slowly somehow or just delete them and redraw them below.
The mouse highlighting shouldnt be too hard either.
The thing that really makes me wonder is after you click and the boxes move down you need to check if there are still any 3 or more matches anywhere... I have no clue how to do that other than start with the first block and run through them all looking for 3 connected blocks, but that would slow it down alot more...
One other thing... do I need to use randomize somewhere or something, because I get the same "random" gamefield configuration everytime I load up... I tried using form unload at the end, and having a button redraw the field, but every time you redraw you get exactly the same patters in the same order, its kindof freaky really, I dont worry to much now because its kindof convenient for debugging, but it needs to be fixed for the game.
As always thx for any help .
Last edited by Encomium; Jun 30th, 2001 at 01:33 AM.
-
Jun 30th, 2001, 01:34 AM
#8
In your click function, create a "Static inFunc as Boolean" variable. when you enter the function, check to see if it is True. if it is, exit sub. Else, set inFunc = True, do stuff, set inFunc = False. This way, the first time you click, it checks the variable and hey, its false. so, we set it to true, and do our stuff. but, you clicked again! So, we check the boolean, but, ut oh, its true. Exit func. then, the first click operation finishes, and sets inFunc back to false, and alls well.
Z.
-
Jun 30th, 2001, 02:10 AM
#9
Thread Starter
New Member
Thx Ill try that... Any other problems/unoptimle code? And anyone know the answers to my other qs?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|