Help 2d game classes

05/18/2016 03:00 elmarcia#1
i want to develop a simple game, just for fun and practice coding, i hardcode so bad that i give up doing that way and want to implement the correct one :)

I made a class diagram in rational so anyone can understand what i want, and what is wrong.

[Only registered and activated users can see links. Click Here To Register...]

Want to know:
1- Is anything bad implemented?
2- Should i change setState to be a static method?
3- Is ok that gameCamera is static?
4- Things to improve

Thx for your time :handsdown:
05/18/2016 21:29 Mysthik#2
I might have a few things.

Designing games is a well studied topic. There are a lot of design-patterns like an event-queue or the update-loop if you are interested [Only registered and activated users can see links. Click Here To Register...]a few more.


1. This might be just a name thing but why does your GameState need to be renderable? You might want to look into the MVC-Pattern to seperate logic, data-model and view. For someone who is new to programming this pattern is awful but it makes it easier to switch the view if you want to change it later.

2. & 3. Static mutable states are problematic especially if you change the states from different threads.
  1. Do you need to access it from everywhere (and always the same instance) and it is not a constant? --> Make it a Singleton with thread-safe methods
  2. Is it a constant? Make it static-final
Other OO-Languages don't use the static concept because static members kinda destroy the whole OOP paradigm. So only use static members if you really need to. Scala for example doesn't have static members if you want a static method or constan you always put it into a singleton-object.
05/19/2016 00:44 Achat#3
Wow, with what did you create that diagram? Could really need something like that.

It's difficult to tell you something only based on the diagram, but my improvements for you:
  • never use public attributes
  • don't use static except when really necessary
How is player supposed to jump if the method is private?

Other questions that came to my mind:
  • How is data workflow?
  • thread-safe? threads?
  • separation of data, gui, network etc?
  • Did you actually code something yet? Or did you just "design" classes?
05/20/2016 20:14 elmarcia#4
I did some code, and jump is bad implemented because when player call update will register input and if is needed key will jump. So the diagram too

Those diagrams are made in rational from ibm [Only registered and activated users can see links. Click Here To Register...]
I have full version from my university =)

Quote:
Originally Posted by Mysthik View Post
I might have a few things.

Designing games is a well studied topic. There are a lot of design-patterns like an event-queue or the update-loop if you are interested [Only registered and activated users can see links. Click Here To Register...]a few more.


1. This might be just a name thing but why does your GameState need to be renderable? You might want to look into the MVC-Pattern to seperate logic, data-model and view. For someone who is new to programming this pattern is awful but it makes it easier to switch the view if you want to change it later.

2. & 3. Static mutable states are problematic especially if you change the states from different threads.
  1. Do you need to access it from everywhere (and always the same instance) and it is not a constant? --> Make it a Singleton with thread-safe methods
  2. Is it a constant? Make it static-final
Other OO-Languages don't use the static concept because static members kinda destroy the whole OOP paradigm. So only use static members if you really need to. Scala for example doesn't have static members if you want a static method or constan you always put it into a singleton-object.
I will use mvc pattern to split logic and views, but by now i prefer learning with something that i can iterate over and over again and see how is its behaviour and when i'm happy with my logic making independant from view is easy :)