sorry, guys, if this is a dumb question. I created a class Door that will put a sprite on stage for a door. When players touches the door, it will play the animation to open the door.
I spawn 10 doors on the same stage and now want to implement a logic as follows:
1) only 3 doors can be opened at the same time
2) when the 4th door will be opening, 3 other doors will close (the animation for closing the doors will start playing when player touches the 4th door)
now my question
Where do I implement the logic like that? is that implemented within the Door class itself or from the calling code? Do I need to use events to implement 2)?
I am struggling to understand the concept basically how to interact with objects and make them work together.
Comments
I guess right now you are using the main to host the 10 doors, right? You need an objec outside of door to keep track, the door will only be open or closed state.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
yeah for now I create doors from main but I just started I was going to use scene manager once I come up with the base structure for classes.
When I do single scene prototypes I always wrap them in a class as I would when using scene manager, so I then could easily bind it to scene manager when needed and it also helps to structure the code better
But let me try to tell how will i implement;
-In the door class i will create all events. (On touch etc..)
-Door object will have a state variable called "open" , bool, true false.
-On thouch event while it is changing the state from closed to open it will push object in a global stack.
( http://en.wikipedia.org/wiki/Stack_(abstract_data_type) )
-On touch event off door before pushing it will check the stack if there are more than 3 object in the stack pop out the first object in the stack and change the state to closed.
-Stack will be implemented as FIFO. (First in first out)
-In the main i will create array of objects from door class like this.
(Or in a loop)
objdoor[1]=door.new(anything you want to pass a variable like coordinates etc)
objdoor[2]=door.new(anything you want to pass a variable like coordinates etc)
objdoor[3]=door.new(anything you want to pass a variable like coordinates etc)
objdoor[4]=door.new(anything you want to pass a variable like coordinates etc)
objdoor[5]=door.new(anything you want to pass a variable like coordinates etc)
.......
Of course this logic can change according to main goal of the game. This is just a simple solution and i am sure not the optimized one:D
"-In the door class i will create all events. (On touch etc..)"
-Scene with code, that control doors
-Generic List of objects, that's implement Enumerator pattern
-And some consumers\predicates for List of Doors
Likes: talis
http://artleeapps.com/
Bubble Adventure - Colors
If you want you can create a stack class also.