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
 
 
%FIRST PADDLE
 
 
process paddle1
 
    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
 
end paddle1
 
 
% SECOND PADDLE
 
process paddle2
 
    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
 
end paddle2
 
 
 
fork scoring
 
fork paddle1
 
fork paddle2
 
fork ball | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		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 | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		DanShadow
 
  
 
    
		 | 
		
		
			
				  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 | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		DanShadow
 
  
 
    
		 | 
		
		
			
				  Posted: Sat Dec 13, 2003 5:37 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Yeah, either way works really. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |