Esempio n. 1
0
    def __init__(self, controller, difficulty):
        super().__init__(controller)
        self.clock = 900000
        self.clock_text = Text(self.get_clock_str(), self._font, (20, 20, 20))
        self.clock_text.rect.center = (400, 50)
        if difficulty == "Easy":
            self.tile_count = (10, 10)
            self.tile_offset = (220, 150)
        elif difficulty == "Medium":
            self.tile_count = (14, 14)
            self.tile_offset = (150, 100)
        elif difficulty == "Hard":
            self.tile_count = (20, 14)
            self.tile_offset = (40, 100)
        self.unrevealed = self.tile_count[0] * self.tile_count[1]
        back_rect = pygame.Rect(self.tile_offset,
                                (self.tile_count[0] * Tile.TILE_SIZE[0] + 1,
                                 self.tile_count[1] * Tile.TILE_SIZE[1] + 1))
        self.backdrop = GameObject(self.game_objects, back_rect)
        self.mine_count = self.unrevealed // 8
        self.original_mine_count = self.mine_count
        self.unmarked = Text("x" + str(self.mine_count), self._small_font)
        self.unmarked.rect.center = (600, 50)

        mine_icon = pygame.image.load(os.path.join('spritesheet', f'mine.png'))
        mine_icon = pygame_utils.aspect_scale(mine_icon, (25, 25))
        mine_icon = GameObject(self.game_objects, mine_icon.get_rect(),
                               mine_icon)
        mine_icon.rect.center = (550, 50)
        self.tiles = self.make_tiles()
        self.place_tiles()
        self.game_objects.add(self.backdrop, *self.tiles, self.clock_text,
                              self.unmarked, mine_icon)
        self.win_sound = pygame.mixer.Sound("sounds/ta da.wav")
        self.lose_sound = pygame.mixer.Sound("sounds/bomb.wav")
    def __assign_transform(self, element: ET.Element, go: GameObject):
        (x, y, center) = self.__parse_transform(element.find('transform'))
        if center:
            go.center = Vector2(x, y)
        else:
            go.transform = Vector2(x, y)

        go.move(self._global_offset)
Esempio n. 3
0
 def __init__(self, x, y):
     GameObject.__init__(self, x, y, 0, 0,
                         visible=False)
     self._visible_time = c.frame_rate * 2
     self._visible_timing = self._visible_time
     self._text = ''
     self._text_object = TextObject(self.centerx, self.centery, lambda: self._text,
                                    colors.YELLOW1, c.font_name, c.font_size, back_color=colors.BLACK)
Esempio n. 4
0
def create_test_scene(screen: Surface) -> Scene:
    background: Surface = Surface((3000, 3000))
    background.fill((250, 250, 250))

    red_box_s: Surface = Surface((300, 50))
    red_box_s.fill((255, 0, 0))

    red_box: GameObject = GameObject(red_box_s)
    red_box.move(Vector2(50, 250))

    orange_box_s: Surface = Surface((300, 50))
    orange_box_s.fill((255, 100, 0))

    orange_box: GameObject = GameObject(orange_box_s)
    orange_box.move(Vector2(400, 350))

    floor_s: Surface = Surface((1080, 50))
    floor_s.fill((0, 0, 0))
    floor: GameObject = GameObject(floor_s)
    floor.move(Vector2(0, 600))

    button: ButtonGameObject = ButtonGameObject()
    button.move(Vector2(500, 580))

    wall_left_s: Surface = Surface((50, 100))
    wall_left_s.fill((0, 0, 0))
    wall_left: GameObject = GameObject(wall_left_s)
    wall_left.move(Vector2(0, 500))

    wall_right_s: Surface = Surface((50, 100))
    wall_right_s.fill((0, 0, 0))
    wall_right: GameObject = GameObject(wall_left_s)
    wall_right.move(Vector2(1000, 500))

    wind_stream: WindGameObject = WindGameObject((200, 200), Vector2(1, 0), 20)
    wind_stream.move(Vector2(950, 200))

    player = Player()
    player.move(Vector2(100, 200))

    enemy = HthEnemy()
    enemy.move(Vector2(900, 500))

    enemy2 = RangedEnemy()
    enemy2.move(Vector2(600, 500))

    ui_comps = get_ui(player)

    scene: Scene = Scene(background,
                         [red_box, orange_box, floor, wall_left, wall_right],
                         [player, enemy, enemy2, button, wind_stream],
                         ui_comps)

    scene.environment.add(red_box, orange_box, floor, wall_left, wall_right)

    return scene
