Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How would i make the games logic  (Read 2770 times)

0 Members and 1 Guest are viewing this topic.

lukaius

  • Guest
How would i make the games logic
« on: November 28, 2017, 08:33:46 pm »
Should i make a game's parts ( player,sprites,etc) into classes or in separate files
« Last Edit: November 28, 2017, 09:18:20 pm by eXpl0it3r »

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: How would i make the games logic
« Reply #1 on: November 29, 2017, 11:47:29 pm »
Check out the SFML game development book

https://www.packtpub.com/game-development/sfml-game-development

It walks you through making a simple game from start to finish

Shane

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: How would i make the games logic
« Reply #2 on: December 01, 2017, 03:13:40 pm »
I find making players, enemies, items, etc. into objects each having their own class easy to work with.  A common approach is to have a base class/interface for each 'type' of object and child classes for the specifics.  This allows for grouping objects of different types into collections (google polymorphism).

For game states logic, implement some sort of state manager that allows easy switching between states.  Make use of the stack for this.  Here is a great tutorial for a simple state manager.
 
https://www.binpress.com/tutorial/creating-a-city-building-game-with-sfml-part-1-state-manager/123

lukaius

  • Guest
Re: How would i make the games logic
« Reply #3 on: December 06, 2017, 04:24:56 am »
Thanks shane!!

RealmRPGer

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: How would i make the games logic
« Reply #4 on: December 06, 2017, 11:46:52 pm »
I don't like needless polymorphism, so all my enemies and items are the same class, with a few minor differences between them:
  • They each have an objectType enumeration that can be used to tell their generic type apart
  • They are added to different object lists for things such as collisions. For example, only the player can collide with and interact with items, only enemies and obstacles can collide with player bullets, etc. These lists can also be used by the code to loop through a specific type quickly.
  • Their major differences are handled via scripting, but that might be a bit too advanced for a first game. Our game currently uses Lua, but I would highly recommend ChaiScript because of its ability to directly map to your C++ data. Since the introduction of C++11, Lua has become more and more problematic to work it. Its one major draw is its ability to use coroutines, which allows for very clean scripting. However, C++ may gain coroutine capabilities as early as C++20, so soon ChaiScript may also support them.
« Last Edit: December 06, 2017, 11:50:11 pm by RealmRPGer »

lukaius

  • Guest
Re: How would i make the games logic
« Reply #5 on: December 07, 2017, 02:29:50 am »
I see that your points Realm RPGer thanks for the help