|
-
May 24th, 2001, 03:45 PM
#1
Thread Starter
Lively Member
What's wrong with this code?
Hi all of you!
I'm doing a small game using DDraw, it's called CrossBall.
A ball is moving along the horizontal part of a cross. The user has to try and stop it in the middle of the cross. If he succeeds in doing so, another ball will start moving on the vertical part, so he has to stop aver the first one.
The problem is, that when the first ball stops in the middle, the second one appears on the vertical part but doesn't move.
This is the code in general:
Code:
'First, the BallType
BallType
XPosition 'Sets the X-coordinate
Yposition 'Sets the Y-coordinate
Xspeed 'A constant added to the X-coordinate simulating the ball's speed in the x direction
yspeed 'A constant added to the Y-coordinate simulating the ball's speed in the y direction
End Type
CrossBall function()
setHorizontalBall
Do
DoEvents
MoveHorizontalBall
If vbKeySpace Then
'if Ball is in the middle
ball.Xspeed = 0
SetVerticalBall
Do
DoEvents
MoveVerticalBall
if vbKeySpace
'if bal is over the other one
ball.yspeed = 0
Exit Do
End If
Loop
End If
Loop
End Function
SetVertical and SetHorizontal are sub's that set the balls in theie places and sets their speeds.
MoveHorizontal: ball.Xposition=Ball.Xposition+Ball.Speed
MoveVertical: ball.yposition=ball.yposition+ball.speed
I think that's it.
Thank you all for your help.
Last edited by sandra; May 24th, 2001 at 04:08 PM.
-
May 29th, 2001, 09:45 AM
#2
New Member
I'm pretty new at this stuff, but it looks to me like it may be a problem with the first "if vbKeySpace". Perhaps that is not always true when you are expecting the vertical ball movement to occur. I think You need to do the vertical movement outside of that if statement.
Just my $.02 and overpriced at that.
-
May 29th, 2001, 09:56 AM
#3
PowerPoster
TMTOMH, that was pseudo-code ^_^
---
How do you realize that? Do you have a keys buffer? If so you'd need to clear that buffer after this line, because else Space would still be 'pressed' and the next check for Space would return true.. see?
-
May 29th, 2001, 10:28 AM
#4
Thread Starter
Lively Member
No Fox actually I have a "buffer" for keys pressed. It's an array holding all the keys.
What hapens is:
Code:
sub form_keydown(anykey) (or something like that)
key(anykey)=true
end sub
sub form_keyup(anykey)
key(anykey)=false
end sub
-
May 29th, 2001, 11:47 AM
#5
PowerPoster
Read my posts carefully I said "Do you have a keys buffer? If so you'd need to clear that buffer after this line.."
So after checking if space is true do:
Code:
Key( vbKeySpace ) = False
-
May 29th, 2001, 12:05 PM
#6
Thread Starter
Lively Member
Ok! I'm sorry. Now I got what you mean.
Ok, I'll try it
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
|