|
-
Jan 5th, 2002, 03:01 PM
#1
Pong game.. make the ball go faster..
Hi everyone,
I'm wondering if there's a way to make the ball in a pong game go faster with time (i.e. accelerate).. Right now in my program the movement of the ball is in accordance with a timer, but I don't think I can make it go any faster using a timer.. Any suggestions?
Thank you 
Linette
-
Jan 5th, 2002, 03:14 PM
#2
Good Ol' Platypus
Say you add + XSpeed (the speed of the X direction) and + YSpeed (the speed of the Y direction) in each Timer interval. If you want it to accelerate, just add (for example) + XSpeed * 1.2 and + YSpeed * 1.2.
This will make the ball accelerate by 1.2 times the YSpeed. It wouldn't get any faster than this.
But you can go this way:
XSpeed = XSpeed * 1.2
YSpeed ... etc.
And it will add 1.2 times XSpeed to Xspeed every time your timer goes - the ball will keep getting faster.
Now if you want, say, for the ball to get faster every time you block, just add that code when the ball hits your board.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jan 5th, 2002, 03:15 PM
#3
Lively Member
Hi,
Instead of putting things into a timer, you could place the code into a game loop. After you load things up you'd want to enter the game loop
Code:
sub GameLoop()
dim RUNNING as boolean
RUNNING = true ' when it equals false, the game is over
do
RUNNING = Input() ' get user input, I have it so if they press escape the game quits
Blt() ' draw stuff onto the screen
Wait(TimeBetween frames) ' here you can determine how much time you want the system to wait, its somewhat like a timer
while(RUNNING)
Cleanup() ' cleanup phase if you use DirectDraw
' then you can quit the game now or play again
end sub
Private Declare Function GetTickCount& Lib "kernel32" ()
function Wait(int Time)
dim tb as long, tn as long
tb=GetTickCount()
do
tn = GetTickCount()
while(abs(tn-tb)<Time)
end function
thats what you pretty much follow for a game loop, you just keep doing things over and over until its done, and forgive me if some of the syntax is wrong, I cut it out from C++ and tried to convert most of it, not sure if I did the loops right.
Hope that helps
-
Jan 5th, 2002, 04:22 PM
#4
I think I'll try that, thank you
-
Jan 8th, 2002, 11:47 AM
#5
The problem is that under Win9x the timer control has a maximal resolution of 15 ticks/second. The GetTickCount method on the other hand is accurate to the millisecond. But I would modify the loop a little bit:
VB Code:
Private Declare Function GetTickCount Lib "kernel32" () as Long
'I find this syntax more readable, I also like hungarian notation
Const lTicksPerFrame = 30 'A good value to work with
Sub GameLoop()
Dim bRun as Boolean
Dim lTicks as Long
bRun = True ' when it equals false, the game is over
do
lTicks = GetTickCount
bRun = Input() ' get user input, I have it so if they press escape the game quits
Blt() ' draw stuff onto the screen
Repeat While (lTicks + lTicksPerFrame > GetTickCount)
End Repeat
While(bRun)
Cleanup() ' cleanup phase if you use DirectDraw
' then you can quit the game now or play again
end sub
This takes into account that the loop itself needs time too. I too can't guarantee that this works since I've never done Vb.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
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
|