Beispiel #1
0
 def change_value(self):
     self.component.move = Vec2(self.move_spins[0].value(),
                                self.move_spins[1].value())
     self.component.rotation = self.rot_spin.value()
     self.component.active = self.active_check.isChecked()
     self.parent.parent.project.save()
     self.parent.parent.viewport.update_screen()
 def change_value(self):
     self.component.position = Vec2(*(i.value() for i in self.pos_spins))
     if self.follow_box.currentText() == "None":
         self.component.follow_entity = None
     else:
         self.component.follow_entity = self.follow_box.currentText()
     self.parent.parent.project.save()
     self.parent.parent.viewport.update_screen()
Beispiel #3
0
 def change_value(self):
     self.component.solid = self.solid_check.isChecked()
     if len(self.callback_script_edit.text()) > 0 and len(
             self.callback_func_edit.text()) > 0:
         self.component.callback = self.callback_script_edit.text(
         ) + " - " + self.callback_func_edit.text()
     else:
         self.component.callback = None
     self.component.size = Vec2(*[i.value() for i in self.size_spins])
     self.parent.parent.project.save()
     self.parent.parent.viewport.update_screen()
Beispiel #4
0
    def change_value(self, _=None, color=None, final_color=None):
        if color is None:
            self.component.color = Color.from_rgba(
                *(i.value() for i in self.color_spins))
        else:
            self.component.color = Color.from_rgba(*color)

        if final_color is None:
            self.component.final_color = Color.from_rgba(
                *(i.value() for i in self.final_color_spins))
        else:
            self.component.final_color = Color.from_rgba(*final_color)

        self.component.size = Vec2(*(i.value() for i in self.size_spins))
        self.component.final_size = Vec2(*(i.value()
                                           for i in self.final_size_spins))
        self.component.angle_range = Vec2(*(i.value()
                                            for i in self.angle_range_spins))
        self.component.force_range = Vec2(*(i.value()
                                            for i in self.force_range_spins))
        self.component.offset_min = Vec2(*(i.value()
                                           for i in self.offset_min_spins))
        self.component.offset_max = Vec2(*(i.value()
                                           for i in self.offset_max_spins))
        self.component.lifetime = self.lifetime_spin.value()
        self.component.spawn_time = self.spawn_time_spin.value()
        self.component.spawn_number = self.spawn_number_spin.value()

        self.parent.parent.project.save()
        self.parent.parent.viewport.update_screen()
 def from_dict(cls, game_object, values):
     comp = ButtonComponent(game_object)
     comp.callback = values.get("callback", None)
     comp.size = Vec2(*values.get("size", (100, 40)))
     comp.bg = Color.from_rgba(*values.get("bg", Color.from_name("GRAY").darker(5).rgba()))
     comp.text = values.get("text", "")
     comp.font_name = values.get("font_name", "arial")
     comp.font_size = values.get("font_size", 16)
     comp.font_bold = values.get("font_bold", False)
     comp.font_italic = values.get("font_italic", False)
     comp.font_underline = values.get("font_underline", False)
     comp.font_color = Color.from_rgba(*values.get("font_color", (0, 0, 0, 0)))
     comp.font_antialias = values.get("font_antialias", False)
     return comp
 def __init__(self, game_object):
     super().__init__(game_object)
     self.name = "ButtonComponent"
     self.callback = None
     self.size = Vec2(100, 40)
     self.bg = Color.from_name("GRAY").darker(5)
     self.text = ""
     self.font_name = "arial"
     self.font_size = 16
     self.font_bold = False
     self.font_italic = False
     self.font_underline = False
     self.font_color = Color.from_rgb(0, 0, 0)
     self.font_antialias = False
Beispiel #7
0
 def __init__(self, game_object):
     super().__init__(game_object)
     self.name = "ParticleComponent"
     self.color = Color.from_rgb(255, 255, 255)
     self.final_color = Color.from_rgb(255, 255, 255)
     self.size = Vec2(20, 20)
     self.final_size = Vec2(20, 20)
     self.angle_range = Vec2(0, 359)
     self.force_range = Vec2(50, 50)
     self.offset_min = Vec2(0, 0)
     self.offset_max = Vec2(0, 0)
     self.lifetime = 2
     self.spawn_time = 1
     self.spawn_number = 1
