Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Making a Flash Game using PureMVC  (Read 19155 times)
dcabiness
Courseware Beta
Newbie
***
Posts: 1


View Profile Email
« on: August 14, 2007, 04:51:23 »

Hi, I'm trying to turn the HelloFlash demo into a game demo, but I'm not sure about the best way to go about things.

What would be the proper way to make it so the sprites in the HelloFlash demo collide into one another?
How about making it so they have a life span and destroy themselves and free up their used memory?

I'd like to change a tank game demo that I have so it fits into the PureMVC framework.  How would I make the tank's turret follow the mouse and the base move based on keyboard commands?

What about when the tank fires a bullet?  My guess is it would send a notification to a command object that would create the appropriate bullet model and view.  Then, when the bullet collides with something, it would send a notification to another command to have it destroyed?  Or would it be better to have a bullet manager that handles the bullet creation/destruction internally?

For basic AI, I guess there would be a macro command that controls basic commands to do things like move, aim and fire at the player?

As I think of more things to add, I realize I will need to add other design patterns to handle creating complex objects and manipulating complex display objects.  How would you incorporate factories or builders and composite views?

Also, I can see the stage mediator getting connected to many parts of the system.  How would I abstract it?  Maybe turn some commands into a strategy pattern so the stage mediator only adds and removes objects and sends out keyboard and mouse events to a small collection of macro commands that pass them on to handlers that modify the proper proxies?

I want to do these things the right way now so when my tank has a dozen different weapons and walks on 6 legs and can climb over some things but not others, but it can use a rocket pack to fly or jump over walls or whatever, my new game engine will be able to create a totally different type of game while reusing most of the code.

Any help is most appreciated.

Thanks,
David Cabiness
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: August 15, 2007, 11:11:53 »

David,

I'm excited to hear you talking about building a game with this. I started out writing games back when dinosaurs (like the trash-80, vic-20 and apple ][ ) roamed the earth. Somehow I wandered astray over the years and found myself doing scads of business related stuff.

