Sign in to follow this  

ok, I read about them..now.., how do I use them? (patterns)

This topic is 4594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So, I've been reading about patterns for the past week, I realise it's not a very long time, but I've understood the basics..., now I want to implement these knowledge into a ultra-super-simple "game".... Then basic idea for the game is this: Object falling from the sky, at diferent speeds, and you control some kind of box, that moves horizontaly at the end of the screen, your objective is just to catch as many object as you can... Each object as a score asociated to it, and yes you guessed it, once you catch the object, that scores is added to yours... You also have some kind of "health", that goes down every time you let some object pass you by.... I'm thinking there could be diferent levels..., with diferent "specia objects", that give you life, or extra points... One extra thing, there will be clouds moving horizontaly and randomly at the top of the window..., don't ask me why, it's just for decoration... And..., well, that's about it... So far, all I got it's a simple UML diagram of the "sprite" class, from which other classes like "FallingObject", "Box", and "Cloud" will be derived.... My question is..., what patterns apply here? Well, thanks in advance!!! Haora

Share this post


Link to post
Share on other sites
well, i wouldn't derive them from a sprite class, since you should seperate the objects and their visual represantation. maybe look up observer pattern for this.

Share this post


Link to post
Share on other sites
Quote:
Original post by haora
now I want to implement these knowledge into a ultra-super-simple "game"....

Well you have a basic problem. Design patterns are most useful for big complicated projects because they simplify the design. In a ultra-super-simple project you might spend more time implementing the patterns than implementing the game.

Regardless, you might use one or more of the creational patterns to create sprites and game elements. You could use the Singleton pattern for interfaces to system resources like graphics, audio, timer. You could use the Flyweight pattern for managing sprites, Memento pattern for loading and saving games, Decorator pattern for power-ups, State pattern for AI, etc... I'm sure there are others that are useful.

Share this post


Link to post
Share on other sites
Quote:

Regardless, you might use one or more of the creational patterns to create sprites and game elements. You could use the Singleton pattern for interfaces to system resources like graphics, audio, timer. You could use the Flyweight pattern for managing sprites, Memento pattern for loading and saving games, Decorator pattern for power-ups, State pattern for AI, etc... I'm sure there are others that are useful.

Ok, great..., this is exactly what I was talking about...., thanks, keep them coming!

Quote:

well, i wouldn't derive them from a sprite class, since you should seperate the objects and their visual represantation. maybe look up observer pattern for this.

I've been traying to do this, but I don't think I did it right....
What I did whas:
I created 3 diferent subjects:
sClouds, sBox, sFallingObjects
And 3 classes of observers...
oCloud, bBox, oFallingObject

And the, I do something like this:
//this gives me 10 clouds
loop i = 0 to 10
sClouds.Attach(oCloud(i, "and other parameters here, like initial x and y"))

//this gives me 100 FallingObjects
loop i = 0 to 100
sFallingObjects.Attach(oFallingObject("initial conditions"));

//and only one box:
sBox.Attach(oBox("initial position"));

the, inside the main loop, something like this:
sClouds.Move(0); //moves the cloud horizontaly (the 0 is useless)
sFallingObjects.Move(0); //makes the objects fall, at their own speed (again, the 0 is useless)
sBox.Move(direction); //moves the box, the direction is determined by the user

Well, that's what I did, the "Move" method triggers the "Notify" method to update all the observers...

Now, I don't think I "separated" things a lot..., what did you mean exactly by "separate the object from their visual represantation"????

Well, thanks again!!

Haora

Share this post


Link to post
Share on other sites
A rather prominent C++ pundit recently stated that design pattern were for complicated projects, but I just don't see that. If you examine any object-oriented code that does useful work, you can find GoF patterns in use.

I think they are useful for even the simplest OO programs.

The visitor pattern comes to mind as something to explorer for manipulating a scene-graph. This is probably an extremely complicated expo case though.

For something practical, use the 'fly weight' pattern to create a D3D or OGL font render. Allow the programmer to realize a true-type font in a particular color, size, & style into a 'font fly weight' that consist of an array of textures and an array of letter objects. The 'letter' objects need to store the correct texture & coordinates to render that letter.
You'll have an efficent font render and have demostrated the fly-weight pattern.

Share this post


Link to post
Share on other sites
Quote:

For something practical, use the 'fly weight' pattern to create a D3D or OGL font render. Allow the programmer to realize a true-type font in a particular color, size, & style into a 'font fly weight' that consist of an array of textures and an array of letter objects. The 'letter' objects need to store the correct texture & coordinates to render that letter.
You'll have an efficent font render and have demostrated the fly-weight pattern.


Ok, that's an idea, but I'm planning on using allegro at first, 'cause I want to concentrate my efforts in aplying the patterns, and not in also learning DX or OpenGL..., and as I understand, Allegro seems to be easier to use...., I will eventually move on to DX or OpenGL...

In another note:
I'm still hoping that someone will review that "pseudo-code" I posted and tell me if I used the Observer Pattern right or not...(which I think I didn't)....
Does someone has like an URL or something in which I can read about how patterns are applied
to game programming?, so I won't have to ask like a million questions to you guys???

Well, thanks again!

Keep suggestions coming!

Haora

Share this post


Link to post
Share on other sites

This topic is 4594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this