Share Your Code

Ghost vs Monsters - OOP

Posted by dmccuskey, Posted on September 30, 2011, Last updated October 18, 2011

GitHub URL: 
http://github.com/dmccuskey/Ghost-vs-Monsters---OOP

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!

Highlights

  • Simplification of level data
  • State Pattern for game objects and engine
  • Factory Pattern to create all objects
  • Working load screen which also spans Director Scenes
  • Organization of assets
  • No globals
  • etc, etc

Information

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

Example Update

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 },
        },
},

Issues

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.


Replies

JRQ
User offline. Last seen 15 weeks 6 days ago. Offline
Joined: 28 Sep 2010

Excellent, well documented, thanks!

guh.clemente
User offline. Last seen 18 weeks 1 day ago. Offline
Joined: 14 Oct 2010

thanks!!!!!

ron
User offline. Last seen 1 year 29 weeks ago. Offline
Joined: 19 Dec 2009

This is really impressive work. Thank you for sharing it!

dmccuskey
User offline. Last seen 3 days 19 hours ago. Offline
Joined: 8 Jul 2011

thank you all for the great kudos ! :)

lemartva
User offline. Last seen 1 year 50 weeks ago. Offline
Joined: 11 May 2011

Thanks for Sharing.

asad
User offline. Last seen 1 year 21 weeks ago. Offline
Joined: 28 Nov 2012

thank you for sharing. i am new with corona. i am wondering how can i implement game sound on/off functionality. please give me some hints .
thanks in advance