Followers 0

# how to design my programs and games structure?

## 8 posts in this topic

hi.

iworked on some programs that some about games and some were not. and i worket on engines like udk and ue4 but there were always aproblem.

something that you you may say structure would happen during the programing. i just imagined and object as a class and started coding for it but there were a lot of mistakes there and those programs was not as compicated as im working now.

its better to write an structure for it but i dont know what is the best way for it.

i have learnt about ssadm and object oriented analyze like class diagram and ...... but i dont know do them work here as in a game we have concepts like spawning or ai behavior and......

are there any good pattern or procedure that help me design my game from ground up or by engine or my program for game like an editor for my levels.

how should i imagine of my program look like.

should i think about it as an end project that what i want and after that start to document those designs and after that start to code? what about i wanted there to be some changes. how should  structure be to those changes be easy?

0

##### Share on other sites

I guess there are as many ways to learn to structure code as people in the world, but I'll share what works for me.

When I'm learning a new framework or language I choose a game that I can code in an afternoon (snake and space invaders are my favourites) and I code it without caring much about structure and such things, because if I barely know what code to write, I'm not even close to know how to properly structure it. I choose a project I can code in a couple of hours because I try to finish it in one sitting, but I guess that's up to personal preferences.

One or two days after I rewrite the same game from scratch. Here I already know what code I need to write, so I can think how to structure it and I've had time to think about it. Sometimes, I will rewrite the game from scratch once again after a week or so, just for the sake of it.

Edit: yeah, and I forgot the point of the question. The Only True and Perfect WayTM to structure a program doesn't exist. Structuring the code is a skill and it needs lots of practise, as everything else. Choose projects of a manageable size for your skill and practise. After a few projects completed, you'll see how you have a clearer idea of how to structure the code every time you start a new project.

Footnote: embrace the refactor. Not for few times I've had to refactor comlpetely a project because the scope had grown beyond expected or simply due to bad decisions at the beginning. In my humble experience, refactor is an unavoidable fact of programmer's life.

Edited by Avalander
1

##### Share on other sites

Ask for a professional freelance designer in the forum ;) You will get great designs!

1

##### Share on other sites

Here is a readable way to structure things in Pong.


// Ball uses inheritance
public class Ball extends Sprite
{

public class Ball(double x , double y)
{
super(x,y);
}
}
// Sprite uses composition
public class Sprite implements GameComponent
{
private Vector2D position;
private Image image;

public Sprite(double x, double y)
{
position = new Vector2D(x,y);
}
}

public interface GameComponent
{
public void update();
public void draw(Graphics2D g2d);
}


One way to learn is to struggle with the design. Write the code design on paper. Contemplate on it. Why does this work and why did this break and the potential damage that can be done further down the line? It comes with experience and practice. You will improve through struggling and pushing on. Another way is to glance at other people's code to get an idea about how to approach the design instead of copying it.

As for structure the entire game, that can be quite complicated even for small games. Every time I went to outdo my last game project in terms of scale, I would use code from my previous games and then assemble together. Sometimes my design implementation is so bad for a specific feature from the last game, but I can change the design to make it more readable. You can fix a bad design through having staring at it for 4 months.

I guess the best way is to write clean code. Try to write clean code like the above. You can only write clean code if you have a holistic view of it which can be done using pencil and paper. I draw diagrams and pseudo-code. Use whatever techniques fit your needs.

Edited by warnexus
2

##### Share on other sites

Designing your code is the hardest part for me too. I usually already know how to implement the logic of the game I wanted but I couldn't start because I can't decide on how to design the bigger picture.

One design pattern that I started embracing is the Entity-Component (System) pattern. I find it easier to start coding without thinking too much about the design with this pattern. I can start writing independent components and then piece them together later. Sometimes, you just have to code all the necessary components first (make dependencies minimal) before you can have the general idea for your overall code. Idk if I'm making sense, I suck at explanations.

1

##### Share on other sites

i think entity-component-system is something like first you design the footballer as entity and after that you work on his functions like walking or running and varibles like height as component and work on its relation with other class object like ball as system. basically most of us i think do that. thank you

0

## Create an account

Register a new account