BreakOut Debugging

scytheuk
03-20-2002, 05:49 AM
Ive started programming a simple breakout game and have came across a problem in the collision of the ball with a block.
The ball seems to pass through some blocks, before colliding, or it does collide at all.

Can any of you people take a peek at the code and let me know why.

Pookie
03-20-2002, 06:24 AM
Man you put a lot of stuff on those if then lines... that's why you can't find it error..


Shape1.Left <= Shape2(I).Left + Shape2(I).Width


You forgot to put that after it as it's not testing the whole width of the shape.

trevland06
03-20-2002, 06:28 AM
Did you use copy and paste on the rectangles?? because. sure all the names say shape1 but look uin the grey box above it (caption).. it says Shape1(2) Shape1(3) etc etc...

that happened to me on my math program

scytheuk
03-20-2002, 06:28 AM
can you post the whole COLLISIONDETECTION procedure.

i was editing the code when vb6.exe crashed and saved over the previous version.

Thanx

Scytheuk

The shape1(1), (2), etc ... is because they are in a control array

Pookie
03-20-2002, 06:33 AM
If Shape1.Top <= Val(Shape2(I).Top) + Shape2(I).Height _
And Shape1.Left >= Shape2(I).Left _
And Shape1.Left <= Shape2(I).Left + Shape2(I).Width _
And Label1 = "NW" _
And Shape2(I).Visible = True Then
Shape2(I).Visible = False
Label1 = "SW"
End If

If Shape1.Top <= Val(Shape2(I).Top) + Shape2(I).Height _
And Shape1.Left >= Shape2(I).Left _
And Shape1.Left <= Shape2(I).Left + Shape2(I).Height _
And Label1 = "NE" _
And Shape2(I).Visible = True Then
Shape2(I).Visible = False
Label1 = "SE"
End If


I've tested it, it's better but still missing block so I'll look at it in a bit more detail for ya. :)

Pookie
03-20-2002, 06:41 AM
Oops. :)

I wrote .height in the second If statement, It should be .width

scytheuk
03-20-2002, 06:45 AM
Works better then it did.
Thanx
Scytheuk

Now to edit bounce code and collision from top.

