Created
March 30, 2011 08:07
-
-
Save kitschpatrol/894035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
«Basic class for game objects Provides: − Basic fields for position and motion | |
− Tracking of what game objects exist in the game − Initialize method − draw and tick generic procedures | |
To customize: | |
− Make sure your game calls [initialize-game-objects] when it starts | |
− Create a new subclass of GameObject − Add an initialize method, if needed Remember to use [call-next-method], if you do. − Add methods for draw and tick | |
» | |
[define all-game-objects “List of all objects currently in play” | |
[new ArrayList]] | |
[define initialize-game-objects | |
[→ [all-game-objects.Clear]]] | |
[define for-all-game-objects | |
[proc → | |
[for-each proc all-game-objects]]] | |
[define all-solid-game-objects “List of all solid objects currently in play.” | |
[filter [n → [= true n.solid]] all-game-objects]] | |
[define GameObject “Base class of all game objects” | |
[class [GameObject] | |
Object | |
position orientation | |
velocity angular-velocity | |
delete?]] | |
[define tick “Lets an object update itself as it sees fit.” | |
[generic-procedure]] | |
[define draw “Draws a game object using the specified Graphics object” | |
[generic-procedure]] | |
[define-method [initialize [GameObject o]] | |
[o.delete? ← false] | |
[all-game-objects.Add o] | |
[if [null? o.position] | |
[o.position ← [point 0 0]]] | |
[if [null? o.orientation] | |
[o.orientation ← 0.0]] | |
[if [null? o.velocity] | |
[o.velocity ← [point 0 0]]] | |
[if [null? o.angular-velocity] | |
[o.angular-velocity ← 0]]] | |
[define destroy “Remove game-object from the game's list of active objects” | |
[game-object → | |
[game-object.delete? ← true]]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment