Pong Game..score dont add up...any suggestions?
Author |
Message |
Code_Urban
|
Posted: Thu Nov 04, 2004 9:20 pm Post subject: Pong Game..score dont add up...any suggestions? |
|
|
for some reason when i let the ball ust bounce on the right and left sides..the score dont add...can anyone suggest anything...and as u can see, me nad my class are just starting and all we've been using are if statements....we know all varibles and crap like that...its just that tthe ball.......trying a lot to fix it........the score dont add...so plz give me suggestions just on the BALL SCORE...and its at the bottom (its bolded)
View.Set ("graphics:640;480,offscreenonly")
var x,y,:int
var x1,y1,x2,y2 :int
var xstep, ystep:int :=5
var key :string (1)
var p1move, p2move:int
var colourpad,ballcolour, ballcolour1:int
va ballx,bally,rad,p1score,p2score:int
var font1:int : = Font.New ("Bookman Old Style BT:12")
var font2:int : = Font.New ("Comic Sans MS BT:12:underline")
x:=360
y:=240
colourpad:= 6
x1:=10
y1:=180
x2:=620
y2:=180
p1move:=25
p2move:=25
p1socre:=0
p2score:=0
rad:=5
loop
drawfillbox (640,0,0,480,9)
drawfillbox (0,440,640,480,7)
Font.Draw ("Player 1: ",10,450,font1,0)
Font.Draw ("Player 2: ", 490,450,font1,0)
Font.Draw ("Score", 280,465,font2,0)
drawfillbox (x1,y1,x1+10,y1+50,colourpad)
drawfillbox (x2,y2,x2+10,y2+50,colourpad)
x:=x + xstep
y:=y + ystep
if x > 630 or x < 10 then
xstep := - xstep
end if
if y > 430 or y < 10 then
ystep := - ystep
end if
if hasch then
getch (key)
if (key = "A' or key = "a" ) and y1 < 300 then
y1 := y1+p1move
end if
if (key = "Z" or key = "z") and y1 > 5 then
y1 := y1-p1move
end if
if key = chr (200) and y2 < 440 then
y2 := y2 +p2move
end if
if key = chr (208) and y2 > 5 then
y2 := y2-p2move
end if
if x + rad >= x2 then
if y >= y2 and y <= y2 + 50 then
xstep := -xstep
end if
end if
if x - rad <= x1 + 10 then
if y >= y1 and y <= y1 + 50 then
xstep := -xstep
if x+rad >= 640 then
p1score := p1score +1
end if
end if
end if
end loop
thanks peace
DAVID |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Paul
|
Posted: Thu Nov 04, 2004 9:33 pm Post subject: (No subject) |
|
|
You don't have a moving ball in this particular piece of code
and lots of typos too, are u doing this in a turing editor?
anyhow, I see you have a ballx and bally variable, just do a couple of if statements inside the loop, so that if the ball hits the left wall or right wall something like:
code: |
if ballx <= 0 then
player2score+=1
end if
if ballx >= maxx then
player1score+=1
end if
|
of course you can just put that as part of your collision detection code... which I assume exists... just not part of this piece of coding. |
|
|
|
|
|
Code_Urban
|
Posted: Thu Nov 04, 2004 9:46 pm Post subject: (No subject) |
|
|
omg im srry.......lol....i forgot 8 lines of code i dont know how but heres the real one
View.Set ("graphics:640;480,offscreenonly")
var x,y,:int
var x1,y1,x2,y2 :int
var xstep, ystep:int :=5
var key :string (1)
var p1move, p2move:int
var colourpad,ballcolour, ballcolour1:int
va ballx,bally,rad,p1score,p2score:int
var font1:int : = Font.New ("Bookman Old Style BT:12")
var font2:int : = Font.New ("Comic Sans MS BT:12:underline")
x:=360
y:=240
colourpad:= 6
x1:=10
y1:=180
x2:=620
y2:=180
p1move:=25
p2move:=25
p1socre:=0
p2score:=0
rad:=5
loop
drawfillbox (640,0,0,480,9)
drawfillbox (0,440,640,480,7)
Font.Draw ("Player 1: ",10,450,font1,0)
Font.Draw ("Player 2: ", 490,450,font1,0)
Font.Draw ("Score", 280,465,font2,0)
drawfillbox (x1,y1,x1+10,y1+50,colourpad)
drawfillbox (x2,y2,x2+10,y2+50,colourpad)
drawfilloval (x,y,rad,rad,ballcolour)
View.Update
delay(50)
drawfilloval (x,y,rad,rad,0)
drawfillbox (x1,y1,x1+10,y1+50,7)
drawfillbox (x2,y2,x2+10,y2+50,7)
x:=x + xstep
y:=y + ystep
if x > 630 or x < 10 then
xstep := - xstep
end if
if y > 430 or y < 10 then
ystep := - ystep
end if
if hasch then
getch (key)
if (key = "A' or key = "a" ) and y1 < 300 then
y1 := y1+p1move
end if
if (key = "Z" or key = "z") and y1 > 5 then
y1 := y1-p1move
end if
if key = chr (200) and y2 < 440 then
y2 := y2 +p2move
end if
if key = chr (208) and y2 > 5 then
y2 := y2-p2move
end if
if x + rad >= x2 then
if y >= y2 and y <= y2 + 50 then
xstep := -xstep
end if
end if
if x - rad <= x1 + 10 then
if y >= y1 and y <= y1 + 50 then
xstep := -xstep
if x+rad >= 640 then
p1score := p1score +1
end if
end if
end if
end loop |
|
|
|
|
|
|
|