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

Author Topic: Question related to game in "SFML game development" book  (Read 5202 times)

0 Members and 2 Guests are viewing this topic.

fakepotato

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Question related to game in "SFML game development" book
« on: April 27, 2015, 07:16:35 pm »
I had some troubles in my game-architecture. The question was - how to make Enemy objects, Bullet objects and Player object interact one with another without implementing tons of singletones?
I decided to look up for decision of this problem in SFML development book. I read 7 chapters of this book, paid attention to every line of it, but i still can't find solution: how to make enemies objects know where player is located to move forward to it? Cuz i was a bit disappointed, when i realized that flights in that example game were moving just by patterns and made an illusion of AI.
Should i make methods like
void Enemy::move(Player& player, float dt);
? I mean, using references to other classes. Doesn't it ruin OO-style?
Or should I just use those singletones?
Sorry for such questions, but game-architecture brings lots of troubles for people without experience in it  :-\
Infinite insomnia.

blojayble

  • Newbie
  • *
  • Posts: 19
  • whoa
    • View Profile
Re: Question related to game in "SFML game development" book
« Reply #1 on: April 27, 2015, 07:25:38 pm »
http://gameprogrammingpatterns.com/

This webpage is very helpful, give it a read.
0 bottles of beer on the wall,
0 bottles of beer!
Take one down, pass it around,
4,294,967,295 bottles of beer on the wall!

fakepotato

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Infinite insomnia.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Question related to game in "SFML game development" book
« Reply #3 on: April 27, 2015, 07:34:27 pm »
I read 7 chapters of this book, paid attention to every line of it, but i still can't find solution: how to make enemies objects know where player is located to move forward to it?
You have looked for the wrong things. We have implemented interaction between a variety of entity combinations for collisions, and between guided missiles and enemies for targeting. It should be possible to extend that to enemies vs player.

Should i make methods like
void Enemy::move(Player& player, float dt);
? I mean, using references to other classes. Doesn't it ruin OO-style?
That's one option, then you would implement the AI logic directly in the Enemy class. I don't know what this "OO style" is, seems like a myth to me. Possibly spread by Java developers ;)

Alternatively, for better separation of concerns, a third instance -- an AI controller -- is responsible of that task. It knows about the player and gives instructions to the enemies. The enemies provide an interface to accept such instructions, but they don't decide on their own.

Or should I just use those singletones?
No, avoid singletons and global variables. See also some of my tips here.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

fakepotato

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: Question related to game in "SFML game development" book
« Reply #4 on: April 27, 2015, 07:39:25 pm »
That's one option, then you would implement the AI logic directly in the Enemy class. I don't know what this "OO style" is, seems like a myth to me. Possibly spread by Java developers ;)
Hhmm, that sounds nice!
You mean, my AI manager will poke to getters/setters/move's of both player and enemies objects and making a bridge between them? I think it's best decision for my problem :D
Infinite insomnia.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Question related to game in "SFML game development" book
« Reply #5 on: April 27, 2015, 07:39:57 pm »
If you're referring to the other part which you haven't quoted: yes, exactly. The AI controller can iterate through all AI-supported enemies in its update function.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

fakepotato

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: Question related to game in "SFML game development" book
« Reply #6 on: April 27, 2015, 07:41:34 pm »
Thanks for answer! Should I implement something like that for bullets?
Infinite insomnia.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Question related to game in "SFML game development" book
« Reply #7 on: April 27, 2015, 07:45:27 pm »
It's your game, so you have to decide by yourself :D

As mentioned above, we have implemented interactions in two other ways (collision detection/response and command system), so you could use them as additional inspiration. Just experiment a bit, you'll find out what works and what doesn't ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

fakepotato

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: Question related to game in "SFML game development" book
« Reply #8 on: April 27, 2015, 07:57:48 pm »
Thanks for advice and tips again  :) Gonna avoid using singletones, except one with audiosystem - it's really very handy.
At least i avoided using more than one .
Infinite insomnia.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Question related to game in "SFML game development" book
« Reply #9 on: April 27, 2015, 08:01:22 pm »
Gonna avoid using singletones, except one with audiosystem - it's really very handy.
At least i avoided using more than one .
That's like saying "I quit drinking, except for a bottle of Whiskey a day -- at least I avoided drinking more than one" :P

It may be handy, but with a good design it's not necessary. There's almost nothing (aside from logging maybe) that just needs to be everywhere.

I'm not saying you have to refactor everything, but I'd keep it in mind for the future -- sometimes you can solve several problems at once when reducing such dependencies.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

fakepotato

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: Question related to game in "SFML game development" book
« Reply #10 on: April 27, 2015, 08:04:26 pm »
Quote
That's like saying "I quit drinking, except for a bottle of Whiskey a day -- at least I avoided drinking more than one"
That was so predictable reply  ;D
Infinite insomnia.

 

anything