Friday, 13 June 2014

Executive is up and running.

The executive engine/framework is up and running, this is an example of it running.

There are four classes here - the bat, the score, the ball and the controller, everything is controlled by the executive.

The controller is a self contained object, so it just can be loaded and used - you require it in and attach it, and you can then access it via executive.e.controller - I decided not to use a messaging system.

Messages are used for the ball delay at the start, to update the score, and the balls each broadcast a message to 'obstacles' to check for collisions.

It allows you to switch pretty much as you want between asynchronous messages and direct messages - so for example to increment the score you can either use

self:sendMessage("score",{points = 10})

or you could with an extra line or two do it something like


I quite like this design. This code is almost completely unchanged from the SOE demo, except for the basic API stuff which has changed slightly.

Because objects are automatically attached (normally, the controller isn't yet) then you can simply add bats and balls as often as you want and it just works.  The main code looks like this:

Bat:new({ x = 32 }) Bat:new({ x = display.contentWidth/3 })
for i = 1,33 do Ball:new({}) end Ball:sendMessage("ball",{},1000)

Two bats, 33 balls, and a delay of 1000ms before balls receive an empty message which tells them to start moving.

One problem, which is a lua issue, is with executive objects now being non-singletons, when you require an object it doesn't know which instance of the executive to attach itself to. So at the moment it is added as a mixin (this is used for objects with non-nil metatables, like Corona display objects, see the score in the pong Demo as an example).


i.e. require the controller class, create a new instance, and add it as a mixin object. May be a case for having an addRequireObject("controller",{}) method. I will give it some thought.

No comments:

Post a Comment