Esempio n. 5
0
    def __init__(self, surface: Surface, position: (int, int)):
        GameObject.__init__(self, surface)
        # Save sprite
        self._original_image = surface
        self._disabled_image = surface.copy()
        self._disabled_image.fill((255, 255, 255, 128), None,
                                  pygame.BLEND_RGBA_MULT)

        self.move(Vector2(position[0], position[1]))
        self._player: Player = None
Esempio n. 6
0
    def _on_collide(self, other: GameObject, direction_of_impact: Vector2,
                    impact_side: ImpactSide, delta_time: float):
        if other != self._target:
            Enemy._on_collide(self, other, direction_of_impact, impact_side,
                              delta_time)
        else:
            # Collided with player, he need to suffer
            other: LivingEntity
            other.take_damage(EnemySettings.HandToHand.DAMAGE)
            if other.is_dead:
                self._target = None

            self.__backoff(direction_of_impact)
Esempio n. 7
0
    def __init__(self, at_bottom):
        self._at_bottom = at_bottom
        if self._at_bottom:
            y = c.screen_height - 2 * c.hand_offset_y - c.card_h
        else:
            y = 0
        GameObject.__init__(self, 0, y, c.hand_w, c.hand_h)
        EventsHandler.__init__(self)
        self._cards = []
        self._settle()

        self._up_card = None

        # Карта, готовая отправиться на стол.
        self._table_card = None