Beispiel #8
0
 def from_dict(cls, game_object, values):
     comp = ParticleComponent(game_object)
     comp.color = Color.from_rgba(
         *values.get("color", (255, 255, 255, 255)))
     comp.final_color = Color.from_rgba(
         *values.get("final_color", (255, 255, 255, 255)))
     comp.size = Vec2(*values.get("size", (20, 20)))
     comp.final_size = Vec2(*values.get("final_size", (20, 20)))
     comp.angle_range = Vec2(*values.get("angle_range", (0, 359)))
     comp.force_range = Vec2(*values.get("force_range", (50, 50)))
     comp.offset_min = Vec2(*values.get("offset_min", (0, 0)))
     comp.offset_max = Vec2(*values.get("offset_max", (0, 0)))
     comp.lifetime = values.get("lifetime", 2)
     comp.spawn_time = values.get("spawn_time", 1)
     comp.spawn_number = values.get("spawn_number", 1)
     return comp
 def change_value(self, _=None, bg=None, font_color=None):
     self.component.text = self.text_edit.text()
     if len(self.callback_script_edit.text()) > 0 and len(self.callback_func_edit.text()) > 0:
         self.component.callback = self.callback_script_edit.text() + " - " + self.callback_func_edit.text()
     else:
         self.component.callback = None
     if bg is None:
         self.component.bg = Color.from_rgba(*(i.value() for i in self.bg_spins))
     else:
         self.component.bg = Color.from_rgba(*bg)
     self.component.size = Vec2(*(i.value() for i in self.size_spins))
     self.component.font_name = self.font_name_edit.text()
     self.component.font_size = self.font_size_spin.value()
     if font_color is None:
         self.component.font_color = Color.from_rgba(*(i.value() for i in self.font_color_spins))
     else:
         self.component.font_color = Color.from_rgba(*font_color)
     self.component.font_bold = self.font_bold_check.isChecked()
     self.component.font_italic = self.font_italic_check.isChecked()
     self.component.font_underline = self.font_underline_check.isChecked()
     self.component.font_antialias = self.font_antialias_check.isChecked()
     self.parent.parent.project.save()
     self.parent.parent.viewport.update_screen()
 def __init__(self, game_object):
     super().__init__(game_object)
     self.name = "AutoComponent"
     self.move = Vec2(0, 0)
     self.rotation = 0
     self.active = True
 def from_dict(cls, game_object, values):
     comp = AutoComponent(game_object)
     comp.move = Vec2(*values.get("move", (0, 0)))
     comp.rotation = values.get("rotation", 0)
     comp.active = values.get("active", True)
     return comp
 def __init__(self, game_object):
     super().__init__(game_object)
     self.name = "TransformComponent"
     self.position = Vec2(0, 0)
     self.rotation = 0
     self.scale = Vec2(1, 1)
 def from_dict(cls, game_object, values):
     comp = CollisionComponent(game_object)
     comp.solid = values.get("solid", True)
     comp.callback = values.get("callback", None)
     comp.size = Vec2(*values.get("size", (0, 0)))
     return comp
 def __init__(self, game_object):
     super().__init__(game_object)
     self.name = "CameraComponent"
     self.position = Vec2(0, 0)
     self.follow_entity = None
 def from_dict(cls, game_object, values):
     comp = CameraComponent(game_object)
     comp.position = Vec2(*values.get("position", (0, 0)))
     comp.follow_entity = values.get("follow_entity", None)
     return comp