This is not going to turn into another ramble down memory lane (In my day I once had to write a word processor in ones and zeros. Ones AND zeros? why we would've killed to have em both! WE had to work on unary systems where we could only use ones OR zeros. Had to write a shuttle control system for NASA in nothing but ones!)

Seriously, I was just thinking it would be great to see a game driven by the same framework that can drive an enterprise application. Though there are certainly many challenges in the enterprise, I remember being far more challenged by game work, or perhaps it was just that the use cases were so different in terms of the real-time nature of anything beyond tic-tac-toe. And it would really show off the ubiquitous nature of PureMVC. When AS3 hits the phones bigtime, it'll be a blast, since game development will be a big driver.

Unfortunately at this moment, there are a lot of questions you open there that I wouldn't want to extemporaneously suggest solutions for without a little more thought. But I did want you to know I wasn't overlooking this topic.

I will toss out a few thoughts though, that might help guide in the short term.

You're spot on about needing to employ other patterns. It's all about how do they fit or interact with the over-arching MVC pattern. The Model, View and Controller axes define the core nature of the application and should not get lost in a wash of other pattern package branches that show up as siblings to model, view and controller.

The first thing you should ask yourself when integrating another pattern is whether you really need it or if you can do it without a stretch within the patterns already in the framework. Not that the current pattern set solves everything, but just make sure there's a good argument why its too much of a stretch for the existing system. As simple as possible, no simpler.

Secondly, if you need to add the new pattern, which wing of the MVC suite does it belong in. A good example of integrating a simple helper pattern is the use of Enums and VOs in the model package of the Architecture 101 demo. They are accessed at the view, but clearly should be defined in the model for the model to be portable.

Consider a bunch of bullets flying around on independent trajectories. There are also a bunch of stationary and or moving objects that may collide with each other or a bullet.

I think this can all be managed by the mediators of the sprites themselves.

The mediators listen for a notification sent by a Timer managed by a TimeProxy. The big clock at the center of the universe. (Why a proxy? You might want to ask it the time. That's data, transient as it may be. This will be useful in the enterprise where we might want to add some date math helper methods as well.)

So, each sprite mediator, upon hearing the TIMER_TICK notification sent by the TimeProxy, advances its sprite and then sends a SPRITE_MOVED notification, with the sprite in question as the body.

All interested sprite mediators, handle the SPRITE_MOVED notification by doing a hitTest call on their sprite to see if there is a collision. ( (mySpriteInstance.hitTest(notification.getBody() as MySprite) )

Then its a rock / paper scissors game. If its a tank who's just heard that an anti-tank missile has collided with it, then the TankMediator instance will remove the event listeners from its view component, set the viewComponent property to null, and then call facade.removeMediator(this.getMediatorName()), freeing up the memory from the tank sprite and its mediator for the GC.

The TankMediator might send a TANK_EXPLODES notification, which fires a TankExplodesCommmand that plays a sound and bumps the score by a thousand by retrieving the ScoreProxy and doing scoreProxy.score+=1000.

Of course the ScoreProxy class's score property would actually be an implicit getter/setter pair. The setter would add the incoming value to the score and check to see if you crossed a level where you get a new weapon, more ammo, an extra man, etc.

You might have to have the StageMediator listen for keystrokes and mouse events from the stage, and send corresponding notifications. In the case of a FIRE event you might send a USER_FIRES notification which causes a bullet to appear at a given Point with a given vector.

Woops, I thought I'd decided to go off and think about this first. Hmm. Ok, well, it's really late, but I do believe this makes sense. Enough for you to get started with. I'll rejoin this discussion soon. Please keep us all updated on what you find.

-=Cliff>
« Last Edit: August 16, 2007, 09:11:21 by puremvc » Logged
harmanjd
Newbie
*
Posts: 5


View Profile Email
« Reply #2 on: June 12, 2008, 09:00:02 »

Just curious if the original poster has any follow up on the game.  Did you make it?  What decisions did you make for how the objects of the game fit into the mvc pattern? 


One question that I am struggling with is where a sound player belongs - is that a view component?

Thanks
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: June 13, 2008, 05:58:22 »

Yes, the sound player is a view component. The 'view' is really the 'presentation layer' and sound is part of the presentation.

-=Cliff>
Logged
dgtlmonk
Courseware Beta
Newbie
***
Posts: 8


View Profile Email
« Reply #4 on: June 13, 2008, 11:06:13 »

Very informative/educational indeed. Thank you Cliff.
Logged
Tehk
Newbie
*
Posts: 4


View Profile Email
« Reply #5 on: July 14, 2008, 11:53:56 »

hi everyone!

im thinking about creating a game too.

my question is related to this suggestion by cliff:

...

So, each sprite mediator, upon hearing the TIMER_TICK notification sent by the TimeProxy, advances its sprite and then sends a SPRITE_MOVED notification, with the sprite in question as the body.

All interested sprite mediators, handle the SPRITE_MOVED notification by doing a hitTest call on their sprite to see if there is a collision. ( (mySpriteInstance.hitTest(notification.getBody() as MySprite) )
...


i would have thought that the sprite mediators hear the TIMER_TICK notification, move the sprite, and then modify the model/proxy that is storing the position of the sprite. the proxy sends the notification SPRITE_MOVED, and then the mediators check for a hit?

how do you guys decide when to use a proxy and when to handle things in a mediator (i would do latter when needing a pure animation, that doesnt influence a proxy )



another question:
...
Then its a rock / paper scissors game. If its a tank who's just heard that an anti-tank missile has collided with it, then the TankMediator instance will remove the event listeners from its view component, set the viewComponent property to null, and then call facade.removeMediator(this.getMediatorName()), freeing up the memory from the tank sprite and its mediator for the GC.
...

when there are many instances of a mediator, wouldnt this.getMediatorName fail??


thanks for reading,
tehk
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: July 14, 2008, 06:26:04 »

The position of the sprite may not be held in the model in the case of a self-directed sprite. Unless there is some need for the rest of the game to know that info keep it close to where it is used/updated.

Also on the multiple instances of mediators or proxies, the key is to give each instance its own unique name, rather than passing in the NAME constant.

See the HelloFlash demo for an example of this with HelloSprite and its mediator.

-=Cliff>   
Logged
Tehk
Newbie
*
Posts: 4


View Profile Email
« Reply #7 on: July 14, 2008, 07:03:51 »

thanks for the insights!


so the model/proxy is only used when the information is used by lots of other classes?
(but wouldnt that be the case in the example with the hitTesting sprites??)


thanks again for sharing the framework and your knowledge with the community!
Logged
Lothiack


Email
« Reply #8 on: July 27, 2008, 12:12:06 »

Hello there!
I´m working on a game project and want to use AS3 & PureMVC too.
Here´s a link for an implementation of a Game MCV in Python. It has some good information.
http://sjbrown.ezide.com/games/writing-games.html#mvc

I´ll share my UML and some other stuff when they are ready. In the meantime I´ll post some other links I find.

Hope the link is useful!  ;)

<<<UPDATE>>>

Well, here they are:(attached somewhere!  :P )

Those are the first drafts for one of the proxies and some of his relations.  

This proxy carries the General Game Map data & internal logic. This general game map is just one module of the game. Another proxy will carry data for a battle module and one more for the main game state&module control.

The game resources(images, sounds, scripts...) will be loaded by a single manager proxy that distributes them to mediators. The intention here is to give artists some sort of script they can use to manage the resources timing & formatting. Its better not having to make another build every time you add some art. :D

Suggestions are welcome!
« Last Edit: July 29, 2008, 12:11:51 by Lothiack » Logged
Pages: [1]
Print