Esempio n. 8
0
 def __init__(self, exit_func):
     GameObject.__init__(
         self, c.hand_offset_x, 2 * c.hand_offset_y + c.hand_h, c.hand_w,
         c.screen_height - 4 * c.hand_offset_y - 2 * c.hand_h)
     self._subscribers = []
     self._beaten = Beaten()
     self._deck = Deck()
     self._trump = random.choice(c.suits)
     bottom_player_pool = []
     top_player_pool = []
     self._players_pools = [bottom_player_pool, top_player_pool]
     self._alarm = Alarm(self.centerx, self.centery - c.font_size // 2)
     self._beat = False
     self._beat_in = 0
     self._exit_func = exit_func
Esempio n. 9
0
    def __init__(self,
                 x,
                 y,
                 w,
                 h,
                 text,
                 on_click=lambda x: None,
                 padding=0,
                 active=True):
        GameObject.__init__(self, x, y, w, h)
        EventsHandler.__init__(self, active)

        self._state = 'normal'
        self._on_click = on_click
        self._text = TextObject(x + padding, y + padding, lambda: text,
                                c.button_text_color, c.font_name, c.font_size)
    def __parse_player(self, scene: Scene, element: ET.Element) -> Player:
        player = GameObject(Surface((0, 0)))
        scene.player.add(player)
        self.__assign_transform(element, player)
        self.__assign_collision_masks(scene, player,
                                      self.__parse_collision_mask(element))

        return player
Esempio n. 11
0
    def __init__(self, controller, last_frame, win=False):
        super().__init__(controller)
        last_frame = GameObject(self.game_objects, last_frame.get_rect(),
                                last_frame)
        self.background.blit(last_frame)
        background_color = (240, 240, 240)
        padding = (5, 5, 5, 5)
        if win:
            title_str = "Congratulations!"
            title_color = (
                40,
                255,
                40,
            )
        else:
            title_str = "GAME OVER"
            title_color = (255, 40, 40)

        title = Text(title_str,
                     self._font,
                     title_color,
                     border=3,
                     background_color=background_color,
                     padding=padding)

        sub_str = "press ESC to quit"
        sub_str2 = "press any other key to try again..."

        sub1 = Text(sub_str,
                    self._small_font, (20, 20, 20),
                    border=3,
                    background_color=background_color,
                    padding=padding)
        sub2 = Text(sub_str2,
                    self._small_font, (20, 20, 20),
                    border=3,
                    background_color=background_color,
                    padding=padding)

        title.rect.center = (400, 200)
        sub1.rect.center = (400, 400)
        sub2.rect.center = (400, 500)
        self.title = title
        self.game_objects.add(title, sub1, sub2)
Esempio n. 12
0
    def __init__(self, controller):
        super().__init__(controller)
        title_str = "py-sweeper"
        sub_str = "press any key to continue..."
        title_text = self._font.render(title_str, True, (255, 255, 255))
        title_text = pygame_utils.pad(title_text, (0, 100), (255, 100, 100))
        title_text_rect = title_text.get_rect()
        title_text_rect.center = (400, 200)

        sub_text = self._small_font.render(sub_str, True, (20, 20, 20))
        sub_text_rect = sub_text.get_rect()
        sub_text_rect.center = (400, 400)

        mine = Tile("mine", revealed=True)
        mine.rect.center = (400, 300)

        title = GameObject(self.game_objects, title_text_rect, title_text)
        sub = GameObject(self.game_objects, sub_text_rect, sub_text)
        self.game_objects.add(title, sub, mine)
Esempio n. 13
0
    def __init__(self, x, y, suit, nominal):
        GameObject.__init__(self, x, y, c.card_w, c.card_h)
        EventsHandler.__init__(self)

        self._hidden = True
        self._below = True
        self._moved = False
        self._state = 'normal'
        self._dest_point = (self.left, self.top)
        self._cur_point = (self.left, self.top)
        self._suit = suit
        self._nominal = nominal

        image_path = 'source/images/cards/' + self._suit + '/' + self._nominal + '.png'
        image = pygame.image.load(image_path)
        self._image = pygame.transform.smoothscale(image, (c.card_w, c.card_h))
        self._flop = pygame.transform.smoothscale(c.flop, (c.card_w, c.card_h))
        self._hover_bounds = pygame.transform.smoothscale(
            c.hover_bounds, (c.card_w, c.card_h))
Esempio n. 14
0
    def __init__(self):
        GameObject.__init__(self, c.screen_width - c.card_w - 5,
                            c.screen_height // 2 - c.card_h // 2, c.card_w,
                            c.card_h)
        self._image = pygame.transform.smoothscale(c.flop,
                                                   (self.width, self.height))
        self._cards = []
        self._fill_deck()
        self._shuffle()
        self._trump_card = self._cards[0]
        self._trump_card.turn_90()
        self._trump_card.show()

        def size_text_func():
            return str(self.size)

        self._size_text = TextObject(self.left + 12, self.top + 5,
                                     size_text_func, colors.YELLOW1,
                                     c.font_name, c.font_size, colors.BLACK)
Esempio n. 15
0
    def __init__(self,
                 area: Rect,
                 color: Color,
                 background_color: Color = TRANSPARENT,
                 maximum: float = 1,
                 value: float = 0,
                 reverse=False):
        surface: Surface = Surface((area.width, area.height), flags=SRCALPHA)
        surface.fill(color)
        GameObject.__init__(self, surface)
        self._area = area
        self._color: Color = color
        self._background_color: Color = background_color
        self._max: float = maximum
        self._reverse = reverse
        self.__percent: float
        self.__dirty: bool = True
        self.value = value

        self.move(Vector2(area.x, area.y))
    def use(self, player: GameObject):
        if self.level > 0:
            if self._next_usage <= time.time(
            ) and player.mana > self.mana_cost:
                player.mana -= self.mana_cost
                tornado_projectile: TornadoProjectile = TornadoProjectile(
                    self.level, player)

                scene: Scene = SceneManagement.active_scene
                tornado_projectile.move(
                    Vector2(player.center.x - tornado_projectile.width / 2,
                            player.transform.y))
                tornado_projectile.add_to_collision_mask(scene.enemies)

                scene.projectiles.add(tornado_projectile)
                scene.dynamics.add(tornado_projectile)

                player.apply_force(
                    Vector2(0, PlayerSettings.Ability.TornadoJump.STRENGTH))
                self._next_usage = time.time() + self.cooldown
Esempio n. 17
0
    def __init__(self, text='YOU DIED', subtext='VONOROF\'S VILLAGE HAVE BEEN WIPED'):
        death_screen_background_surface = Surface((1024, 768), flags=SRCALPHA)
        death_screen_background_surface.fill((100, 100, 100, 200))

        font = pyfont.Font(GlobalSettings.FONT, 33)
        text_surface: Surface = DeathScreen.render_font(font, text)
        death_screen_background_surface.blit(text_surface,
                                             InformationBanner.title_text_placer(death_screen_background_surface,
                                                                                 text_surface))

        font = pyfont.Font(GlobalSettings.FONT, 19)
        text_surface: Surface = DeathScreen.render_font(font, subtext)
        death_screen_background_surface.blit(
            text_surface,
            InformationBanner.content_text_placer(
                death_screen_background_surface,
                text_surface
            )
        )

        GameObject.__init__(self, death_screen_background_surface)

        self.__reset_time = time.time() + 5
Esempio n. 18
0
    def __init__(self, controller):
        super().__init__(controller)
        self.__font = ftfont.Font(self.REGULAR_FONT, 50)
        self.text = self.__font.render("py-Man", True, (255, 255, 255))
        self.text = pad(self.text, (0, 100), (255, 100, 100))
        demo2 = Demo(self.game_objects, self.text.get_rect(), self.text)
        demo = GameObject(self.game_objects, pygame.Rect(100, 100, 30, 30))
        demo.image.fill((255, 100, 100))
        demo.add_component(Physics)
        demo.add_component(Sprite)
        demo.add_component(Player)
        background = pygame.Surface(self.screen_rect.size)
        background.fill((20, 20, 20))
        background = GameObject(self.game_objects, pygame.Rect(0, 0, 0, 0),
                                background)
        background.blit(demo)
        crect1 = Rect(self.screen_rect)
        crect1.right = crect1.left
        crect2 = Rect(self.screen_rect)
        crect2.bottom = crect2.top
        crect3 = Rect(self.screen_rect)
        crect3.left = crect3.right
        crect4 = Rect(self.screen_rect)
        crect4.top = crect4.bottom
        collider1 = Demo(self.game_objects, crect1)
        collider2 = Demo(self.game_objects, crect2)
        collider3 = Demo(self.game_objects, crect3)
        collider4 = Demo(self.game_objects, crect4)
        collider1.get_component(Physics).set_static(True)
        collider2.get_component(Physics).set_static(True)
        collider3.get_component(Physics).set_static(True)
        collider4.get_component(Physics).set_static(True)

        self.game_objects.add(background, demo2, demo, collider1, collider2,
                              collider3, collider4)
        my_event = pygame.event.Event(USEREVENT, code='wow')
        timers.set_timer(my_event, 1000, 5000)
Esempio n. 19
0
    def __init__(self, title: str, content: str, duration: float):
        banner_background_surface = Surface((1024, 150), flags=SRCALPHA)
        banner_background_surface.fill((111, 111, 111, 200))

        font = pyfont.Font(GlobalSettings.FONT, 33)
        text_surface: Surface = InformationBanner.render_font(
            font, title.upper())
        banner_background_surface.blit(
            text_surface,
            InformationBanner.title_text_placer(banner_background_surface,
                                                text_surface))

        font = pyfont.Font(GlobalSettings.FONT, 19)
        text_surface: Surface = InformationBanner.render_font(
            font, content.upper())
        banner_background_surface.blit(
            text_surface,
            InformationBanner.content_text_placer(banner_background_surface,
                                                  text_surface))

        GameObject.__init__(self, banner_background_surface)

        self._duration = duration
        self._death_time = 0
    def __parse_box(self, element: ET.Element) -> GameObject:
        if 'src' in element.attrib:
            surface: Surface = ResourceManagement.get_image(
                element.attrib['src'])
        else:
            surface: Surface = Surface(self.__parse_dimensions(element))
            if 'invisible' in element.attrib:
                surface = surface.convert_alpha()
                surface.fill((0, 0, 0, 0))
            else:
                surface.fill(self.__parse_color(element))

        go = GameObject(surface)
        self.__assign_transform(element, go)

        return go
Esempio n. 21
0
 def __init__(self, controller):
     try:
         open(self.REGULAR_FONT).close()
     except FileNotFoundError:
         fix_path()
     self._font = ftfont.Font(self.REGULAR_FONT, 50)
     self._small_font = ftfont.Font(self.REGULAR_FONT, 30)
     self._bold_font = ftfont.Font(self.BOLD_FONT, 30)
     self.__controller = controller
     try:
         self.__last_scene = controller.get_scene()
     except AttributeError:
         self.__last_scene = None
     self.game_objects = LayeredUpdates()
     self.screen_rect = pygame.display.get_surface().get_rect()
     background = pygame.Surface(self.screen_rect.size)
     background.fill((240, 240, 240))
     self.background = GameObject(self.game_objects,
                                  pygame.Rect(0, 0, 0, 0), background)
     self.game_objects.add(self.background)
    def _on_collide(self, other: GameObject, direction_of_impact: Vector2,
                    impact_side: ImpactSide, delta_time: float):
        if other != self._target:
            Enemy._on_collide(self, other, direction_of_impact, impact_side,
                              delta_time)
        else:
            if impact_side != ImpactSide.TOP:
                # Collided with player, he need to suffer
                other: GameObject
                if impact_side == ImpactSide.BOTTOM:
                    i = 0
                    other.take_damage(1000)
                elif impact_side == ImpactSide.RIGHT:
                    i = 1
                elif impact_side == ImpactSide.LEFT:
                    i = -1

                other.apply_force(EnemySettings.HeavyRock.KNOCKBACK * i)
                other.take_damage(EnemySettings.HeavyRock.SIDE_DAMAGE)
                if other.is_dead:
                    self._target = None
Esempio n. 23
0
 def _on_collide(self, other: GameObject, direction_of_impact: Vector2, impact_side: ImpactSide, delta_time: float):
     if isinstance(other, Hitable):
         other.on_hit(self, impact_side)
     self.kill()
 def _on_collide(self, other: GameObject, direction_of_impact: Vector2, impact_side: ImpactSide, delta_time: float):
     if isinstance(other, PhysicsReceiver):
         other.apply_force(self._direction * self._force * delta_time)
 def _on_collide(self, other: GameObject, direction_of_impact: Vector2, impact_side: ImpactSide, delta_time: float):
     if isinstance(other, LivingEntity):
         other: LivingEntity
         other.health = 0
         other._win = True
         other._die()
 def __init__(self, surface: Surface, path_creator: Callable[[], Generator], start_on_creation: bool = True):
     GameObject.__init__(self, surface)
     self.__path_creator = path_creator
     self.__path_generator = None
     if start_on_creation:
         self.start()
Esempio n. 27
0
 def _on_collide(self, other: GameObject, direction_of_impact: Vector2, direction: ImpactSide, delta_time: float):
     if isinstance(other, RigidPhysicsAwareGameObject):
         other.apply_force(
             direction_of_impact.normalize() * PlayerSettings.Ability.TornadoJump.KNOCKBACK_STRENGTH * self.level)
Esempio n. 28
0
 def _on_collide(self, other: GameObject, direction_of_impact: Vector2, impact_side: ImpactSide, delta_time: float):
     if isinstance(other, RigidPhysicsAwareGameObject):
         other.apply_force(Vector2(self.velocity.x, PlayerSettings.Ability.Gust.PROJECTILE_HIT_STRENGTH_Y))
     self.kill()
Esempio n. 29
0
 def _on_collide(self, other: GameObject, direction_of_impact: Vector2, impact_side: ImpactSide, delta_time: float):
     if isinstance(other, RigidPhysicsAwareGameObject):
         other.apply_force(self.strength)
 def _on_collide(self, other: GameObject, direction_of_impact: Vector2,
                 impact_side: ImpactSide, delta_time: float):
     if isinstance(other, Player):
         other.apply_force(self._direction * 30)
         other.take_damage(20)
     self.kill()