help plz Pong
Author |
Message |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Mon Jan 16, 2006 4:33 pm Post subject: help plz Pong |
|
|
how can i improve on this game, and how would i be able to get it so that u can have a beatable comp? plz help |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
pavol
|
Posted: Mon Jan 16, 2006 5:48 pm Post subject: (No subject) |
|
|
you could make the game go faster (smaller delay and/or smaller screen). and for the beatable comp, everytime that you hit the ball (right now the comp's center of the paddle is attached to the ball) randomize where the ball will be attached. so if you randomize 0 the comp will hit the ball with the center of the paddle, if you randomize something like 25 the comp will hit it with the edge of the paddle, and 30 the comp would miss the ball.
hope it helps |
|
|
|
|
![](images/spacer.gif) |
theuberk
|
Posted: Mon Jan 16, 2006 7:13 pm Post subject: (No subject) |
|
|
Yes, you could randomize it, like pavol pointed out. You could also slow down how fast the paddle moves. For example:
ypos = the y position of the paddle
code: |
var ypos, ballpos : int
loop
delay(25) %or however slow you want the paddle to move
if ballpos > ypos then
ypos := ypos + 1
elsif ballpos < ypos then
ypos := ypos - 1
end if
end loop
|
So instead of the comp being "locked" to the ball's position, the comp will check to see if the ball is above or below it, and then move to it accordingly. The computer will either be fast of slow depending on the delay (higer delay = slower computer). |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Tue Jan 17, 2006 10:55 pm Post subject: (No subject) |
|
|
pavol wrote: you could make the game go faster (smaller delay and/or smaller screen). and for the beatable comp, everytime that you hit the ball (right now the comp's center of the paddle is attached to the ball) randomize where the ball will be attached. so if you randomize 0 the comp will hit the ball with the center of the paddle, if you randomize something like 25 the comp will hit it with the edge of the paddle, and 30 the comp would miss the ball.
hope it helps
what kink of code would i use to prog that cuz i cant figure out how to have the paddle the same size and not hit it on the center |
|
|
|
|
![](images/spacer.gif) |
pavol
|
Posted: Wed Jan 18, 2006 11:16 am Post subject: (No subject) |
|
|
well, right now you're probably using either the same variable for ball x/y and paddle x/y (im not sure i don't have your code here), so instead of making the paddle x = the ball x you could do something like:
code: | var paddleX, ballX, paddleRnd : int
randint (paddleRnd, 1,100)
paddleX := paddleRnd * (paddleRnd div 100)
| i don't think this is exactly right im just using it as an example. this is what i meant, "randomize where the ball will be attached". or you could always not randomize and just say
code: | paddleX := ballX +/- ? |
i know it's vague but i hope that clears it up a bit ![Very Happy Very Happy](http://compsci.ca/v3/images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Tue Jan 24, 2006 2:17 am Post subject: (No subject) |
|
|
thanks for the help it helped a lot i understand what you meant now |
|
|
|
|
![](images/spacer.gif) |
Drakain Zeil
|
Posted: Tue Jan 24, 2006 12:16 pm Post subject: (No subject) |
|
|
I suggest against the use of a delay in a game...
Instead, build it in a loop with timers... for example:
Time2:=now
Time1:=now
loop
if Time1-Time2 > X then
Time1:=now
doWhatever
end if
time 2:=now
end loop
Or something along those lines anyway. It lets your program keep running, and will only run that block of code when it's needed, instead of pausing the entire program to make something move slowly.
Also, you could try:
if Input.hasch then
doWhatever
end if |
|
|
|
|
![](images/spacer.gif) |
|
|