Pong Help
Author |
Message |
SIXAXIS
|
Posted: Fri Feb 01, 2008 9:23 pm Post subject: Pong Help |
|
|
Hi guys,
I am working on a pong game and so far, so good, but there is one problem. The ball always bounces around and never counts as out. So basically I have to figure out how to program the scoring system and where the ball can't pass (where the players are).
P.S. Sorry if it's messy, I'm just starting to program. Clean it up if you want.
Turing: |
setscreen ("graphics:800;600,nobuttonbar,nocursor,noecho")
View.Set ("title:Pong Beta (Work in Progress)")
var chars : array char of boolean
var arial18, arial12 : int
arial18 := Font.New ("Arial:18:Italic")
arial12 := Font.New ("Arial:12:Italic")
var y1, y2 : int
y1 := maxy div 2 - 40
y2 := maxy div 2 - 40
Font.Draw ("Welcome to Turing Pong!", maxx div 2 - 160, maxy - 40, arial18, black)
Font.Draw ("This game is two player only. Player one uses the keys 'w' and 's' and player two uses arrow", 0, maxy - 100, arial12, black)
Font.Draw ("up and arrow down.", 0, maxy - 120, arial12, black)
Font.Draw ("Press any key to continue...", 0, maxy - 150, arial12, black)
Input.Pause
setscreen ("graphics:800;600,offscreenonly,nobuttonbar")
process player1
loop
Input.KeyDown (chars )
if chars ('w') then
y1 := y1 + 7
end if
if chars ('s') then
y1 := y1 - 7
end if
if chars (KEY_ESC) then
exit
end if
if chars ('q') then
exit
end if
Input.KeyDown (chars )
if chars (KEY_UP_ARROW) then
y2 := y2 + 7
end if
if chars (KEY_DOWN_ARROW) then
y2 := y2 - 7
end if
if chars (KEY_ESC) then
exit
end if
if chars ('q') then
exit
end if
cls
drawfillbox (maxx - 3, y2, maxx - 22, y2 + 100, black)
drawfillbox (3, y1, 22, y1 + 100, black)
View.UpdateArea (maxx - 3, y2, maxx - 22, y2 + 100)
View.UpdateArea (3, y1, 22, y1 + 100)
delay (15)
View.Update
end loop
end player1
process ball
var x, y, z, a : int
randint (x, 100, maxx - 100)
randint (y, 100, maxy - 100)
z := 10
a := 10
loop
drawfilloval (x, y, 5, 5, black)
x := x + z
y := y + a
if x > maxx - 25 then
z := z * - 1
end if
if y > maxy - 10 then
a := a * - 1
end if
if x < 25 then
z := z * - 1
end if
if y < 10 then
a := a * - 1
end if
delay (30)
View.UpdateArea (x - 3, y - 3, x + 3, y + 3)
end loop
end ball
fork player1
fork ball
View.Update
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
syntax_error
|
Posted: Fri Feb 01, 2008 9:25 pm Post subject: Re: Pong Help |
|
|
hmmm... if the ball goes out of the screeen what is it hitting the maxx and maxy right so just have a if condition if
ball is equal to maxx and maxy {blah...}
right?
think it through
EDIT: TRY VERY HARD NOT TO USE FORK IF YOU MUST USE IT FOR MUSIC BUT THAT IS ABOUT IT[/i] |
|
|
|
|
|
SIXAXIS
|
Posted: Fri Feb 01, 2008 9:34 pm Post subject: Re: Pong Help |
|
|
syntax_error @ Fri Feb 01, 2008 9:25 pm wrote: hmmm... if the ball goes out of the screeen what is it hitting the maxx and maxy right so just have a if condition if
ball is equal to maxx and maxy {blah...}
right?
think it through
EDIT: TRY VERY HARD NOT TO USE FORK IF YOU MUST USE IT FOR MUSIC BUT THAT IS ABOUT IT[/i]
Oh yeah! Thanks, I wasn't thinking straight.
EDIT: I just realised it wouldn't work though. Can you help me put them together or do it some other way that both processes would be together? Then I can relate and compare the different variables.
I don't really know how to do more than one thing at once without different processes and forks. It seems to work good enough until I'm finished and I get the kinks out of it. |
|
|
|
|
|
syntax_error
|
Posted: Fri Feb 01, 2008 9:41 pm Post subject: Re: Pong Help |
|
|
SIXAXIS wrote:
syntax_error @ Fri Feb 01, 2008 9:25 pm wrote: hmmm... if the ball goes out of the screeen what is it hitting the maxx and maxy right so just have a if condition if
ball is equal to maxx and maxy {blah...}
right?
think it through
EDIT: TRY VERY HARD NOT TO USE FORK IF YOU MUST USE IT FOR MUSIC BUT THAT IS ABOUT IT[/i]
Oh yeah! Thanks, I wasn't thinking straight.
I don't really know how to do more than one thing at once without different processes and forks. It seems to work good enough until I'm finished and I get the kinks out of it.
well to give yo uan idea how to keep calling the proc let me give you a basic view of basicly any game you can make in turing
code: |
proc bhal
proc foo
proc bar
/* the list goes on ;
where main program starts */
loop
bhal
bar foo
if char = 'q' then exit
end loop
| [/quote] |
|
|
|
|
|
ericfourfour
|
Posted: Fri Feb 01, 2008 10:07 pm Post subject: Re: Pong Help |
|
|
syntax_error @ Fri Feb 01, 2008 9:25 pm wrote: TRY VERY HARD NOT TO USE FORK IF YOU MUST USE IT FOR MUSIC BUT THAT IS ABOUT IT
The addition of PlayFileReturn, PlayFileLoop and PlayFileStop to the Music module, has eliminated the need for processes to play music. The only case in Turing where processes are required, is when the program needs to wait for a connection. Processes are used to split your program into different threads so multiple processors can do calculations simultaneously. In Turing, the average user will never need this optimization. Chances are, if you are using processes, there is an easier and more robust way of doing things. |
|
|
|
|
|
syntax_error
|
Posted: Fri Feb 01, 2008 10:15 pm Post subject: Re: Pong Help |
|
|
thank you ericfourfour i wasnt aware of such functions in turing guess i should look into the new
modification to turing been years since i did it tho
still so now i dont think there are any reasons why SIXAXIS should use fork(s) |
|
|
|
|
|
SIXAXIS
|
Posted: Fri Feb 01, 2008 10:25 pm Post subject: Re: Pong Help |
|
|
This is what I have so far. It's functional, but a bit glitchy. Can you guys give me some pointers for cleaning it up and making it less glitchy?
Turing: |
setscreen ("graphics:800;600,nobuttonbar,nocursor,noecho")
View.Set ("title:Pong Beta (Work in Progress)")
var chars : array char of boolean
var x, y, z, a : int
var arial18, arial12 : int
arial18 := Font.New ("Arial:18:Italic")
arial12 := Font.New ("Arial:12:Italic")
var y1, y2 : int
y1 := maxy div 2 - 40
y2 := maxy div 2 - 40
Font.Draw ("Welcome to Turing Pong!", maxx div 2 - 160, maxy - 40, arial18, black)
Font.Draw ("This game is two player only. Player one uses the keys 'w' and 's' and player two uses arrow", 0, maxy - 100, arial12, black)
Font.Draw ("up and arrow down.", 0, maxy - 120, arial12, black)
Font.Draw ("Press any key to continue...", 0, maxy - 150, arial12, black)
Input.Pause
setscreen ("graphics:800;600,offscreenonly,nobuttonbar")
process player1
loop
Input.KeyDown (chars )
if chars ('w') then
y1 := y1 + 7
end if
if chars ('s') then
y1 := y1 - 7
end if
if chars (KEY_ESC) then
exit
end if
if chars ('q') then
exit
end if
Input.KeyDown (chars )
if chars (KEY_UP_ARROW) then
y2 := y2 + 7
end if
if chars (KEY_DOWN_ARROW) then
y2 := y2 - 7
end if
if chars (KEY_ESC) then
exit
end if
if chars ('q') then
exit
end if
cls
drawfillbox (maxx - 3, y2, maxx - 22, y2 + 100, black)
drawfillbox (3, y1, 22, y1 + 100, black)
View.UpdateArea (maxx - 3, y2, maxx - 22, y2 + 100)
View.UpdateArea (3, y1, 22, y1 + 100)
delay (15)
View.Update
if x < 0 then
exit
end if
if x > maxx then
exit
end if
if whatdotcolor (x, y + 5) = black then
a := a * 1
z := z * - 1
end if
if whatdotcolor (x, y - 5) = black then
a := a * 1
z := z * - 1
end if
if whatdotcolor (x + 5, y - 5) = black then
a := a * 1
z := z * - 1
end if
if whatdotcolor (x - 5, y + 5) = black then
a := a * 1
z := z * - 1
end if
end loop
end player1
process ball
randint (x, 100, maxx - 100)
randint (y, 100, maxy - 100)
randint (z, 4, 6)
randint (a, 4, 6)
loop
drawfilloval (x, y, 5, 5, blue)
x := x + z
y := y + a
if x > maxx then
exit
end if
if y > maxy - 5 then
a := a * - 1
end if
if x < 0 then
exit
end if
if y < 5 then
a := a * - 1
end if
delay (30)
View.UpdateArea (x - 3, y - 3, x + 3, y + 3)
end loop
end ball
fork player1
fork ball
View.Update
|
|
|
|
|
|
|
ericfourfour
|
Posted: Fri Feb 01, 2008 10:53 pm Post subject: Re: Pong Help |
|
|
First of all, you should get a scrap piece of paper. Write down all of the variables the players will have. Write down all of the variables the ball will use. Write down all of the controls, how they are triggered and what they do. Then design a single loop that does the following:
Get User Input
Do Calculations
Clear Screen
Draw Everything
View.Update
Time Delay
Then you can reprogram this pong game without processes. You should only have one main loop. This is the most important thing you can do right now. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
SIXAXIS
|
Posted: Sat Feb 02, 2008 9:20 am Post subject: Re: Pong Help |
|
|
I'll do that.
EDIT: Done. The scoring system is in. If you press q or escape, the program finishes. No glitches anymore. The program is clean. Thanks for all your help guys. |
|
|
|
|
|
|
|