 Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki Blog Search Turing Chat Room Members
Pong Scoring Problem       Author Message
Schaef  Posted: Sat Dec 13, 2003 12:52 am   Post subject: Pong Scoring Problem

Ok, here is my pong game so far.. I am having trouble getting the score to go up when the ball hits 0 or maxx. Take a look at my code and try and find out what the problem is..

% PONG GAME

View.Set ("graphics:600;500, offscreenonly, nobuttonbar")

var a, b, c, d, e, f, g, introf : int
a := 200
b := 200
c := 10
d := 100
e := 0
f := 100
g := 0
var m : array char of boolean
var m2 : array char of boolean
introf := Font.New ("North Point:50:bold")
var xstep:int:=1
var ystep:int:=1

proc intro

for i : -10 .. 100
drawfilloval (i, 250, 10, 10, 2)
View.Update
if i < 100 then
cls
end if
end for
delay (500)
drawfilloval (150, 250, 10, 10, 4)
View.Update
delay (500)
drawfilloval (200, 250, 10, 10, 16)
View.Update
delay (500)
drawfilloval (250, 250, 10, 10, 16)
View.Update
delay (500)
drawfilloval (300, 250, 10, 10, 16)
View.Update
delay (500)
introf := Font.New ("North Point:50:bold")
Font.Draw ("d", 350, 240, introf, grey)
View.Update
Font.Draw ("sOFT", 380, 240, introf, black)
View.Update
delay (2000)
end intro

process scoring
var p2,p1:int
p2:=0
p1:=0
loop
put "P1:",p1
put "P2:",p2
if a-10<=0 then
p2:=p2+1
elsif a+10>=maxx then
p1:=p1+1
end if

delay(1)
cls
end loop
end scoring

% Moving Ball
process ball
loop
a:=a+xstep
b:=b+ystep
Draw.FillOval(a,b,10,10,0)
delay(5)
Draw.FillOval(a,b,10,10,12)
if a+15>=maxx then
xstep:=-1
elsif a-15<=0 then
xstep:=+1
elsif b+15>=maxy then
ystep:=-1
elsif b-15<=0 then
ystep:=+1
elsif a+10>=maxx and b<=f and b>=g then
xstep:=a-1
elsif a-10<=0 and b<=d and b>=e then
xstep:=a+1
end if
View.Update
cls
end loop
end ball

loop
Input.KeyDown (m)
drawfillbox (10, d, 0, e, 2)
if m ('w') then
d := d + 1
e := e + 1
View.Update
cls
elsif m ('s') then
d := d - 1
e := e - 1
View.Update
cls
end if
if d = maxy then
d := d - 1
e := e - 1
elsif e = 0 then
d := d + 1
e := e + 1
end if
end loop

loop
Input.KeyDown (m2)
drawfillbox (maxx, f, maxx - 10, g, 2)
if m2 (KEY_UP_ARROW) then
f := f + 1
g := g + 1
View.Update
cls
elsif m2 (KEY_DOWN_ARROW) then
f := f - 1
g := g - 1
View.Update
cls
end if
if f = maxy then
f := f - 1
g := g - 1
View.Update
end if
if g = 0 then
f := f + 1
g := g + 1
View.Update
end if
end loop

fork scoring
fork ball    Andy Posted: Sat Dec 13, 2003 4:54 pm   Post subject: (No subject)

y are u using process for scoring? make it a procedure and run it in ur program   Posted: Sat Dec 13, 2003 5:08 pm   Post subject: (No subject)

Wow, complex for such an easy concept, geez.
 code: var p1_score,p2_score:int:=0 var ballx,bally:int:=0 %Pong Program code...blah blah %...assuming radius of ball is '15' if ballx-15<=0 then ballx,bally:=200 p2_score:=p2_score+1 elsif ballx+15>=maxx then ballx,bally:=200 p1_score:=p1_score+1 end if

If the Left side of the ball hits the left side of the screen (past player 1s paddle, player 2's score goes up. Or if the right side of the ball hits the right side of the screen past player 2s paddle, player 1 gets a point.
Easy.  Andy Posted: Sat Dec 13, 2003 5:28 pm   Post subject: (No subject)

or u can use whatdotcolor instead of drawing the background that color, simply draw a box in the viewable area, then use whatdtocolor to check if the ball is out   Posted: Sat Dec 13, 2003 5:37 pm   Post subject: (No subject)

Yeah, either way works really. Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First        Page 1 of 1  [ 5 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: