Esempio n. 1
0
    def __init__(self, name, entities_data):
        self.name = name
        self.entities = []
        self.started_entities = []
        self.event_input = None
        self.cont_input = None

        for entity_data in entities_data:
            position = (entity_data["X"], entity_data["Y"])

            entity = Entity(entity_data["Name"], position)
            for component_data in entity_data["Components"]:
                try:
                    component_constructor = getattr(controller.component, component_data["Type"])
                    component = component_constructor()
                    component.scene = self

                    data = component_data["ComponentData"]
                    if not len(data) == 0:
                        component.load_data(data)

                    entity.add_component(component)
                except AttributeError:
                    debug.log(component_data["Type"] + " not recognised :/")

            self.entities.append(entity)
Esempio n. 2
0
 def run(self):
     if self.scene is None:
         debug.log('scene not set!')
         return
     self.scene.start()
     self.tick_method = self.tick
     super().run()
Esempio n. 3
0
    def __init__(self, name, entities_data):
        self.name = name
        self.entities = []
        self.started_entities = []
        self.event_input = None
        self.cont_input = None

        for entity_data in entities_data:
            position = (entity_data["X"], entity_data["Y"])

            entity = Entity(entity_data["Name"], position)
            for component_data in entity_data["Components"]:
                try:
                    component_constructor = getattr(controller.component,
                                                    component_data["Type"])
                    component = component_constructor()
                    component.scene = self

                    data = component_data["ComponentData"]
                    if not len(data) == 0:
                        component.load_data(data)

                    entity.add_component(component)
                except AttributeError:
                    debug.log(component_data["Type"] + " not recognised :/")

            self.entities.append(entity)
Esempio n. 4
0
 def invoke(self):
     try:
         getattr(sys.modules[__name__], self.action)()
     except AttributeError as error:
         debug.log('Something went wrong :(')
         debug.log(error.args)
         raise error
Esempio n. 5
0
 def target_reached(self):
     own_pixel_pos = self.entity.x, self.entity.y
     target_pixel_pos = helpers.multiply_vector(self.target_pos,
                                                configuration.tile_size)
     result = helpers.vector_equality(own_pixel_pos, target_pixel_pos)
     debug.log('[{0}]-[{1}]: {2}'.format(own_pixel_pos, target_pixel_pos,
                                         result))
     return result
Esempio n. 6
0
 def run(self):
     if self.tick_method is None:
         debug.log('no assigned tick method')
         return
     self.setup()
     self.total_frames = 0
     debug.log('starting main loop execution')
     while True:
         self.tick_method()
         self.clock.tick(configuration.clock_tick)
         pygame.display.flip()
         self.total_frames += 1
    def set_target(self, direction):
        """
        sets target to neighbouring tile specified by direction
        :param direction: target direction
        :return:
        """
        debug.log(direction)
        self.entity.direction = direction

        direction_vector = helpers.direction_to_direction_vector(direction)
        next_tile_pos = helpers.add_vectors(self.position, direction_vector)

        if not self.tile_map_component.in_bounds(next_tile_pos):
            debug.log('can\'t go that way!')
            return

        next_tile_type = self.tile_map_component.get_tile_type(next_tile_pos)
        if next_tile_type == 'collision':
            return

        if not helpers.vector_equality(next_tile_pos, self.position):
            self.target_pos = next_tile_pos
Esempio n. 8
0
    def set_target(self, direction):
        """
        sets target to neighbouring tile specified by direction
        :param direction: target direction
        :return:
        """
        debug.log(direction)
        self.entity.direction = direction

        direction_vector = helpers.direction_to_direction_vector(direction)
        next_tile_pos = helpers.add_vectors(self.position, direction_vector)

        if not self.tile_map_component.in_bounds(next_tile_pos):
            debug.log('can\'t go that way!')
            return

        next_tile_type = self.tile_map_component.get_tile_type(next_tile_pos)
        if next_tile_type == 'collision':
            return

        if not helpers.vector_equality(next_tile_pos, self.position):
            self.target_pos = next_tile_pos
Esempio n. 9
0
    def tick(self):
        pygame.event.pump()
        self.gui.draw()
        self.overlay.draw()

        mouse_input = input.tick('mouse')

        if mouse_input[0] != self.last_tick_mouse:

            mouse_changed = mouse_input[0] != 'none'
            self.overlay.draw_mouse = mouse_changed

            if mouse_changed:
                debug.log('mouse button down')
                debug.log(mouse_input[0] + ' ' + str(mouse_input[1]))
            else:
                debug.log('mouse button up')

        self.last_tick_mouse = mouse_input[0]
Esempio n. 10
0
 def target_reached(self):
     own_pixel_pos = self.entity.x, self.entity.y
     target_pixel_pos = helpers.multiply_vector(self.target_pos, configuration.tile_size)
     result = helpers.vector_equality(own_pixel_pos, target_pixel_pos)
     debug.log('[{0}]-[{1}]: {2}'.format(own_pixel_pos, target_pixel_pos, result))
     return result
Esempio n. 11
0
    def start(self):
        self.event_input = 'none'
        self.cont_input = 'none'

        while not self.ready_to_start():
            debug.log('preparing to start entities...')
            entities_to_start = []
            for ent in self.entities:
                if not ent.is_started():
                    entities_to_start.append(ent)
            debug.log(str(len(entities_to_start)) + ' entities ready to start.')

            debug.log('starting...')
            for entity in entities_to_start:
                try:
                    entity.start()
                except Exception as e:
                    debug.log('could not start entity. Logging error:')
                    debug.log(e)

        debug.log('started {0} entities :)'.format(len(self.entities)))
Esempio n. 12
0
    def start(self):
        self.event_input = 'none'
        self.cont_input = 'none'

        while not self.ready_to_start():
            debug.log('preparing to start entities...')
            entities_to_start = []
            for ent in self.entities:
                if not ent.is_started():
                    entities_to_start.append(ent)
            debug.log(
                str(len(entities_to_start)) + ' entities ready to start.')

            debug.log('starting...')
            for entity in entities_to_start:
                try:
                    entity.start()
                except Exception as e:
                    debug.log('could not start entity. Logging error:')
                    debug.log(e)

        debug.log('started {0} entities :)'.format(len(self.entities)))
Esempio n. 13
0
import argparse

from core import menu
from util import debug

parser = argparse.ArgumentParser(description='Pythonmon game engine')
parser.add_argument('-l', action='store_true', help='enable logging')
args = parser.parse_args()

# set logging state
debug.enabled = args.l

debug.log('Program started')

start_menu = menu.make_console_menu('start-menu')

start_menu.run()