0
\$\begingroup\$

I have a very simple little game that consists of a player, zombies, food, and treasure. It's all automated. The player will walk towards a zombie and shoot within a certain distance, which costs energy. If the player goes below a certain energy level, it will find the closest food item and walk towards that and once the player has reached it, the player will gain energy, and continue to move towards zombies and shoot them, until all are dead and the player will movie towards the zombie.

This is meant to be a way of learning object oriented programming for a class, so standard functional concepts such as ECS do not apply (and its so simple that would be overkill). Currently I have an array of GameObjects that all other objects such as player, zombie etc inherit from that gives them a position and an image to render (I'm aware an object shouldn't be responsible for its own rendering). All GameObjects are put into this array so I can interate through it and rendering everything which works fine. But not every entity requires an update, so I made an updatable interface, allowing classes that require updating to implement. So now i'm in a situation where there are two lists, renderable game objects, and updatable game objects. My problem arises when the player must operate on a specific subset of entities at a time. e.g. find all the zombies or all the food items to determine which is the closest. So would it be better then, to have arrays of zombies, and arrays of food items instead that I can pass to the player to operate on? And since only 2-3 game objects will need to actually be updated, should I just not bother putting them into a list to be updated and just keep a list of all renderables, with seperate lists for all zombies and food items etc?

Any thoughts on how this could be best designed would be appreciated.

\$\endgroup\$
2
  • \$\begingroup\$ This is a performance question, it cannot be answered without actually measuring the performance, but the answer will become obvious once you measure. \$\endgroup\$ May 1, 2021 at 12:05
  • \$\begingroup\$ It sounds to me like you already have a way of implementing this that makes sense to you and could plausibly benefit your game. What happens when you try implementing it this way? Does it have the benefits you wanted, or do you encounter a problem somewhere that we can help you solve? \$\endgroup\$
    – DMGregory
    May 1, 2021 at 12:13

0

You must log in to answer this question.

Browse other questions tagged .