Beispiel #1
0
    def parse_trigger(self, json):
        event     = json['event']
        id        = json.get('id')
        indica    = json['indicator'] and ResourceManager.load_config().is_debug()
        once      = json.get('once')
        if once == None: #Once by default is true bro
            once = True  #Once by default aint shit as it is not required by json schema!
        locking   = json.get('locking')
        if locking == None:
            locking = True
        # Not needed anymore
        #if locking == True:
        #    once = True # This prevents getting locked inside the dialog!
        coords = self.parse_coords(json['coords'])
        invert = json['coords']['inverted']
        size   = self.parse_size(json['size'])
        if event == 0 and id != None:
            extra = id
        elif event == 2 and id != None:
            extra = self.dialogs[id]
        elif event == 3:
            extra = json['next_scene']
        else:
            extra = None

        return Trigger(self.name, event, indica, once, coords, size, invert, extra, locking)
    def _update_scroll(self):
        player = Farm.get_player()
        resolution = ResourceManager.load_config().get_resolution()

        if player.rect.right > AbstractHorizontalScene.MAX_X:
            displ = player.rect.right - AbstractHorizontalScene.MAX_X

            if self._scroll_x + resolution[0] >= self._background.rect.right:
                if player.rect.right >= resolution[0]:
                    player.set_global_position(
                        (self._background.rect.right - player.rect.width,
                         player._position[1]))
                return False

            self._scroll_x = min(self._scroll_x + displ,
                                 self._background.rect.right - resolution[0])
            return True

        if player.rect.left < AbstractHorizontalScene.MIN_X:
            displ = AbstractHorizontalScene.MIN_X - player.rect.left
            self._scroll_x = max(self._scroll_x - displ, 0)

            if self._scroll_x == 0 and player.rect.left < 0:
                player.set_global_position((0, player._position[1]))
                return False
            else:
                return True

        return False
Beispiel #3
0
    def move_cpu(self):
        width, _ = ResourceManager.load_config().get_resolution()
        x_pos, _ = Farm.get_player()._position

        if self._delay >= Covid.DELAY:
            self._delay = 0
            if self.rect.left >= -150 and self.rect.right <= width + 150:
                dist_x = x_pos - self._position[0]

                if dist_x <= 0:
                    direction_x = Character.LEFT
                else:
                    direction_x = Character.RIGHT

                inc = self.rect.width / 2 * (1 if direction_x
                                             == Character.RIGHT else -1)
                self.rect.left += inc
                platform = Farm.platform_collision(self)
                self.rect.left -= inc
                if platform != None and platform._collides:
                    direction_y = Character.UP
                else:
                    direction_y = Character.STILL
            else:
                direction_x = Character.STILL
                direction_y = Character.STILL
            self._last_x = direction_x
            self._last_y = direction_y
        Character.move(self, (self._last_x, self._last_y))
Beispiel #4
0
    def update(self, elapsed_time):
        self._dur += elapsed_time
        self.image.set_alpha(self.duration / min(self._dur, self.duration) * 100)

        _, vel_y = ResourceManager.load_config().get_pixels((0, -self.speed))
        self._increase_position((0, vel_y * elapsed_time))

        if self._dur > self.duration:
            self.kill()
    def __init__(self):
        pygame.init()
        self._font = pygame.font.Font(None, 30)

        configuration = ResourceManager.load_config()
        self._screen = pygame.display.set_mode(configuration.get_resolution())
        pygame.display.set_caption(configuration.get_name())

        self._director = ResourceManager.load_director()
        self._farm_factory = None
Beispiel #6
0
    def __init__(self):
        (self._X_TOTAL, self._Y_TOTAL) = ResourceManager.load_config().get_resolution()

        # We store here the sprite groups
        self._sprite_groups = {}
        self._sprite_group = pygame.sprite.Group()

        # Set hud offsets
        self._x_min_offset = self._X_TOTAL*self.X_RELATIVE_LEFT_OFFSET/100
        self._y_min_offset = self._Y_TOTAL*self.Y_RELATIVE_TOP_OFFSET/100
        self._x_max_offset = self._X_TOTAL - self._X_TOTAL*self.X_RELATIVE_RIGHT_OFFSET/100
        self._y_max_offset = self._Y_TOTAL - self._Y_TOTAL*self.Y_RELATIVE_BOTTOM_OFFSET/100
Beispiel #7
0
    def __init__(self, menu, image, song=None, transform=False):
        res = ResourceManager.load_config().get_resolution()

        self._menu = menu

        self.image = ResourceManager.load_image_asset(image)
        if transform:
            self.image = pygame.transform.scale(self.image, res)

        self.rect = self.image.get_rect()
        self.rect.left = 0
        self.rect.bottom = res[1]

        self._song = song

        self._clicked = None
        self._gui_elements = []

        (self._x_total,
         self._y_total) = ResourceManager.load_config().get_resolution()
        (self._x_total_half, self._y_total_half) = (self._x_total >> 1,
                                                    self._y_total >> 1)
    def __init__(self, level, filename, scroll_x=0):
        AbstractBackground.__init__(self, scroll_x)

        resolution = ResourceManager.load_config().get_resolution()
        image = ResourceManager.load_sprite(filename, level)

        dest_resolution = (image.get_rect().width, resolution[1])
        self.image = pygame.transform.scale(image, dest_resolution)

        self.rect = self.image.get_rect()
        self.rect.bottom = resolution[1]

        self.subimage_rect = pygame.Rect((0, 0), resolution)
        self.subimage_rect.left = scroll_x
