Pong game for school
Author |
Message |
a1229
|
Posted: Mon Jun 16, 2008 7:57 pm Post subject: Pong game for school |
|
|
I really need help for this, for some reason I can get the paddles to move but the ball isn't showing up, can someone tell me what I'm doing wrong?
Description: |
|
 Download |
Filename: |
pong1.t |
Filesize: |
3.24 KB |
Downloaded: |
119 Time(s) |
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
gitoxa

|
Posted: Mon Jun 16, 2008 8:50 pm Post subject: RE:Pong game for school |
|
|
I'm going to recommend not using processes, instead just run a procedure in the main loop.
But anyway, your problem is that you are not forking your Ball process
Also note that View.Update only works if you set the screen to offscreenonly
|
|
|
|
|
 |
a1229
|
Posted: Mon Jun 16, 2008 9:12 pm Post subject: Re: Pong game for school |
|
|
Can someone edit/fix my program? I tried changing my Ball process to a procedure but it's still not working.
|
|
|
|
|
 |
gitoxa

|
Posted: Mon Jun 16, 2008 9:27 pm Post subject: RE:Pong game for school |
|
|
No, you can. Just know that by changing it to a procedure, and calling it in your main loop, every time the program goes through the loop, it runs it once. Note that your Ball process/procedure is looped, with no exit. What does that mean?
|
|
|
|
|
 |
a1229
|
Posted: Mon Jun 16, 2008 9:42 pm Post subject: Re: Pong game for school |
|
|
Ok, I've gotten the ball to be part of the loop and I forked it, but I still can't see it on my screen.
|
|
|
|
|
 |
Tony

|
Posted: Mon Jun 16, 2008 11:44 pm Post subject: Re: Pong game for school |
|
|
a1229 @ Mon Jun 16, 2008 9:42 pm wrote: I've gotten the ball to be part of the loop and I forked it
Please tell me that you are not creating a new fork during each frame of the loop.
Seriously, if you don't know how processes work -- do not use them. This is actually one of the few parts of Turing that have the potential tohorribly mess up your program.
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
a1229
|
Posted: Tue Jun 17, 2008 9:50 am Post subject: Re: Pong game for school |
|
|
My mom's going to kill me if I don't get this fixed! The ball loop is now a procedure, and I corrected a few of the parameters, but it's still not showing up (its supposed to be white)
|
|
|
|
|
 |
Insectoid

|
Posted: Tue Jun 17, 2008 10:23 am Post subject: RE:Pong game for school |
|
|
How many loops do you have in your program?
A game like pong usually has 1 main loop (except for the menu) in which all movement is done (ball, paddles, score, etc.). Why not post your revised code so we can find out the problem and help you on the road to learning what you did wrong.
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
a1229
|
Posted: Tue Jun 17, 2008 3:07 pm Post subject: Re: Pong game for school |
|
|
var x : int
var y : int
var dx := 1
var dy := 1
var p1 : string
var p2 : string
var choice : int
var chars : array char of boolean
var c : int := 1
var dir := 100
var dir2 := 180
var dir3 := 100
var dir4 := 180
var background := black
var stickspeed := 2
var ballspeed := 3
var name : string
var getKey : array char of boolean
procedure Screen
drawfillbox (0, 0, maxx, maxy, background)
drawbox (0, 0, maxx, maxy, white)
drawfillbox (20, dir2, 30, dir, white)
drawbox (20, dir2, 30, dir, black)
drawfillbox (maxx - 20, dir4, maxx - 30, dir3, white)
drawbox (maxx - 20, dir4, maxx - 30, dir3, white)
end Screen
Screen
procedure UpPlayer1
drawfillbox (20, dir2, 30, dir, background)
dir += 1
dir2 += 1
drawfillbox (20, dir2, 30, dir, white)
drawbox (20, dir2, 30, dir, white)
delay (stickspeed)
end UpPlayer1
procedure DownPlayer1
drawfillbox (20, dir2, 30, dir, background)
dir -= 1
dir2 -= 1
drawfillbox (20, dir2, 30, dir, white)
drawbox (20, dir2, 30, dir, white)
delay (stickspeed)
end DownPlayer1
procedure UpPlayer2
drawfillbox (maxx - 20, dir4, maxx - 30, dir3, background)
dir3 += 1
dir4 += 1
drawfillbox (maxx - 20, dir4, maxx - 30, dir3, white)
drawbox (maxx - 20, dir4, maxx - 30, dir3, black)
delay (stickspeed)
end UpPlayer2
procedure DownPlayer2
drawfillbox (maxx - 20, dir4, maxx - 30, dir3, background)
dir3 -= 1
dir4 -= 1
drawfillbox (maxx - 20, dir4, maxx - 30, dir3, white)
drawbox (maxx - 20, dir4, maxx - 30, dir3, black)
delay (stickspeed)
end DownPlayer2
process Ball
locate (1, 1)
colorback (black)
locate (1, 43)
x += dx
y += dy
delay (ballspeed)
drawfilloval (x, y, 5, 5, white)
drawoval (x, y, 5, 5, white)
drawfillbox ((maxx div 2) - 10, 0, (maxx div 2), maxy, white)
drawbox ((maxx div 2) - 10, 0, (maxx div 2), maxy, white)
drawfilloval (x, y, 5, 5, background)
% Boundary
if (x = 40) and (y >= dir and y <= dir2) then
dx := -dx
elsif (x < 40) then
x := 550
y := 300
elsif (x >= maxx - 40) and (y >= dir3 and y <= dir4) then
dx := -dx
elsif (x > maxx - 40) then
x := 70
y := 300
elsif (y = 0) or (y = maxy - 20) then
dy := -dy
end if
end Ball
loop
Input.KeyDown (getKey)
if getKey ('w') then
UpPlayer1
end if
if getKey ('s') then
DownPlayer1
end if
if getKey (KEY_UP_ARROW) then
UpPlayer2
end if
if getKey (KEY_DOWN_ARROW) then
DownPlayer2
end if
% 1P Boundaries
if (dir <= 0) and (dir2 <= 80) then
dir := 0
dir2 := 80
elsif (dir >= maxy - 80) and (dir2 >= maxy - 80) then
dir2 := maxy
dir := maxy - 80
end if
% 2P Boundaries
if (dir3 <= 0) and (dir4 <= 80) then
dir3 := 0
dir4 := 80
elsif (dir3 >= maxy - 80) and (dir4 >= maxy - 80) then
dir3 := maxy - 80
dir4 := maxy
end if
end loop
fork Ball
% drawfillbox (0, 0, maxx, maxy, black)
% color (white)
% colorback (black)
% locate (10, 25)
% put "Welcome to Ping Pong!"
% locate (20, 25)
% put "Enter Your Name: " ..
% get name
% name := "Player 1"
% Screen
|
|
|
|
|
 |
Zampano

|
Posted: Tue Jun 17, 2008 3:28 pm Post subject: Re: Pong game for school |
|
|
You are forking the ball procedure in the wrong place (after the main loop), but to be honest, by forking it in what would seem to be the right place, I haven't achieved any measure of functionality. The program is a bit of a mess of variables, which makes it almost impossible to find the problem.
|
|
|
|
|
 |
|
|