
-----------------------------------
Hunter007
Mon Jan 19, 2004 7:55 pm

Counter adding by 1...
-----------------------------------
Hey, this is another program that my friend's been working on. I can't seem to figure out why the counter keeps screwing up. The balls move and when they are supposed to intersect the collision counter adds it but when it bounces off the wall (going from left to right) it adds another collision where they usually hit.


View.Set ("graphics:481;481,offscreenonly") 

%BORDER 

%left side 
drawfilloval (15, 15, 15, 15, red) 
drawfilloval (15, 45, 15, 15, blue) 
drawfilloval (15, 75, 15, 15, green) 
drawfilloval (15, 105, 15, 15, blue) 
drawfilloval (15, 135, 15, 15, green) 
drawfilloval (15, 165, 15, 15, blue) 
drawfilloval (15, 195, 15, 15, green) 
drawfilloval (15, 225, 15, 15, blue) 
drawfilloval (15, 255, 15, 15, green) 
drawfilloval (15, 285, 15, 15, blue) 
drawfilloval (15, 315, 15, 15, green) 
drawfilloval (15, 345, 15, 15, blue) 
drawfilloval (15, 375, 15, 15, green) 
drawfilloval (15, 405, 15, 15, blue) 
drawfilloval (15, 435, 15, 15, green) 
drawfilloval (15, 465, 15, 15, red) 


%bottom 
drawfilloval (45, 15, 15, 15, blue) 
drawfilloval (75, 15, 15, 15, green) 
drawfilloval (105, 15, 15, 15, blue) 
drawfilloval (135, 15, 15, 15, green) 
drawfilloval (165, 15, 15, 15, blue) 
drawfilloval (195, 15, 15, 15, green) 
drawfilloval (225, 15, 15, 15, blue) 
drawfilloval (255, 15, 15, 15, green) 
drawfilloval (285, 15, 15, 15, blue) 
drawfilloval (315, 15, 15, 15, green) 
drawfilloval (345, 15, 15, 15, blue) 
drawfilloval (375, 15, 15, 15, green) 
drawfilloval (405, 15, 15, 15, blue) 
drawfilloval (435, 15, 15, 15, green) 
drawfilloval (465, 15, 15, 15, red) 

%right side 
drawfilloval (465, 45, 15, 15, green) 
drawfilloval (465, 75, 15, 15, blue) 
drawfilloval (465, 105, 15, 15, green) 
drawfilloval (465, 135, 15, 15, blue) 
drawfilloval (465, 165, 15, 15, green) 
drawfilloval (465, 195, 15, 15, blue) 
drawfilloval (465, 225, 15, 15, green) 
drawfilloval (465, 255, 15, 15, blue) 
drawfilloval (465, 285, 15, 15, green) 
drawfilloval (465, 315, 15, 15, blue) 
drawfilloval (465, 345, 15, 15, green) 
drawfilloval (465, 375, 15, 15, blue) 
drawfilloval (465, 405, 15, 15, green) 
drawfilloval (465, 435, 15, 15, blue) 
drawfilloval (465, 465, 15, 15, red) 

%top 
drawfilloval (45, 465, 15, 15, green) 
drawfilloval (75, 465, 15, 15, blue) 
drawfilloval (105, 465, 15, 15, green) 
drawfilloval (135, 465, 15, 15, blue) 
drawfilloval (165, 465, 15, 15, green) 
drawfilloval (195, 465, 15, 15, blue) 
drawfilloval (225, 465, 15, 15, green) 
drawfilloval (255, 465, 15, 15, blue) 
drawfilloval (285, 465, 15, 15, green) 
drawfilloval (315, 465, 15, 15, blue) 
drawfilloval (345, 465, 15, 15, green) 
drawfilloval (375, 465, 15, 15, blue) 
drawfilloval (405, 465, 15, 15, green) 
drawfilloval (435, 465, 15, 15, blue) 

var xpos : int := 55 
var move : int := 1 
var move1 : int := 1 
var yPos : int := 155 
var ymove : int := 1 
var ymove1 : int := 1 
var counter : int := 0 
var xypos : int := 200 
var yxpos : int := 110 

% counter 




loop 
   drawfilloval (xpos, yxpos, 25, 25, brightgreen) 
   View.Update 
   delay (10) 
   drawfilloval (xpos, yxpos, 25, 25, white) 
   if xpos > maxx - 58 then 
       move := move * -1 
   end if 
   if xpos < 58 then 
       move := move1 * 1 
   end if 
   xpos := xpos + move 

   % other ball 

   drawfilloval (xypos, yPos, 25, 25, black) 
   View.Update 
   delay (10) 
   drawfilloval (xypos, yPos, 25, 25, white) 
   if yPos > maxy - 58 then 
       ymove := ymove * -1 
   end if 
   if yPos < 58 then 
       ymove := ymove1 * 1 
   end if 
   yPos := yPos + ymove 

   % counter 

   if (xpos+12) + (yPos+12) = (xypos+12) + (yxpos + 12) 
           then 


       counter := counter + 1 
   end if 
Text.Locate (3, 5) 
put "Collision: ", counter 
  Text.Locate (3, 16) 
   put counter 




end loop 


Also the balls still flash which is annoying. I thought View.Set and View.Update would fix it, but I think he put it in the wrong spot.

-----------------------------------
TheXploder
Mon Jan 19, 2004 9:13 pm


-----------------------------------
Try something like this:


var gridxsize, gridysize : int

gridxsize := 30
gridysize := 30

function newX (x : int) : int
    result x * gridxsize
end newX

function newY (y : int) : int
    result y * gridysize
end newY

proc objCircle (x, y, circleSize, clr : int)
    drawfilloval (newX (x) + circleSize, newY (y) + circleSize, circleSize, circleSize, clr)
end objCircle

for i : 1 .. 16
    objCircle (i-1, 0, 15, i)
end for


-=TheXploder=-
