开发者

getting classes to interact in game engine

I need to get classes to interact within the game engine. I have saved all the classes to different .py files and am simply going to import them into my game engine file and run them through the game engine. Issue is I need to set up the game engine, to initiate the game, and then the classes should be able to call one another once the game has initiated. I am thinking something like this below:

import class1.py
import class2.py

class Engine(Object):

  def__init__(self, start)
    self.start = start

  def play(self):
    next = self.start

    while True:
        print "\n-"
        class = getattr(self.start, next)
        next = class()

my_engine = Engine(class1)

my_engine.play()

Then as the game goes on I will have class1 call class 2 and so on...

This seems far too simplistic though.

Any dir开发者_StackOverflow社区ection on this would much appreciated.


Game engine is generally composed of systems, which take care of a single function of the engine. Examples include Physics, Rendering, Collision, Input, etc. You can implement a system-based architecture, which will handle indivisual components.

Even the ECS (Entity Component System) architecture serves good. Entities are nothing more than empty classes, and you gotta add components, which are nothing more than behavioural elements which govern how an entity should perform.

At the end, I suggest you create classes for systems and components, and derive them appropriately. Here is a useful link: ECS in Games

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