Beispiel #16
0
    def update_screen(self):
        screen = pygame.Surface(
            (self.parent.project.settings.get("width", 1080),
             self.parent.project.settings.get("height", 720)))
        if self.parent.scene_tree.scene is not None:
            screen.fill(
                self.parent.scene_tree.scene.get_component(
                    "ColorComponent").color.rgba())
            camera_pos = self.parent.scene_tree.scene.get_component(
                "CameraComponent").position
        else:
            screen.fill((0, 0, 0))
            camera_pos = Vec2(0, 0)

        if self.parent.scene_tree.scene is not None:
            objs = [self.parent.scene_tree.scene]
            while len(objs) > 0:
                parent = objs[0]
                del objs[0]
                for child in parent.childs:
                    transform = child.get_component("TransformComponent")
                    if transform is not None:
                        sprite = child.get_component("SpriteComponent")
                        spritesheet = child.get_component(
                            "SpriteSheetComponent")
                        text = child.get_component("TextComponent")
                        button = child.get_component("ButtonComponent")
                        anim = child.get_component("AnimComponent")
                        label = child.get_component("LabelComponent")
                        image = child.get_component("ImageComponent")
                        position = transform.global_position()
                        rotation = transform.global_rotation()
                        scale = transform.global_scale()

                        # RENDER BUTTON COMPONENT
                        if button is not None:
                            render = pygame.Surface(button.size.coords(),
                                                    pygame.SRCALPHA,
                                                    32).convert_alpha()
                            render.fill(button.bg.rgba())

                            try:
                                font = pygame.font.Font(
                                    button.font_name, button.font_size)
                            except FileNotFoundError:
                                font = pygame.font.SysFont(
                                    button.font_name, button.font_size)
                            font.set_underline(button.font_underline)
                            font.set_italic(button.font_italic)
                            font.set_bold(button.font_bold)
                            text_render = font.render(button.text,
                                                      button.font_antialias,
                                                      button.font_color.rgba())

                            x = button.size.x - render.get_rect(
                            ).width / 2 - text_render.get_rect().width / 2
                            y = button.size.y - render.get_rect(
                            ).height / 2 - text_render.get_rect().height / 2
                            render.blit(text_render, (x, y))
                            render = pygame.transform.rotate(render, rotation)
                            render = pygame.transform.scale(
                                render, [
                                    int(render.get_rect().width * scale.x),
                                    int(render.get_rect().height * scale.y)
                                ])
                            screen.blit(
                                render,
                                (position -
                                 Vec2(render.get_rect().width,
                                      render.get_rect().height) / 2).coords())

                        # RENDER SPRITE COMPONENT
                        if sprite is not None and sprite.sprite is not None:
                            path = self.parent.project.get_texture(
                                sprite.sprite).components[0].path
                            if path is not None:
                                render = pygame.image.load(
                                    path).convert_alpha()
                                render = pygame.transform.rotate(
                                    render, rotation)
                                render = pygame.transform.scale(
                                    render, [
                                        int(render.get_rect().width * scale.x),
                                        int(render.get_rect().height * scale.y)
                                    ])
                                screen.blit(
                                    render,
                                    (position -
                                     Vec2(render.get_rect().width,
                                          render.get_rect().height) / 2 -
                                     camera_pos).coords())

                        # RENDER IMAGE COMPONENT
                        if image is not None and image.sprite is not None:
                            path = self.parent.project.get_texture(
                                image.sprite).components[0].path
                            if path is not None:
                                render = pygame.image.load(
                                    path).convert_alpha()
                                render = pygame.transform.rotate(
                                    render, rotation)
                                render = pygame.transform.scale(
                                    render, [
                                        int(render.get_rect().width * scale.x),
                                        int(render.get_rect().height * scale.y)
                                    ])
                                screen.blit(render,
                                            (position -
                                             Vec2(render.get_rect().width,
                                                  render.get_rect().height) /
                                             2).coords())

                        # RENDER SPRITESHEET COMPONENT
                        if spritesheet is not None and spritesheet.sprite is not None:
                            path = self.parent.project.get_texture(
                                spritesheet.sprite).components[0].path
                            if path is not None:
                                image = pygame.image.load(path).convert_alpha()
                                x_diff = image.get_rect(
                                ).width // spritesheet.sprite_number[0]
                                y_diff = image.get_rect(
                                ).height // spritesheet.sprite_number[1]
                                indexes = (spritesheet.current_sprite %
                                           spritesheet.sprite_number[0],
                                           spritesheet.current_sprite //
                                           spritesheet.sprite_number[0])
                                render = image.subsurface(
                                    pygame.Rect(indexes[0] * x_diff,
                                                indexes[1] * y_diff, x_diff,
                                                y_diff))
                                render = pygame.transform.rotate(
                                    render, rotation)
                                render = pygame.transform.scale(
                                    render, [
                                        int(render.get_rect().width * scale.x),
                                        int(render.get_rect().height * scale.y)
                                    ])
                                screen.blit(
                                    render,
                                    (position -
                                     Vec2(render.get_rect().width,
                                          render.get_rect().height) / 2 -
                                     camera_pos).coords())

                        # RENDER LABEL COMPONENT
                        if label is not None:
                            try:
                                font = pygame.font.Font(
                                    label.font_name, label.font_size)
                            except FileNotFoundError:
                                font = pygame.font.SysFont(
                                    label.font_name, label.font_size)
                            font.set_underline(label.font_underline)
                            font.set_italic(label.font_italic)
                            font.set_bold(label.font_bold)
                            render = font.render(label.text,
                                                 label.font_antialias,
                                                 label.font_color.rgba())
                            render = pygame.transform.rotate(render, rotation)
                            render = pygame.transform.scale(
                                render, [
                                    int(render.get_rect().width * scale.x),
                                    int(render.get_rect().height * scale.y)
                                ])
                            temp = (position -
                                    Vec2(render.get_rect().width,
                                         render.get_rect().height) / 2)
                            if not label.background_transparent:
                                screen.fill(
                                    label.background_color.rgba(),
                                    render.get_rect(x=temp.x, y=temp.y))
                            screen.blit(render, temp.coords())

                        # RENDER TEXT COMPONENT
                        if text is not None:
                            try:
                                font = pygame.font.Font(
                                    text.font_name, text.font_size)
                            except FileNotFoundError:
                                font = pygame.font.SysFont(
                                    text.font_name, text.font_size)
                            font.set_underline(text.font_underline)
                            font.set_italic(text.font_italic)
                            font.set_bold(text.font_bold)
                            render = font.render(text.text,
                                                 text.font_antialias,
                                                 text.font_color.rgba())
                            render = pygame.transform.rotate(render, rotation)
                            render = pygame.transform.scale(
                                render, [
                                    int(render.get_rect().width * scale.x),
                                    int(render.get_rect().height * scale.y)
                                ])
                            temp = (position -
                                    Vec2(render.get_rect().width,
                                         render.get_rect().height) / 2 -
                                    camera_pos)
                            if not text.background_transparent:
                                screen.fill(
                                    text.background_color.rgba(),
                                    render.get_rect(x=temp.x, y=temp.y))
                            screen.blit(render, temp.coords())

                        # RENDER ANIM COMPONENT
                        if anim is not None:
                            if anim.playing != "":
                                for i in anim.anims:
                                    if i.name == anim.playing:
                                        if i.type_ == "Sprite":
                                            path = self.parent.project.get_texture(
                                                i.sprites[0]
                                            ).components[0].path
                                            if path is not None:
                                                render = pygame.image.load(
                                                    path).convert_alpha()
                                                render = pygame.transform.rotate(
                                                    render, rotation)
                                                render = pygame.transform.scale(
                                                    render, [
                                                        int(render.get_rect().
                                                            width * scale.x),
                                                        int(render.get_rect().
                                                            height * scale.y)
                                                    ])
                                                screen.blit(
                                                    render,
                                                    (position - Vec2(
                                                        render.get_rect().width,
                                                        render.get_rect().
                                                        height) / 2 -
                                                     camera_pos).coords())
                                        elif i.type_ == "Sheet":
                                            path = self.parent.project.get_texture(
                                                i.sprite_sheet
                                            ).components[0].path
                                            if path is not None:
                                                image = pygame.image.load(
                                                    path).convert_alpha()
                                                x_diff = image.get_rect(
                                                ).width // i.sprite_number[0]
                                                y_diff = image.get_rect(
                                                ).height // i.sprite_number[1]
                                                render = image.subsurface(
                                                    pygame.Rect(
                                                        0, 0, x_diff, y_diff))
                                                render = pygame.transform.rotate(
                                                    render, rotation)
                                                render = pygame.transform.scale(
                                                    render, [
                                                        int(render.get_rect().
                                                            width * scale.x),
                                                        int(render.get_rect().
                                                            height * scale.y)
                                                    ])
                                                screen.blit(
                                                    render,
                                                    (position - Vec2(
                                                        render.get_rect().width,
                                                        render.get_rect().
                                                        height) / 2 -
                                                     camera_pos).coords())
                                        break
                    objs.append(child)

        w = screen.get_width()
        h = screen.get_height()

        data = screen.get_buffer().raw
        self.image = QImage(data, w, h, QImage.Format_RGB32)
        self.update()
 def __init__(self, game_object):
     super().__init__(game_object)
     self.name = "CollisionComponent"
     self.solid = True
     self.callback = None
     self.size = Vec2.zero()
 def from_dict(cls, game_object, values):
     comp = TransformComponent(game_object)
     comp.position = Vec2(*values.get("position", (0, 0)))
     comp.rotation = values.get("rotation", 0)
     comp.scale = Vec2(*values.get("scale", (1, 1)))
     return comp
Beispiel #19
0
 def change_value(self):
     self.component.position = Vec2(*(i.value() for i in self.pos_spins))
     self.component.rotation = self.rot_spin.value()
     self.component.scale = Vec2(*(i.value() for i in self.scale_spins))
     self.parent.parent.project.save()
     self.parent.parent.viewport.update_screen()