home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-29 | 3.4 KB | 153 lines | [TEXT/Rich] |
- { Billiards Program Simulation - main program }
- { written by Tim Budd, Oregon State University }
- { April 1990 }
-
- program billiards;
-
- uses
- SimpleWindow, graphicUniverse, billiardComponents;
- type
- { the menu containing the quit command }
- BilliardMenu = object(SimpleMenu)
- procedure initialize (title: STR255);
- procedure selectItem (itemNumber: Integer); override;
- end;
-
- { the main simulation window }
- BilliardSimulation = object(SimpleWindow)
- procedure initialize;
- procedure buttonDown (x, y: integer); override;
- procedure update; override;
- procedure keyPressed (c: char); override;
- procedure createWalls;
- procedure createHoles;
- procedure rackBalls;
- end;
- var
- theGame: BilliardSimulation;
-
- { create a new menu }
- procedure BilliardMenu.initialize (title: Str255);
- begin
- self.createNewMenu(title);
- self.addItem('quit');
- end;
-
- { when the user selects quit, we quit }
- procedure BilliardMenu.selectItem (itemNumber: integer);
- begin
- theGame.endEventLoop;
- end;
-
- { initialize the billiard window }
- procedure BilliardSimulation.initialize;
- var
- appleMenu: SimpleMenu;
- newMenu: BilliardMenu;
- begin
- setAttributes;
- name := 'billiard Simulation';
- setRect(windowRect, 20, 50, 400, 350);
-
- new(theUniverse);
- theUniverse.initialize;
-
- createWalls;
- createHoles;
- rackBalls;
-
- new(appleMenu);
- appleMenu.createAppleMenu('about BilliardSimulation...');
-
- new(newMenu);
- newMenu.initialize('billiards');
-
- establish;
- end;
-
- { when the button goes down, it the cue ball }
- procedure BilliardSimulation.buttonDown (x, y: integer);
- begin
- cueBall.energy := 20.0;
- cueBall.direction := hitAngle(cueBall.x - x, cueBall.y - y);
- theUniverse.updateMoveableObjects;
- end;
-
- { to update the simulation, draw everything }
- procedure BilliardSimulation.update;
- begin
- inherited update;
- theUniverse.draw;
- end;
-
- procedure BilliardSimulation.createWalls;
- var
- newWall: wall;
- begin
- new(newWall);
- newWall.setBounds(10, 10, 300, 15, 0.0);
- theUniverse.installFixedObject(newWall);
- new(newWall);
- newWall.setBounds(10, 200, 300, 205, 0.0);
- theUniverse.installFixedObject(newWall);
- new(newWall);
- newWall.setBounds(10, 10, 15, 200, 3.114159);
- theUniverse.installFixedObject(newWall);
- new(newWall);
- newWall.setBounds(300, 10, 305, 205, 3.114159);
- theUniverse.installFixedObject(newWall);
- end;
-
- procedure BilliardSimulation.createHoles;
- var
- newHole: hole;
- begin
- new(newHole);
- newHole.setCenter(15, 15);
- theUniverse.installFixedObject(newHole);
- new(newHole);
- newHole.setCenter(15, 200);
- theUniverse.installFixedObject(newHole);
- new(newHole);
- newHole.setCenter(300, 15);
- theUniverse.installFixedObject(newHole);
- new(newHole);
- newHole.setCenter(300, 200);
- theUniverse.installFixedObject(newHole);
- end;
-
- procedure BilliardSimulation.rackBalls;
- var
- i, j: integer;
- newBall: ball;
- begin
- saveRack := 0;
- new(cueBall);
- cueBall.setCenter(50, 96);
- cueBall.direction := 0.0;
- theUniverse.installMovableObject(cueBall);
-
- for i := 1 to 5 do
- for j := 1 to i do
- begin
- new(newBall);
- newBall.setCenter(190 + i * 8, 100 + 16 * j - 8 * i);
- theUniverse.installMovableObject(newBall);
- end;
- end;
-
- { quit on any key press }
- procedure BilliardSimulation.keyPressed (c: char);
- begin
- endEventLoop;
- end;
-
- { ********** main program ********* }
- begin
- globalInitializations;
-
- new(theGame);
- theGame.initialize;
- theGame.eventLoop;
- end.
-