This is Ghost vs Monsters re-written in an object-oriented style of programming. It's intended as a example of how one might separate functionality within the application.
Many thanks to everyone at Beebe Games and Ansca for making the code publicly available!
The code is available on github: https://github.com/dmccuskey/Ghost-vs-Monsters---OOP
I have written more details about the changes: http://docs.davidmccuskey.com/display/docs/Ghosts+vs+Monsters+Details
For one of the changes I pulled out the level data from the game and changed its format to be JSON friendly. It would be very easy to add functionality to download game levels from the Internet. Each level now looks something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | --== Level 1 ==-- { info = { icon = "level1btn", level = "level1", restartLevel = "level1", nextLevel = "level2", characterName = "ghost", enemyName = "monster", }, backgroundItems = { { name="altbackground-one", x=0, y=160, reference="CenterLeft" }, { name="altbackground-two", x=480, y=160, reference="CenterLeft" }, { name="clouds-left", x=240, y=160 }, { name="clouds-right", x=720, y=160 }, { name="clouds-left", x=1200, y=160 }, { name="clouds-right", x=1680, y=160 }, { name="trees-left", x=240, y=160 }, { name="trees-right", x=720, y=160 }, { name="ground-light", x=150, y=190 }, }, physicsForgroundItems = { { name="ground-one", x=0, y=320, reference="BottomLeft" }, { name="ground-two", x=480, y=320, reference="BottomLeft" }, }, physicsGameItems = { -- bottom vertical items { name="vert-slab", x=600, y=215 }, { name="vert-slab", x=646, y=215 }, { name="vert-plank", x=623, y=215 }, { name="vert-plank", x=723, y=215 }, { name="vert-plank", x=821, y=215 }, { name="vert-slab", x=800, y=215 }, { name="vert-slab", x=843, y=215 }, { name="horiz-plank", x=674, y=162 }, { name="horiz-plank", x=772, y=162 }, { name="horiz-plank", x=723, y=142 }, { name="tombstone", x=650, y=128 }, { name="tombstone", x=796, y=128 }, { name="monster", x=745, y=125 }, { name="monster", x=700, y=125 }, }, }, |
The game is definitely playable, however, periodically the physics world will glitch at the beginning of a level, then it will be ok for awhile. Unfortunately, this seems to be common when working with the physics engine. During my research on how to make the physics engine behave, I found differing opinions, solutions and examples on how that was accomplished. More information is available in my writeup.
Excellent, well documented, thanks!