Beispiel #1
0
 def update(self, *args):
     if self._start + self.life_time * 1000 < InputManager.get_ticks():
         # POSSIBLE MEMORY LEAK ????????
         SceneManager.current_scene.remove_object(self.game_object)
     else:
         move = self.direction * self.speed * InputManager.get_delta_tick(
         ) / 1000
         self.game_object.transform.move(move.x, move.y)
Beispiel #2
0
 def __init__(self, direction, speed, life_time, game_object):
     super().__init__(game_object)
     self.life_time = life_time
     self.direction = direction
     self.speed = speed
     # self._start = time()
     self._start = InputManager.get_ticks()
Beispiel #3
0
    def update(self, *args):
        command = self.current_command.split()
        if command[0] == 'move_to':
            move = Vector2(
                int(command[1]) - self.game_object.transform.x,
                int(command[2]) - self.game_object.transform.y)

            if move.length() > self.speed * (InputManager.get_delta_tick() /
                                             1000):
                move = move.normalize() * self.speed * (
                    InputManager.get_delta_tick() / 1000)
            else:
                self.current_command = next(self.commands)

            self.game_object.transform.move(move.x, move.y)

            phys_collider = self.game_object.get_component(PhysicsCollider)
            for obj in SceneManager.current_scene.objects:
                if phys_collider is not None:
                    phys_collider.update()
                    if obj != self.game_object and obj.has_component(
                            PhysicsCollider):
                        collision = phys_collider.detect_collision(
                            obj.get_component(PhysicsCollider))
                        if collision:
                            self.game_object.transform.move(-move.x, -move.y)
                            move = Vector2()

            self.change_animation(move)
            self._prev_move = move

        elif command[0] == 'sleep':
            if self._start_sleep is None:
                self._start_sleep = time()
            if time() - self._start_sleep >= float(command[1]):
                self.current_command = next(self.commands)
                self._start_sleep = None
            self.change_animation(Vector2())
            self._prev_move = Vector2()

        elif command[0] == 'del_self':
            SceneManager.current_scene.remove_object(self.game_object)
Beispiel #4
0
    def update(self, *args):
        for event in InputManager.get_events():
            if event.type == pygame.KEYDOWN:
                if event.key not in list(InputManager.AXES['Horizontal']) + list(InputManager.AXES['Vertical']) or \
                        event.key == SaveManager.get_entry('preferences', self.name):

                    direction = 'Horizontal' if self.name in (
                        'left', 'right') else 'Vertical'

                    axis = InputManager.AXES[direction]
                    axis[event.key] = axis.pop(
                        SaveManager.get_entry('preferences', self.name))
                    InputManager.set_axis(direction, axis)

                    SaveManager.set_entry('preferences', self.name, event.key)
                    self.button.text = 'Move {}: {}'.format(
                        self.name,
                        pygame.key.name(
                            SaveManager.get_entry('preferences', self.name)))
                    SceneManager.current_scene.remove_object(self.game_object)
Beispiel #5
0
 def update(self, *args):
     fps = InputManager.get_fps()
     if fps != 0:
         for _ in range(self.particles_per_second // fps + 1):
             go = GameObject(*self.game_object.transform.coord)
             go.add_component(ImageFile(self.path, go))
             go.add_component(
                 Particle((
                     self.correction +
                     Vector2(random.random(), random.random())).normalize(),
                          self.speed, self.life_time, go))
             SceneManager.current_scene.add_object(go)
Beispiel #6
0
    def update(self, *args):
        move = Vector2(
            InputManager.get_axis('Horizontal') * self.speed,
            InputManager.get_axis('Vertical') *
            self.speed) * (InputManager.get_delta_tick() / 1000)
        self.game_object.transform.move(move.x, move.y)

        phys_collider = self.game_object.get_component(PhysicsCollider)

        for obj in SceneManager.current_scene.objects:
            if phys_collider is not None:
                phys_collider.update()
                if obj != self.game_object and obj.has_component(
                        PhysicsCollider):
                    collision = phys_collider.detect_collision(
                        obj.get_component(PhysicsCollider))
                    if collision:
                        self.game_object.transform.move(-move.x, -move.y)
                        move = Vector2()

        self.set_camera_pos()
        self.change_animation(move)
        self.play_sound(move)
        self._prev_move = move
Beispiel #7
0
 def update(self, *args):
     container = self.game_object.get_component(ChatContainer)
     for msg in self.client.received.readlines():
         container.add(': '.join(self.parse(msg)))
     for event in InputManager.get_events():
         if event.type == pygame.KEYDOWN:
             if event.key == pygame.K_RETURN:
                 if not self.on_screen:
                     GUI.add_element(
                         TextBox((Config.get_width() // 8 + 10,
                                  Config.get_height() - 40,
                                  Config.get_width() // 4, 40),
                                 '',
                                 callback=self.client.send,
                                 name='message_textbox'))
                     self.on_screen = True
             elif event.key == pygame.K_ESCAPE:
                 if self.on_screen:
                     GUI.del_element('message_textbox')
                     self.on_screen = False
Beispiel #8
0
                              [width, Config.get_height()])

    @staticmethod
    def set_height(height):
        SaveManager.set_entry('config', 'resolution',
                              [Config.get_width(), height])

    @staticmethod
    def get_width():
        return SaveManager.get_entry('config', 'resolution')[0]

    @staticmethod
    def get_height():
        return SaveManager.get_entry('config', 'resolution')[1]

    @staticmethod
    def set_fullscreen(value):
        SaveManager.set_entry('config', 'fullscreen', value)
        pygame.display.set_mode(SaveManager.get_entry('config', 'resolution'),
                                Config.get_flags())
        return value

    @staticmethod
    def set_icon(path):
        SaveManager.set_entry('config', 'icon', path)
        pygame.display.set_icon(pygame.image.load(path).convert_alpha())


InputManager.set_max_fps(SaveManager.get_entry('config', 'fps'))
Config.init()
Beispiel #9
0
from engine.input_manager import InputManager
from engine.save_manager import SaveManager
from engine.gui import GUI

from user_components import NetworkingController, ChatController
from scene_loader import load_scene
from guis import MainMenuGUI

SaveManager.load_profile('preferences', 'user_prefs.json')
Config.set_resolution(*SaveManager.get_entry('preferences', 'resolution'))
Config.set_fullscreen(SaveManager.get_entry('preferences', 'fullscreen'))

GUI.set_cursor(SaveManager.get_entry('config', 'cursor'))

InputManager.set_axis('Horizontal', {
    SaveManager.get_entry('preferences', 'right'): 1,
    SaveManager.get_entry('preferences', 'left'): -1,
})

InputManager.set_axis('Vertical', {
    SaveManager.get_entry('preferences', 'up'): 1,
    SaveManager.get_entry('preferences', 'down'): -1,
})

load_scene('scenes/main_menu.json')
MainMenuGUI.init()

while True:
    InputManager.update()

    for event in InputManager.get_events():
        if event.type == pygame.QUIT: