Introduction to OOP Chapter 7: A Billiards Game: next previous audio real text

Balls move when updated

procedure TBall.update;
var
	hptr : THole;
	wptr : TWall;
	bptr : TBall;
	dx, dy : integer;
begin
	if energy > 0.5 then begin
		ballMoved := true;
			{ decrease energy }
		energy := energy - 0.05;
			{ move ball }
		dx := trunc(5.0 * cos(direction));
		dy := trunc(5.0 * sin(direction));
                x := x + dx;
                y := y + dy;
		
			{ see if we hit a hole }
		hptr := listOfHoles;
		while (hptr <> nil) do
			if hptr.hasIntersected(self) then begin
				hptr.hitBy(self);
				hptr := nil;
			end
			else
				hptr := hptr.link;

			{ see if we hit a wall }
		wptr := listOfWalls;
		while (wptr <> nil) do
			if wptr.hasIntersected(self) then begin
				wptr.hitBy(self);
				wptr := nil;
			end
			else
				wptr := wptr.link;

			{ see if we hit a ball }
		bptr := listOfBalls;
		while (bptr <> nil) do
			if (bptr <> self) and bptr.hasIntersected(self) then begin
				bptr.hitBy(self);
				bptr := nil;
			end
			else
				bptr := bptr.link;
	end;
end;
Intro OOP, Chapter 7, Slide 7