Beispiel #9
0
    def update(self, elapsed_time):
        Enemy.update(self, elapsed_time)
        width, _ = ResourceManager.load_config().get_resolution()
        left = self.rect.left
        right = self.rect.right
        inc = self.rect.width / 2 * (-1 if self._velocity[0] < 0 else 1)
        self.rect.left += inc

        left = self.rect.left
        right = self.rect.right
        inc = self.rect.width / 2 * (-1 if self._velocity[0] < 0 else 1)
        self.rect.left += inc

        if Farm.touches_anything_visible(self) or left < -50 or right > width + 50:
            self.kill()

        self.rect.left += inc
Beispiel #10
0
    def move_cpu(self):
        width, _ = ResourceManager.load_config().get_resolution()
        x_pos, y_pos = Farm.get_player()._position

        if self._delay >= Torreta.DELAY:
            self._delay = 0
            if self.rect.left >= -150 and self.rect.right <= width + 150:
                dist_x = x_pos - self._position[0]

                if dist_x <= 0:
                    direction_x = Character.LEFT
                    self._pos_shot = self._position[0] - 20, self._position[1] - 22
                else:
                    direction_x = Character.RIGHT
                    self._pos_shot = self._position[0] + 50, self._position[1] - 22

                if self._last_shot >= Torreta.SHOOT_RATIO:
                    self._last_shot = 0
                    Farm.add_enemy(Shot(self._level, self._shot, self._pos_shot, dist_x < 0, self._scroll))
            else:
                direction_x = Character.STILL

            self._last_x = direction_x
        Character.move(self, (self._last_x, Character.STILL))
Beispiel #11
0
    def update(self, elapsed_time):
        step_over = False
        self._jump += elapsed_time
        self._dash += elapsed_time

        res = ResourceManager.load_config().get_resolution()
        vel_x, vel_y = self._velocity_x, self._velocity_y
        vel_px, vel_py = ResourceManager.load_config().get_pixels(
            (vel_x, vel_y))

        if self._dash > Character.DASH_DUR and not self._end_dash:
            self._end_dash = True
            self._velocity = vel_px * elapsed_time * (-1 if self._left else
                                                      1), self._velocity[1]

        # update horizontal movement
        if self._movement_x == Character.LEFT:
            self._velocity = (-vel_px * elapsed_time, self._velocity[1])
        if self._movement_x == Character.RIGHT:
            self._velocity = (vel_px * elapsed_time, self._velocity[1])
        if self._movement_x == Character.STILL:
            self._velocity = (0, self._velocity[1])
        if self._movement_y == Character.UP and self._jump >= Character.JUMPING_DELAY and not self._is_jumping:
            self._jump = 0
            self._is_jumping = True
            self._velocity = (self._velocity[0], -vel_py * 0.018)
        if self._dash < Character.DASH_DUR:
            direction = -1 if self._left else 1
            self._velocity = ((vel_px + 300) * elapsed_time * direction, 0)
        self._update_sprite()

        # check horizontal collisions
        self._increase_position((self._velocity[0], 0))
        platform = Farm.platform_collision(self)
        if platform != None and platform._collides and self.rect.bottom > platform.rect.top:
            dist_l = abs(platform.rect.centerx - self.rect.left)
            dist_r = abs(platform.rect.centerx - self.rect.right)

            if self.rect.bottom - Character.STEP_OVER < platform.rect.top + 1:
                step_over = True
            elif self._velocity[0] > 0 or dist_l >= dist_r:
                self.set_global_position(
                    (platform._position[0] - self.rect.width,
                     self._position[1]))
            elif self._velocity[0] < 0 or dist_r > dist_l:
                self.set_global_position(
                    (platform._position[0] + platform.rect.width,
                     self._position[1]))

        # check vertical collisions
        self._increase_position((0, self._velocity[1]))
        platform = Farm.platform_collision(self)
        if platform != None and platform._collides:
            if self._velocity[1] > 0 or step_over:
                if self._is_jumping and self._velocity[
                        1] > 0 and self.rect.left - platform.rect.left - platform.rect.height > 10:
                    self._dash = Character.DASH_CD
                self._is_jumping = False
                self._velocity = (self._velocity[0], 0)
                self.set_global_position(
                    (self._position[0],
                     platform._position[1] - platform.rect.height + 1))
            elif self._velocity[1] < 0:
                self._velocity = (self._velocity[0],
                                  0.04 * vel_py * elapsed_time)
                self.set_global_position(
                    (self._position[0],
                     platform._position[1] + self.rect.height))
        else:
            # check y axis boundaries
            if self.rect.bottom >= res[1]:
                if self._is_jumping and self._velocity[
                        1] > 0 and self.rect.left > 10:
                    self._dash = Character.DASH_CD
                self._is_jumping = False
                self._velocity = (self._velocity[0], 0)
                self.set_global_position((self._position[0], res[1]))
            else:
                self._is_jumping = True
                self._jump -= elapsed_time
                self._velocity = (self._velocity[0], self._velocity[1] +
                                  0.08 * vel_py * elapsed_time)
Beispiel #12
0
 def move_cpu(self):
     width, _ = ResourceManager.load_config().get_resolution()
     if self.rect.left >= -50 and self.rect.right <= width + 50:
         Character.move(self, (Character.LEFT, Character.STILL))
 def update(self, elapsed_time):
     increment = ResourceManager.load_config().get_pixels(self._velocity)
     new_x = increment[0] * elapsed_time
     new_y = increment[1] * elapsed_time
     self._increase_position((new_x, new_y))