Object Oriented Programming in Corona, a good idea or a bad one?

Hey guys, so I’m developing my first game in Corona, and things quickly became, well, a mess… So I started looking into using the OOP style of writing code… I found this blog post by Darren Osadchuk, and it helped a lot. http://www.ludicroussoftware.com/blog/2011/07/06/simple-oop-with-inheritance-in-corona/ What confuses me now, it where I put my game logic, and how I do it, using storyboard… I have a class for the player, for the game logic, game objects, etc… I can’t figurev out how I put my game logic into a class… Do I put it all in one function, or seperate it into sub-funcitons? Let’s say I have a function to start the ‘camera’ effect. To do that I need the player.x and group.x, when I reference that function, do I have to pass in the player and view group so it can move the group? I hope that makes sense… lol Thanks!

-Jake [import]uid: 144504 topic_id: 27383 reply_id: 327383[/import]

In response to the subject of the post, it’s neither good or bad, it just is. Some people can organize their code better using Object Oriented practices, others see it as extra overhead. There is no right or wrong.
The body of your post asks a different question, which I’m not sure I’m all that qualified to answer since I’m old school procedural and I haven’t seen your code.

But in the OOP mentality, your player object would have methods (functions) for anything that needs to interact with the player:

player:move()
player:jump()
player:takeDamage()

for your coins (I don’t know what your making, so pretend this makes sense)

coin:pickUp()
coin:spawn()

monster:spawn()
monster:takeDamage()
monster:attack()
Then in storyboard, you would put whatever functions you need to tie your player to the world, pick up coins etc. Most likely you would have what’s known as a game loop, which in Corona is typically implemented with an

Runtime:addEventListener(“enterFrame”, gameloop)

call. You provide a function gameloop() that then runs through your spawned enemies to move them, spawn new coins, etc. You let however you drive your player (touch, joystick, etc.) trigger events when the player moves (that will probably be outside the gameloop) calling the proper object methods as needed.

Hope that makes sense.
[import]uid: 19626 topic_id: 27383 reply_id: 111252[/import]

Thank you so much! Sorry about the title and body having different questions, not sure what I was think there… I’m not currently using a game loop, which might sound wierd, its probably because I haven’t added a whole bunch of functionality… Currently all my game logic is in the enterFrame function of my level, which is really inconvenient for making other levels… So I should have that logic in the game loop instead?

Thanks again!

-Jake [import]uid: 144504 topic_id: 27383 reply_id: 111255[/import]

I used to code in oop, but now I put everything in one lua as its faster to develop(I don’t use storyboard). For example my previous game Dragon Evolution Free
http://itunes.apple.com/us/app/dragon-evolution-free/id527691582?mt=8

you can try remove and add listener to another game loop
Runtime:removeEventListener(“enterFrame”, gameloop_level1)
Runtime:addEventListener(“enterFrame”, gameloop_level2)

or you can put it in the gameloop

[code]
function gameloop()
—common codes—
characterRun()

if gameLevel == 1 then
—codes
cameraMovement1()
elseif gameLevel == 2 then
—codes
cameraMovement2()
end
end
[/code] [import]uid: 49513 topic_id: 27383 reply_id: 111257[/import]

Ok, I see… What do you do to organize your scenes if you don’t use storyboard? Use director?
Thanks!

-Jake [import]uid: 144504 topic_id: 27383 reply_id: 111353[/import]

@Jake people sometimes “roll there own”. As in they make there own scene managers.

OOP is definately a good idea, no question about that. One of the most important things to do is to have re-usable functions. [import]uid: 84637 topic_id: 27383 reply_id: 111357[/import]

Yeah, that makes sense… How would I access the scene view from a game loop?

-Jake [import]uid: 144504 topic_id: 27383 reply_id: 111369[/import]