Hi All,
Introduction
I am developing a 2d tower defense game using unity. A couple of weeks ago and though making nice progress, I felt that robustness of the design is lacking due to the tight dependencies between the various components of the game. So I decided to take a pause with the development and do some research on how to redesign the game. A short research led me to strange framework and after a few days of reading the documentation and going over various examples I feel that I understand the concepts and their value in making the game design better. However, I still am unsure about how to project my game into the strange components (i.e. what are my commands, signals, views, models and controllers) and was hoping to get some guidance from folks here in the forum with a more experience in using strange for their games. I thought that perhaps getting a direction check on an example might help me in moving forward with my new design.
Moving Creeps along a path example
Not surprisingly, the creeps in a tower defense game are walking along a spline path. I have an editor extension that allows me to visually create the spline from unity and to generate an array of way points that get injected to the path game object. Creeps hold a reference to the path object and follow the way point when spawned.
Since the game is a 2d game, I have 4 "RUN" animations per creep: up, down, left and right. Every time the creep reaches a way point I recalculate the direction the creep is pointing to and trigger the proper "RUN" animation via the Animator object. All of this is pretty simple, right?
Now, I am trying to figure out how to translate this code to strange. Here are my thoughts:
LevelModel: A model class that contains a the array of points in the path. For simplicity, let's assume there is a single path for now in each level.
CreepModel: A model class that tracks the currently assigned index in the path and the current RUN animation to use by the animator.
CreepView: The view class of the creep game object. Among many other things, the game object contains a unity Animator object that drives the 4 "RUN" animations. This component is accessible to the view.
CreepMediator: The creep mediator class.
And now comes the flow I had in mind:
- Let's assume the creep is already running along the spline.
- The CreepView MonoBehavior::Update() method drives the position of the creep game object towards the next assigned way point in the path.
- When reaching the next assigned way point in the path. The CreepView sends a WayPointReached signal, which is a simple empty signal.
- This signal is registered by its view (the CreepMediator). In response, the CreepMediator checks whether this is the last way point in the path and responds:
- If this is not the last way point, sends a signal to move the creep to its next way point
- If this is the last way point, sends an end of path reached
- Both signals described in #4 are mapped to equivalent commands that contain the logic.
- The AssignNextWayPoint command updates the creep model with the current index and "RUN" animation of the CreepModel.
- The CreepModel updates these values and triggers WayPointUpdated signal which is registered by the CreepMediator object.
- The mediator injects that information to the CreepView.
And a few questions:
- Does this seem like a sane approach when using strange MVCS approach?
- It is very tempting to let the CreepMediator do the calculations internally and shortcut the need for all the signals and controller commands, what do you think?
- I can take step #4 even one step further and push the logic in the mediator into the CreepModel, so that the model is the one to send an end of path reached signal instead of a WayPointUpdated signal
- Is this flow a big performance overhead (let's assume the commands & signals are all pooled)?
Thanks and sorry for this long post,
Boaz