Killerguppy101
Mar 11th, 2002, 02:11 PM
Yeah, um, ima newbie, so try not to get too pissed off at me.
I gotta game, and the collision system doesn't quite work, so i was wondering if there was anyone with some free time who could help me out.
Killerguppy101
Mar 13th, 2002, 11:41 AM
Why does no one want to help?
Is it because im a newbie?
Or because they're afraid of getting a virus from my file?
If thats the problem, I'll put the code right on the board.
Killerguppy101
Mar 13th, 2002, 11:46 AM
I think this is all you will need. The walls are types that have top, left, height, width, and visible properties. Rects have top,left, bottom, and right.
Private Sub Intersection()
Dim rDest As RECT
Dim i As Integer
'set the ball rectangle to shpBall's size
With rBall
.Bottom = shpBall.Top + shpBall.Height
.Left = shpBall.Left
.Right = shpBall.Left + shpBall.Width
.Top = shpBall.Top
End With
'check all walls to see if they are intersecing w/ ball
For i = 0 To 84
If IntersectRect(rDest, rWall(i), rBall) <> 0 Then
'if they intersect and are visible...
If Wall(i).Visible = True Then
'reverse ball direction,make wall invisible
BallDir = -BallDir
Wall(i).Visible = False
'Redo all the walls
Repaint
'if they intersect ans are invisible...
ElseIf Wall(i).Visible = False Then
'don't worry about it
BallDir = BallDir
End If
End If
Next i
End Sub
Private Sub LoadLevel()
Dim FileHandle%
Dim strXBuffer As String
Dim strYBuffer As String
Dim strTypeBuffer As String
Dim LineNum As Integer
Dim i As Integer
'get next fre file handle
FileHandle% = FreeFile
'open level for inputing
Open App.Path + "\levels\Level" & Level & ".lvl" For Input As #FileHandle%
'while not at end of file...
Do While Not EOF(FileHandle%)
'input the x,y,and type of wall
Line Input #FileHandle%, strXBuffer
Line Input #FileHandle%, strYBuffer
Line Input #FileHandle%, strTypeBuffer
'increment the number line/wall we are on
LineNum = LineNum + 1
'set props of current wall
Wall(LineNum).Left = ((strXBuffer * picCurrWall.Width) / 15) - (lblStatus.Width / 30)
Wall(LineNum).Top = ((strYBuffer * picCurrWall.Height) / 15) - (picCurrWall.Height / 15) '16
Wall(LineNum).Type = strTypeBuffer
Wall(LineNum).Visible = True
Wall(LineNum).Height = picCurrWall.Height
Wall(LineNum).Width = picCurrWall.Width
'set currwall's rectangel (see Intersection())
rWall(LineNum).Bottom = (Wall(LineNum).Top + Wall(LineNum).Height) * 15
rWall(LineNum).Left = (Wall(LineNum).Left) * 15
rWall(LineNum).Right = (Wall(LineNum).Left + Wall(LineNum).Width) * 15
rWall(LineNum).Top = (Wall(LineNum).Top) * 15
Loop
'close level file
Close #1
'refresh the scene
Refresh
'loop through all walls
For i = 0 To 84
'if the wall is visible...
If Wall(i).Visible = True Then
'get what type of wall it is...
Select Case (Wall(i).Type)
'and put it on the screen
Case "BlankWall"
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picBlankWall.hDC, 0, 0, vbSrcCopy
Case "SpikeWall"
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picSpikeWall.hDC, 0, 0, vbSrcCopy
Case "Wall01"
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picWall01.hDC, 0, 0, vbSrcCopy
Case "Wall02"
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picWall02.hDC, 0, 0, vbSrcCopy
Case "wall03"
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picWall03.hDC, 0, 0, vbSrcCopy
Case "Wall04"
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picWall04.hDC, 0, 0, vbSrcCopy
Case "ChWall01"
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picChWall01.hDC, 0, 0, vbSrcCopy
Case "ChWall02"
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picChWall02.hDC, 0, 0, vbSrcCopy
Case "Chwall03"
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picChWall03.hDC, 0, 0, vbSrcCopy
Case "ChWall04"
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picChWall04.hDC, 0, 0, vbSrcCopy
Case "FullWall"
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picFullWall.hDC, 0, 0, vbSrcCopy
Case Else
BitBlt frmMain.hDC, Wall(i).Left, Wall(i).Top, Wall(i).Width, Wall(i).Height, frmPics.picBlankWall.hDC, 0, 0, vbSrcCopy
End Select
End If
Next i
End Sub
Nirces
Mar 13th, 2002, 02:03 PM
Looked at your code, seems to be alright, not sure about intersectRect, never used it so not sure what rDest is used for (best guess would be the rect of the overlapping section)
(not downloaded)
One problem with this method is that the ball's speed must not be faster than the size of the wall section.
for example
if a ball is two by two pixels.
and a wall is 3 by 3 pixels
if the ball is 1 pixel under the wall and is moving at a speed of 6 pixels per frame then the ball will pass through the wall and out on the otherside without causing a collision.
there are other more complex methods that can be used to beat this problem (like line-intersection, determining which wall the ball WILL hit, then checking to see if it has happened yet)
Killerguppy101
Mar 13th, 2002, 05:11 PM
Thnx for your help, but it didn't help. I went back and checked over all that and it seems to be ok. The ball increased 100 or -100 (depending on its curr direction) The ball height was 255 and the wall height was 600. rWall height was 9000 and rball height was 225. Don't know what units they are (pixels, twips, etc) Its just what the compiler said when I pressed F8 to step through my code and hovered my mouse over the variables to get their current value.
Nirces
Mar 13th, 2002, 07:20 PM
Ok been looking at the code for a couple of hours now (anything to put off wirtting that dang report :P)
I knew what was wrong a while ago, but your code is bad and every fix i made stopped the entire thing working.
your problem is scale
you are using pixels for some values and twips for others.
Switch everything to using pixels (no *15 /15), when refering to the forms use scale height/width
all controls will use the scale of the form.
Killerguppy101
Mar 15th, 2002, 07:32 PM
Thnx, I made a few adjustments to scales and such and now my code works great. Check back in a few days and i'll post the final (or near final) version of my crappy first game.
Arbiter
Mar 16th, 2002, 04:43 AM
I just popped in to see if I could help and Nirces has beat me to it.
Couple of hours looking at someone elses code? You must really not want to do that report... :p
Killerguppy,
Be sure to let us know when you post a playable version of your game. :)
Killerguppy101
Mar 16th, 2002, 01:35 PM
Its finally here!!!
The first playable version!!!
press the space bar to pause
use the arrow keys to move back and forth.
the block in the lower right is the only type you can kill.
hit blocks that are half white and half another color to change block types to kill.
the blocks with blue crosses are deadly!
p.s.- Its still under construction, but i think you can get the general idea of what its gonna look like.
Killerguppy101
Mar 16th, 2002, 03:06 PM
stoopid board doesn't want to post my game, eh?
lets try it now!