scytheuk
03-20-2002, 08:27 AM
I Wanna Cry!!!:(

I cant get my head around this collision code.

Has Anyone got any idea how i can detect collision form above?
Ive tried everything and my heads starting to hurt

Pookie
03-20-2002, 08:30 AM
Don't know why you are having trouble for. What I posted in reply, with that code, made the game worked fine on my computer.... :confused:

Pookie
03-20-2002, 08:33 AM
ahhh. I see, you having trouble if the ball hits the blocks from above?..... hmmm....

Well those two IF Then won't work on the way down cause they test for 'NW' and 'NE' but not for 'SW' and "SE"

Pookie
03-20-2002, 09:00 AM
Okay, here is your new working code:
(It was a rush job so didn't bother to much about formatting it properly)



Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
Case vbKeyLeft
Line1.X1 = Line1.X1 - 180
Line1.x2 = Line1.x2 - 180
Case vbKeyRight
Line1.X1 = Line1.X1 + 180
Line1.x2 = Line1.x2 + 180
End Select

End Sub

Private Sub Timer1_Timer()

If Shape1.Left <= 0 And Label1 = "NW" Then
Label1 = "NE"
End If
If Shape1.Left <= 0 And Label1 = "SW" Then
Label1 = "SE"
End If
If Shape1.Left >= 4800 And Label1 = "NE" Then
Label1 = "NW"
End If
If Shape1.Left >= 4800 And Label1 = "SE" Then
Label1 = "SW"
End If
If Shape1.Top >= 3480 And Label1 = "SW" Then
Label1 = "NW"
End If
If Shape1.Top >= 3480 And Label1 = "SE" Then
Label1 = "NE"
End If
If Shape1.Top <= 0 And Label1 = "NE" Then
Label1 = "SE"
End If
If Shape1.Top <= 0 And Label1 = "NW" Then
Label1 = "SW"
End If

' If Shape1.Top = 3480 And Shape1.Left <= Line1.X1 - 120 Or Shape1.Top = 3480 And Shape1.Left >= Line1.x2 Then
' MsgBox ("DEAD")
' Timer1.Enabled = False
' End If

COLLISIONDETECTION

Select Case Label1
Case "NE"
Shape1.Top = Shape1.Top - 120
Shape1.Left = Shape1.Left + 120
Case "NW"
Shape1.Top = Shape1.Top - 120
Shape1.Left = Shape1.Left - 120
Case "SE"
Shape1.Top = Shape1.Top + 120
Shape1.Left = Shape1.Left + 120
Case "SW"
Shape1.Top = Shape1.Top + 120
Shape1.Left = Shape1.Left - 120
End Select

End Sub

Public Sub COLLISIONDETECTION()

Dim XBat As Integer
Dim YBat As Integer
Dim XBlock As Integer
Dim YBlock As Integer
Dim Xsize As Integer
Dim Ysize As Integer
Dim i As Integer

XBat = Shape1.Left / 120
YBat = Shape1.Top / 120

For i = 1 To 50
XBlock = Shape2(i).Left / 120
YBlock = Shape2(i).Top / 120
Xsize = XBlock + Shape2(i).Width / 120
Ysize = YBlock + Shape2(i).Height / 120

If Shape2(i).Visible = True Then
If YBat = Ysize And XBat >= XBlock And XBat <= Xsize Then flipdown i
If YBat = YBlock And XBat >= XBlock And XBat <= Xsize Then flipUp i
If XBat = XBlock And YBat >= YBlock And YBat <= Ysize Then flipleft i
If XBat = Xsize And YBat >= YBlock And YBat <= Ysize Then flipright i
End If

Next i
End Sub

Sub flipdown(i As Integer)

If Label1 = "NW" Then
Label1 = "SW"
Else
Label1 = "SE"
End If
Shape2(i).Visible = False

End Sub

Sub flipUp(i As Integer)

If Label1 = "SW" Then
Label1 = "NW"
Else
Label1 = "NE"
End If
Shape2(i).Visible = False

End Sub
Sub flipleft(i As Integer)

If Label1 = "NE" Then
Label1 = "NW"
Else
Label1 = "SW"
End If
Shape2(i).Visible = False

End Sub
Sub flipright(i As Integer)

If Label1 = "NW" Then
Label1 = "NE"
Else
Label1 = "SE"
End If
Shape2(i).Visible = False

End Sub


You should use Option Explicit at the start of your program.... But that will lead to more errors for now.....

Anyway, it works with this code so delete the code from your form and copy this into it instead.

trevland06
03-20-2002, 09:12 AM
i was messing around playing it.. error or not.

i took out part of the code and it would make a great hard mode!
the ball went up a few pixels then bounces down fast. it doesnt touch the rectangles at all! but. when it comes down it removes a rectangle. its pretty fun. also. i like the game. great idea! i always thought this game was called pong.. the game you made is what i was going to make but then i found out what pong was and made that. also. may i make a suggestion now that your Collision detection is fixed. Levels! :D :D :D... for my Game when i make it.. Im going to Make it just Tiled.. On the Rosebud RPG that was posted here. i saw the notepad with numbers.. were they tiles? if they were tiles that would be a great way to make a Break thru game. then all you gotta do is open notpad and type a number for the tile. thats what i suggest. Cya

And Again --- Great Job :D..

PS: www.cnet.com look for DXBall (i cant find the link anymore)
It has is really cool. You may get ideas off it. i did. It is Breakthru with like Items coming from the balls with special effects.. What i am doing is hopfully adding some to my pong game. Also. Your game is addicting.. Mind if i try to add a High Score Chart so i can compete with myself? (50$ says i lose. lol)

Cya

scytheuk
03-21-2002, 02:18 AM
Thanx for the code Lord Pookie.

I played a bit at home yesterday and produced a similar example only with if statements everywhere. also added a feww restraints on the paddle movement and an extra angle of bounce.

As for modification of the code, help yourself trevland06, unless Lord Pookie has any comments to make about, it the code available is mostly his now anyway.
:D

I'll try and post my code later today so that you can see my primative solution to that of Lord Pookie's.

Scytheuk

Pookie
03-21-2002, 03:53 AM
Heh, the code I wrote for you is very badly written too, but as it was a rush job before as I was busy, I didn't format it much.

Actually you could do away with half of that code by streamlining it.

The NW SE NW SW can all be put into 2 Variables for example...


' NE
XD=120
YD=-120

To make the ball bounce up or down off an object

Yd=-Yd

To make the ball bounce left or right off an object

Xd=-Xd

scytheuk
03-21-2002, 05:56 AM
As promised the code i used to create bounce affects etc, etc using if statements (and lots of em).
:rolleyes:
I still think Lord Pookies makes for better reading, but im proud of what ive done and it shows a different (if not far longer), appoach to the solution.

Anyway thanx for the helping hand.
scytheuk

Pookie
03-21-2002, 06:58 AM
It's good to see you can work out how to do it in the end without help. :)

You know you should always use Option Explicit at the top of every form, it's good practice to do this as it raises an error whenever it finds a variable which hasn't been dimmed.

You may find it annoying to have to do this, but when you start writing big games with hundreds and hundreds of lines of code, debugging the program will come so much easier.

Also the program will run faster as the variables have been dimmed and ain't being used as variants (slowest and most memory hungery type variables).

Also, you souldn't use labels as a variable strings. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum