I need help with pong
Author |
Message |
uknowhoiam
|
Posted: Fri Mar 13, 2009 4:39 pm Post subject: I need help with pong |
|
|
I have alot of questions about this program but the main one is that how to make my ball bounce back when it hits the bar, i've tried everything but nothing works and my flickering will NOT STOP omg my head hurts... its been 2 weeks since i've been trying to fix it
here's my code, can some one plz help me
Turing: | View.Set ("graphics:650,400;offscreenonly")
Mouse.ButtonChoose ("multibutton")
var xpos, ypos, ypos1, ypos2, ypos3, ypos4 : int := 1
var x : int := maxx div 2
var y : int := maxy div 2
var y1 : int := maxy div 2 - 35
var y2 : int := maxy div 2 + 35
var y3 : int := maxy div 2 - 35
var y4 : int := maxy div 2 + 35
var key : string (1)
var x5, y5, button : int
var xpos1 : int := 1
var xmov : int := maxx div 2
var x1mov : int := maxy div 2 - 35
var x2mov : int := maxy div 2 + 35
colourback (black)
cls
procedure leftbar
drawfillbox (0, y1, 5, y2, white)
View.Update
end leftbar
procedure rightbar
drawfillbox (maxx - 5, y3, maxx, y4, white)
View.Update
end rightbar
procedure keyboard
%player 1
drawfillbox (0, y1, 5, y2, white)
View.Update
delay (2)
cls
if ord (key ) = 203 then
y1 := y1 + 10
y2 := y2 + 10
x1mov := x1mov + 1
x2mov := x2mov + 1
elsif ord (key ) = 205 then
y1 := y1 - 10
y2 := y2 - 10
xpos1 := -xpos1
x1mov := x1mov - 1
x2mov := x2mov - 1
end if
end keyboard
procedure mouse
%player 2
drawfillbox (maxx - 5, y3, maxx, y4, white)
View.Update
delay (5)
cls
if button = 1 then
y3 := y3 - 5
y4 := y4 - 5
elsif button = 100 then
y3 := y3 + 5
y4 := y4 + 5
end if
end mouse
procedure ball
%ball
drawfilloval (x, y, 5, 5, white)
delay (5)
if y < maxy div 2 then
xmov := xmov - 1
elsif y > maxy div 2 then
xmov := xmov + 1
end if
if xmov >= x1mov or xmov <= x2mov then
xpos := +xpos
ypos := +ypos
end if
if x < 5 or x >= maxx - 5 then
xpos := -xpos
end if
if y < 5 or y >= maxy - 5 then
ypos := -ypos
end if
end ball
loop
ball
leftbar
rightbar
x := x + xpos
y := y + ypos
Mouse.Where (x5, y5, button )
if Mouse.ButtonMoved ("Down") then
mouse
end if
if hasch then
getch (key )
keyboard
end if
if x = 5 or x = maxx - 5 then
exit
end if
cls
end loop |
Mod Edit: Remember to use syntax tags! Thanks code: | [syntax="turing"]Code Here[/syntax] |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
corriep
|
|
|
|
|
uknowhoiam
|
Posted: Fri Mar 13, 2009 11:02 pm Post subject: RE:I need help with pong |
|
|
k i dont understand the syntax turing thing.. can you tell me how to use that and about the program what i did was
Turing: | if y >= y1 or y <= y2 and x = 5 then
xpos := -xpos % the ball will not move, if you make it +xpos then it will move but it has no effect
ypos := -ypos
elsif y >= y3 or y <= y4 and x = maxx - 5 then
xpos := -xpos
ypos := -ypos
end if |
Nothing happens here is what i have (im going to try the syntax)
Turing: | code here [View.Set ("graphics:650;400,offscreenonly")
Mouse.ButtonChoose ("multibutton")
var xpos, ypos, ypos1, ypos2, ypos3, ypos4 : int := 1
var x : int := maxx div 2
var y : int := maxy div 2
var y1 : int := maxy div 2 - 35
var y2 : int := maxy div 2 + 35
var y3 : int := maxy div 2 - 35
var y4 : int := maxy div 2 + 35
var key : array char of boolean
var x5, y5, button : int
colourback (black)
cls
procedure leftbar
drawfillbox (0, y1, 5, y2, white)
View.Update
end leftbar
procedure rightbar
drawfillbox (maxx - 5, y3, maxx, y4, white)
View.Update
end rightbar
procedure keyboard
%player 1
drawfillbox (0, y1, 5, y2, white)
View.Update
delay (2)
cls
if key (KEY_LEFT_ARROW) and y2 < maxy then
View.Update
y1 := y1 + 10
y2 := y2 + 10
elsif key (KEY_RIGHT_ARROW) and y1 > 0 then
View.Update
y1 := y1 - 10
y2 := y2 - 10
end if
end keyboard
procedure mouse
%player 2
drawfillbox (maxx - 5, y3, maxx, y4, white)
View.Update
delay (5)
cls
if button = 1 and y3 > 0 then
y3 := y3 - 5
y4 := y4 - 5
elsif button = 100 and y4 < maxy then
y3 := y3 + 5
y4 := y4 + 5
end if
end mouse
procedure ball
%ball
drawfilloval (x, y, 5, 5, white)
delay (5)
if y >= y1 or y <= y2 and x = 5 then
xpos := +xpos
ypos := +ypos
elsif y >= y3 or y <= y4 and x = maxx - 5 then
xpos := +xpos
ypos := +ypos
end if
if x < 5 or x >= maxx - 5 then
xpos := -xpos
end if
if y < 5 or y >= maxy - 5 then
ypos := -ypos
end if
end ball
loop
ball
leftbar
rightbar
x := x + xpos
y := y + ypos
Mouse.Where (x5, y5, button )
if Mouse.ButtonMoved ("Down") then
mouse
end if
if hasch then
Input.KeyDown (key )
keyboard
end if
if x = 5 then
exit
end if
cls
end loop
|
Mod Edit: Remember to use syntax tags! Copy the tags, and put your code where the code here is code: | [syntax="turing"]Code Here[/syntax] |
|
|
|
|
|
|
uknowhoiam
|
Posted: Sat Mar 14, 2009 9:58 am Post subject: RE:I need help with pong |
|
|
K i got the ball to bounce back but the problem is that it bounces down only, if i make it bounce up, i get an error here's my got
Turing: | View.Set ("graphics:650;400,offscreenonly")
Mouse.ButtonChoose ("multibutton")
var xpos, ypos, ypos1, ypos2, ypos3, ypos4 : int := 1
var x : int := maxx div 2
var y : int := maxy div 2
var y1 : int := maxy div 2 - 35
var y2 : int := maxy div 2 + 35
var y3 : int := maxy div 2 - 35
var y4 : int := maxy div 2 + 35
var key : array char of boolean
var x5, y5, button : int
colourback (black)
cls
procedure leftbar
drawfillbox (0, y1, 5, y2, white)
View.Update
end leftbar
procedure rightbar
drawfillbox (maxx - 5, y3, maxx, y4, white)
View.Update
end rightbar
procedure keyboard
%player 1
drawfillbox (0, y1, 5, y2, white)
View.Update
delay (2)
cls
if key (KEY_LEFT_ARROW) and y2 < maxy then
View.Update
y1 := y1 + 10
y2 := y2 + 10
elsif key (KEY_RIGHT_ARROW) and y1 > 0 then
View.Update
y1 := y1 - 10
y2 := y2 - 10
end if
end keyboard
procedure mouse
%player 2
drawfillbox (maxx - 5, y3, maxx, y4, white)
View.Update
delay (5)
cls
if button = 1 and y3 > 0 then
y3 := y3 - 5
y4 := y4 - 5
elsif button = 100 and y4 < maxy then
y3 := y3 + 5
y4 := y4 + 5
end if
end mouse
procedure ball
%ball
drawfilloval (x, y, 5, 5, white)
delay (5)
if x = 10 and y >= y1 and y <= y2 then
xpos := -xpos
ypos := -ypos
elsif y >= y3 and y <= y4 and x = maxx - 10 then
xpos := +xpos
ypos := +ypos
end if
if x < 5 or x >= maxx - 5 then
xpos := -xpos
end if
if y < 5 or y >= maxy - 5 then
ypos := -ypos
end if
end ball
loop
ball
leftbar
rightbar
x := x + xpos
y := y + ypos
Mouse.Where (x5, y5, button )
if Mouse.ButtonMoved ("Down") then
mouse
end if
if hasch then
Input.KeyDown (key )
keyboard
end if
if x = 5 then
exit
end if
cls
end loop
|
|
|
|
|
|
|
corriep
|
Posted: Sat Mar 14, 2009 11:06 am Post subject: Re: I need help with pong |
|
|
The game seems to work fine for me. The only thing you have to fix now is the flickering. To fix that, look at your code, how many View.Updates do you have, why do you need that many, try putting at the end of the main loop, and removing the delays and View.Updates in the middle of your procedures.
View.Update should only be used when everything is drawn and you want to display it. |
|
|
|
|
|
uknowhoiam
|
Posted: Sat Mar 14, 2009 4:30 pm Post subject: RE:I need help with pong |
|
|
k i fixed the flickering , i only need to know how to change the score, my score will not change, here's my code
Turing: | View.Set ("graphics:650;400,offscreenonly")
Mouse.ButtonChoose ("multibutton")
var xpos, ypos, ypos1, ypos2, ypos3, ypos4 : int := 1
var x : int := maxx div 2
var y : int := maxy div 2
var y1 : int := maxy div 2 - 35
var y2 : int := maxy div 2 + 35
var y3 : int := maxy div 2 - 35
var y4 : int := maxy div 2 + 35
var key : array char of boolean
var x5, y5, button : int
var speed : int := 5
var counter : int := 0
var score1, score2 := 0
colourback (black)
cls
procedure leftbar
drawfillbox (0, y1, 5, y2, white)
end leftbar
procedure rightbar
drawfillbox (maxx - 5, y3, maxx, y4, white)
end rightbar
procedure keyboard
%player 1
drawfillbox (0, y1, 5, y2, white)
delay (2)
cls
if key (KEY_LEFT_ARROW) and y2 < maxy then
y1 := y1 + 10
y2 := y2 + 10
elsif key (KEY_RIGHT_ARROW) and y1 > 0 then
y1 := y1 - 10
y2 := y2 - 10
end if
end keyboard
procedure mouse
%player 2
drawfillbox (maxx - 5, y3, maxx, y4, white)
View.Update
delay (5)
cls
if button = 1 and y3 > 0 then
y3 := y3 - 5
y4 := y4 - 5
elsif button = 100 and y4 < maxy then
y3 := y3 + 5
y4 := y4 + 5
end if
end mouse
procedure ball
%ball
drawfilloval (x, y, 5, 5, white)
if counter = 100 then
speed := speed - 1
end if
if counter = 200 then
speed := speed - 1
end if
if counter = 300 then
speed := speed - 1
end if
if counter = 400 then
speed := speed - 1
end if
if counter = 500 then
speed := speed - 1
end if
delay (speed )
if x = 10 and y >= y1 and y <= y2 then
xpos := -xpos
elsif y >= y3 and y <= y4 and x = maxx - 10 then
xpos := -xpos
end if
if x < 5 or x >= maxx - 5 then
xpos := -xpos
end if
if y < 5 or y >= maxy - 5 then
ypos := -ypos
end if
end ball
procedure loc_ball
x := maxx div 2
y := maxy div 2
end loc_ball
procedure score
if x = 5 then
score1 := score1 + 1
elsif x = maxx - 5 then
score2 := score2 + 1
end if
locate (1, 1)
colour (white)
put score2
end score
loop
ball
leftbar
rightbar
score
View.Update
x := x + xpos
y := y + ypos
counter := counter + 1
Mouse.Where (x5, y5, button )
mouse
if hasch then
Input.KeyDown (key )
keyboard
end if
if x = 5 then
delay (200)
loc_ball
elsif x = maxx - 5 then
delay (200)
loc_ball
end if
cls
end loop
|
|
|
|
|
|
|
BigBear
|
Posted: Sat Mar 14, 2009 6:10 pm Post subject: RE:I need help with pong |
|
|
The score is updating, you just arn't displaying both score1 and score2. |
|
|
|
|
|
corriep
|
Posted: Sat Mar 14, 2009 6:17 pm Post subject: RE:I need help with pong |
|
|
Quick tip: Getting rid of Turing: | if hasch then
% code
end if | but keeping the code inside of it will eliminate the need to constantly tap the arrow keys |
|
|
|
|
|
Sponsor Sponsor
|
|
|
BigBear
|
Posted: Sat Mar 14, 2009 6:28 pm Post subject: Re: RE:I need help with pong |
|
|
corriep @ Sat Mar 14, 2009 6:17 pm wrote: Quick tip: Getting rid of Turing: | if hasch then
% code
end if | but keeping the code inside of it will eliminate the need to constantly tap the arrow keys
Actually what that does it make it more senetive, it is able to get more inputs in a shorter time. if you were to use
and not asign key := "" every iteration of the loop it will act as you are holding down the key because it will keep the same value of key untill hasch or a key is pressed. |
|
|
|
|
|
uknowhoiam
|
Posted: Sat Mar 14, 2009 6:31 pm Post subject: RE:I need help with pong |
|
|
i dont get it, my score still wont update this is what i did
|
|
|
|
|
|
uknowhoiam
|
Posted: Sat Mar 14, 2009 11:07 pm Post subject: RE:I need help with pong |
|
|
NVM i got it work
Here's my code
Turing: | View.Set ("graphics:650;400,offscreenonly")
Mouse.ButtonChoose ("multibutton")
var xpos, ypos, ypos1, ypos2, ypos3, ypos4 : int := 1
var x : int := maxx div 2
var y : int := maxy div 2
var y1 : int := maxy div 2 - 35
var y2 : int := maxy div 2 + 35
var y3 : int := maxy div 2 - 35
var y4 : int := maxy div 2 + 35
var key : array char of boolean
var x5, y5, button : int
var speed : int := 5
var counter : int := 0
var score1, score2 := 0
colourback (black)
cls
procedure leftbar
drawfillbox (0, y1, 5, y2, white)
end leftbar
procedure rightbar
drawfillbox (maxx - 5, y3, maxx, y4, white)
end rightbar
procedure keyboard
%player 1
drawfillbox (0, y1, 5, y2, white)
delay (2)
cls
if key (KEY_LEFT_ARROW) and y2 < maxy then
y1 := y1 + 10
y2 := y2 + 10
elsif key (KEY_RIGHT_ARROW) and y1 > 0 then
y1 := y1 - 10
y2 := y2 - 10
end if
end keyboard
procedure mouse
%player 2
drawfillbox (maxx - 5, y3, maxx, y4, white)
View.Update
delay (5)
cls
if button = 1 and y3 > 0 then
y3 := y3 - 5
y4 := y4 - 5
elsif button = 100 and y4 < maxy then
y3 := y3 + 5
y4 := y4 + 5
end if
end mouse
procedure ball
%ball
drawfilloval (x, y, 5, 5, white)
if counter = 100 then
speed := speed - 1
end if
if counter = 200 then
speed := speed - 1
end if
if counter = 300 then
speed := speed - 1
end if
if counter = 400 then
speed := speed - 1
end if
if counter = 500 then
speed := speed - 1
end if
delay (speed )
if x = 10 and y >= y1 and y <= y2 then
xpos := -xpos
elsif y >= y3 and y <= y4 and x = maxx - 10 then
xpos := -xpos
end if
if x < 5 or x >= maxx - 5 then
xpos := -xpos
end if
if y < 5 or y >= maxy - 5 then
ypos := -ypos
end if
end ball
procedure loc_ball
x := maxx div 2
y := maxy div 2
end loc_ball
procedure score
end score
loop
colour (yellow)
put repeat ("%", maxcol)
exit
end loop
loop
ball
leftbar
rightbar
View.Update
x := x + xpos
y := y + ypos
counter := counter + 1
Mouse.Where (x5, y5, button )
mouse
if hasch then
Input.KeyDown (key )
keyboard
end if
if x = 5 then
delay (200)
loc_ball
elsif x = maxx - 5 then
delay (200)
loc_ball
end if
if x <= 6 then
score2 := score2 + 1
elsif x >= maxx - 6 then
score1 := score1 + 1
end if
locate (1, 1)
colour (white)
put score1
locate (1, maxcol)
colour (white)
put score2
if score1 = 5 then
locate (maxrow div 2, maxcol div 2)
colour (white)
put "Player 1 WON!"
delay (500)
exit
elsif score2 = 5 then
locate (maxrow div 2, maxcol div 2)
colour (white)
put "Player 2 WON!"
delay (500)
exit
end if
end loop
|
for the score this is what i did
|
|
|
|
|
|
uknowhoiam
|
Posted: Sun Mar 15, 2009 1:15 am Post subject: RE:I need help with pong |
|
|
Sorry im having too much fun, the keyboard lag is out
Turing: | View.Set ("graphics:650;400,offscreenonly")
Mouse.ButtonChoose ("multibutton")
var xpos, ypos, ypos1, ypos2, ypos3, ypos4 : int := 1
var x : int := maxx div 2
var y : int := maxy div 2
var y1 : int := maxy div 2 - 35
var y2 : int := maxy div 2 + 35
var y3 : int := maxy div 2 - 35
var y4 : int := maxy div 2 + 35
var key : array char of boolean
var x5, y5, button : int
var speed : int := 5
var counter : int := 0
var score1, score2 := 0
colourback (black)
cls
procedure leftbar
drawfillbox (0, y1, 5, y2, white)
end leftbar
procedure rightbar
drawfillbox (maxx - 5, y3, maxx, y4, white)
end rightbar
procedure keyboard
%player 1
drawfillbox (0, y1, 5, y2, white)
delay (2)
cls
y1 := y1 + 5
y2 := y2 + 5
end keyboard
procedure keyboard2
%player 1
drawfillbox (0, y1, 5, y2, white)
delay (2)
cls
y1 := y1 - 5
y2 := y2 - 5
end keyboard2
procedure mouse
%player 2
drawfillbox (maxx - 5, y3, maxx, y4, white)
View.Update
delay (5)
cls
if button = 1 and y3 > 0 then
y3 := y3 - 5
y4 := y4 - 5
elsif button = 100 and y4 < maxy then
y3 := y3 + 5
y4 := y4 + 5
end if
end mouse
procedure ball
%ball
drawfilloval (x, y, 5, 5, white)
if counter = 100 then
speed := speed - 1
end if
if counter = 200 then
speed := speed - 1
end if
if counter = 300 then
speed := speed - 1
end if
if counter = 400 then
speed := speed - 1
end if
if counter = 500 then
speed := speed - 1
end if
delay (speed )
if x = 10 and y >= y1 and y <= y2 then
xpos := -xpos
elsif y >= y3 and y <= y4 and x = maxx - 10 then
xpos := -xpos
end if
if x < 5 or x >= maxx - 5 then
xpos := -xpos
end if
if y < 5 or y >= maxy - 5 then
ypos := -ypos
end if
end ball
procedure loc_ball
x := maxx div 2
y := maxy div 2
end loc_ball
procedure score
end score
loop
colour (yellow)
put repeat ("%", maxcol)
exit
end loop
loop
ball
leftbar
rightbar
View.Update
x := x + xpos
y := y + ypos
counter := counter + 1
Mouse.Where (x5, y5, button )
mouse
Input.KeyDown (key )
if key (KEY_LEFT_ARROW) and y2 < maxy then
keyboard
elsif key (KEY_RIGHT_ARROW) and y1 > 0 then
keyboard2
end if
if x = 5 then
delay (200)
loc_ball
elsif x = maxx - 5 then
delay (200)
loc_ball
end if
if x <= 6 then
score2 := score2 + 1
elsif x >= maxx - 6 then
score1 := score1 + 1
end if
locate (1, 1)
colour (white)
put score1
locate (1, maxcol)
colour (white)
put score2
if score1 = 5 then
locate (maxrow div 2, maxcol div 2)
colour (white)
put "Player 1 WON!"
delay (500)
exit
elsif score2 = 5 then
locate (maxrow div 2, maxcol div 2)
colour (white)
put "Player 2 WON!"
delay (500)
exit
end if
end loop
|
|
|
|
|
|
|
|
|