Пример #1
0
    def startup(self, **kwargs):
        super(MonsterMenuState, self).startup(**kwargs)

        # make a text area to show messages
        self.text_area = TextArea(self.font, self.font_color, (96, 96, 96))
        self.text_area.rect = pygame.Rect(tools.scale_sequence([20, 80, 80, 100]))
        self.sprites.add(self.text_area, layer=100)

        # Set up the border images used for the monster slots
        self.monster_slot_border = {}
        self.monster_portrait = pygame.sprite.Sprite()
        self.hp_bar = HpBar()

        # load and scale the monster slot borders
        root = "gfx/ui/monster/"
        border_types = ["empty", "filled", "active"]
        for border_type in border_types:
            filename = root + border_type + "_monster_slot_border.png"
            border = tools.load_and_scale(filename)

            filename = root + border_type + "_monster_slot_bg.png"
            background = tools.load_image(filename)

            window = GraphicBox(border, background, None)
            self.monster_slot_border[border_type] = window

        # TODO: something better than this global, load_sprites stuff
        for monster in self.game.player1.monsters:
            monster.load_sprites()
Пример #2
0
    def startup(self, **kwargs):
        super(MonsterMenuState, self).startup(**kwargs)

        # make a text area to show messages
        self.text_area = TextArea(self.font, self.font_color, (96, 96, 96))
        self.text_area.rect = pygame.Rect(
            tools.scale_sequence([20, 80, 80, 100]))
        self.sprites.add(self.text_area, layer=100)

        # Set up the border images used for the monster slots
        self.monster_slot_border = {}
        self.monster_portrait = pygame.sprite.Sprite()
        self.hp_bar = HpBar()

        # load and scale the monster slot borders
        root = "gfx/ui/monster/"
        border_types = ["empty", "filled", "active"]
        for border_type in border_types:
            filename = root + border_type + "_monster_slot_border.png"
            border = tools.load_and_scale(filename)

            filename = root + border_type + "_monster_slot_bg.png"
            background = tools.load_image(filename)

            window = GraphicBox(border, background, None)
            self.monster_slot_border[border_type] = window

        # TODO: something better than this global, load_sprites stuff
        for monster in self.game.player1.monsters:
            monster.load_sprites()
Пример #3
0
    def __init__(self, x, y, filename):

        self.x = x
        self.y = y

        self.image = load_image(filename)
        self.hitbox = pygame.Rect(self.x, self.y,
                                  self.image.get_rect().size[0],
                                  self.image.get_rect().size[1])
Пример #4
0
    def __init__(self, name, icon, color):

        self.name = name
        self.icon = icon
        self.color = color
        self.points = 0
        self.move_finished = False

        self.name_rendered = render_text(self.name)
        self.active_name_rendered = render_text(self.name, color=(255, 0, 0))
        self.icon_rendered = load_image(self.icon)
Пример #5
0
    def __init__(self, row, column, color, filename):

        self.row = row
        self.column = column

        self.color = color
        self.filename = filename
        self.image = load_image(f'{self.filename}_{self.color}.png')

        self.width, self.height = self.image.get_rect().size
        self.has_moved = False
        self.value = 0
        self.symbol = ''
Пример #6
0
    def load_graphics(self):
        """ Loads all the graphical elements of the menu
            Will load some elements from disk, so needs to be called at least once.
        """
        # load and scale the _background
        background = None
        if self.background_filename:
            background = tools.load_image(self.background_filename)

        # load and scale the menu borders
        border = None
        if self.draw_borders:
            border = tools.load_and_scale(self.borders_filename)

        # set the helper to draw the _background
        self.window = GraphicBox(border, background, self.background_color)

        # handle the arrow cursor
        image = tools.load_and_scale(self.cursor_filename)
        self.arrow = MenuCursor(image)
Пример #7
0
    def load_graphics(self):
        """ Loads all the graphical elements of the menu
            Will load some elements from disk, so needs to be called at least once.
        """
        # load and scale the _background
        background = None
        if self.background_filename:
            background = tools.load_image(self.background_filename)

        # load and scale the menu borders
        border = None
        if self.draw_borders:
            border = tools.load_and_scale(self.borders_filename)

        # set the helper to draw the _background
        self.window = GraphicBox(border, background, self.background_color)

        # handle the arrow cursor
        image = tools.load_and_scale(self.cursor_filename)
        self.arrow = MenuCursor(image)
Пример #8
0
    def update(self):

        self.name_rendered = render_text(self.name)
        self.active_name_rendered = render_text(self.name, color=(255, 0, 0))
        self.icon_rendered = load_image(self.icon)
Пример #9
0
from core.player import Player

os.environ['SDL_VIDEO_CENTERED'] = '1'
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = 'hide'

pygame.init()
pygame.font.init()

config = json.load(open('core/config.json', 'r'))

display = pygame.display.set_mode((config['WIDTH'], config['HEIGHT']))
pygame.display.set_caption(config['TITLE'])

clock = pygame.time.Clock()

icon = load_image('icon.png')
pygame.display.set_icon(icon)


def run():

    start_menu()


def start_menu():
    def graphics(surface, entities):

        surface.fill((255, 255, 255))

        text = render_text('Chess', font='arial', fontsize=100)
        surface.blit(text, ((config['WIDTH'] - text.get_width()) // 2,
Пример #10
0
    def __init__(self, sprite_name="player1", name="Red"):
        self.name = name			# This is the player's name to be used in dialog
        self.ai = None              # Whether or not this player has AI associated with it
        self.sprite = {}			# The pyganim object that contains the player animations
        self.sprite_name = sprite_name # Hold on the the string so it can be sent over the network
        self.isplayer = True
        self.path = None

        # reference direction and movement states to animation names
        # this dictionary is kinda wip, idk
        self.animation_mapping = {
            True: {
                'up': 'back_walk',
                'down': 'front_walk',
                'left': 'left_walk',
                'right': 'right_walk'},
            False: {
                'up': 'back',
                'down': 'front',
                'left': 'left',
                'right': 'right'}
        }

        # Get all of the player's standing animation images.
        self.standing = {}
        standing_types = ["front", "back", "left", "right"]
        for standing_type in standing_types:
            surface = tools.load_image("sprites/%s_%s.png" % (sprite_name, standing_type))
            surface_top = surface.subsurface((0, 0,
                                              surface.get_width(), int(surface.get_height() / 2)))
            surface_bottom = surface.subsurface((0, int(surface.get_height() / 2),
                                                 surface.get_width(), int(surface.get_height() / 2)))
            self.standing[standing_type] = surface
            self.standing[standing_type + "-top"] = surface_top
            self.standing[standing_type + "-bottom"] = surface_bottom

        self.playerWidth, self.playerHeight = self.standing["front"].get_size()    # The player's sprite size in pixels
        self.game_variables = {}		# Game variables for use with events
        self.inventory = {}             # The Player's inventory.
        self.monsters = []              # This is a list of tuxemon the player has
        self.storage = {"monsters": [], "items": {}}
        self.party_limit = 6            # The maximum number of tuxemon this player can hold 1 for testing
        self.walking = False		    # Whether or not the player is walking
        self.running = False		    # Whether or not the player is running
        self.moving = False			    # Whether or not the player is moving
        self.move_direction = "down"    # This is a string of the direction we're moving if we're in the middle of moving
        self.direction = {"up": False, "down": False, "left": False, "right": False}	# What direction the player is moving
        self.facing = "down"            # What direction the player is facing
        self.walkrate = 60              # The rate in pixels per second the player is walking
        self.runrate = 118			    # The rate in pixels per second the player is running
        self.moverate = self.walkrate   # The movement rate in pixels per second
        self.position = [0,0]			# The player's sprite position on the screen
        self.global_pos = [0,0]			# This is the offset we're going to add to the x,y coordinates of everything on the map
        self.tile_pos = (0,0)           # This is the position of the player based on tile
        self.tile_size = [16,16]
        self.move_destination = [0,0]   # The player's destination location to move to
        self.final_move_dest = [0,0]    # Stores the final destination sent from a client
        self.rect = pygame.Rect(self.position, (self.playerWidth, self.playerHeight)) # Collision rect

        # Load all of the player's sprite animations
        anim_types = ['front_walk', 'back_walk', 'left_walk', 'right_walk']
        for anim_type in anim_types:
            images_and_durations = [('sprites/%s_%s.%s.png' % (sprite_name, anim_type, str(num).rjust(3, '0')),
                                    prepare.CONFIG.player_animation_speed) for num in range(4)]

            # Loop through all of our animations and get the top and bottom subsurfaces.
            full_frames = []
            top_frames = []
            bottom_frames = []
            for image, duration in images_and_durations:
                surface = tools.load_image(image)
                w, h = surface.get_size()

                top_surface = surface.subsurface((0, 0, w, h // 2))
                bottom_surface = surface.subsurface((0, h // 2, w, h // 2))

                full_frames.append((surface, duration))
                top_frames.append((top_surface, duration))
                bottom_frames.append((bottom_surface, duration))

            # Create an animation set for the top and bottom halfs of our sprite, so we can draw
            # them on different layers.
            self.sprite[anim_type] = pyganim.PygAnimation(full_frames)
            self.sprite[anim_type + '-top'] = pyganim.PygAnimation(top_frames)
            self.sprite[anim_type + '-bottom'] = pyganim.PygAnimation(bottom_frames)

        # Have the animation objects managed by a conductor.
        # With the conductor, we can call play() and stop() on all the animtion
        # objects at the same time, so that way they'll always be in sync with each
        # other.
        self.moveConductor = pyganim.PygConductor(self.sprite)
        self.moveConductor.play()
        self.anim_playing = True
Пример #11
0
    def __init__(self, sprite_name="player1", name="Red"):
        self.name = name  # This is the player's name to be used in dialog
        self.ai = None  # Whether or not this player has AI associated with it
        self.sprite = {
        }  # The pyganim object that contains the player animations
        self.sprite_name = sprite_name  # Hold on the the string so it can be sent over the network
        self.isplayer = True

        # Get all of the player's standing animation images.
        self.standing = {}
        standing_types = ["front", "back", "left", "right"]
        for standing_type in standing_types:
            surface = tools.load_image("sprites/%s_%s.png" %
                                       (sprite_name, standing_type))
            surface_top = surface.subsurface(
                (0, 0, surface.get_width(), int(surface.get_height() / 2)))
            surface_bottom = surface.subsurface(
                (0, int(surface.get_height() / 2), surface.get_width(),
                 int(surface.get_height() / 2)))
            self.standing[standing_type] = surface
            self.standing[standing_type + "-top"] = surface_top
            self.standing[standing_type + "-bottom"] = surface_bottom

        self.playerWidth, self.playerHeight = self.standing["front"].get_size(
        )  # The player's sprite size in pixels
        self.inventory = {}  # The Player's inventory.
        self.monsters = []  # This is a list of tuxemon the player has
        self.storage = {"monsters": [], "items": {}}
        self.party_limit = 6  # The maximum number of tuxemon this player can hold 1 for testing
        self.walking = False  # Whether or not the player is walking
        self.running = False  # Whether or not the player is running
        self.moving = False  # Whether or not the player is moving
        self.move_direction = "down"  # This is a string of the direction we're moving if we're in the middle of moving
        self.direction = {
            "up": False,
            "down": False,
            "left": False,
            "right": False
        }  # What direction the player is moving
        self.facing = "down"  # What direction the player is facing
        self.walkrate = 60  # The rate in pixels per second the player is walking
        self.runrate = 118  # The rate in pixels per second the player is running
        self.moverate = self.walkrate  # The movement rate in pixels per second
        self.position = [0, 0]  # The player's sprite position on the screen
        self.global_pos = [
            0, 0
        ]  # This is the offset we're going to add to the x,y coordinates of everything on the map
        self.tile_pos = (0, 0
                         )  # This is the position of the player based on tile
        self.tile_size = [16, 16]
        self.move_destination = [
            0, 0
        ]  # The player's destination location to move to
        self.final_move_dest = [
            0, 0
        ]  # Stores the final destination sent from a client
        #self.colliding = False			# To check and see if we're colliding with anything
        self.rect = pygame.Rect(self.position[0], self.position[1],
                                self.playerWidth,
                                self.playerHeight)  # Collision rect
        self.game_variables = {}  # Game variables for use with events

        self.path = None

        # Load all of the player's sprite animations
        anim_types = ['front_walk', 'back_walk', 'left_walk', 'right_walk']
        for anim_type in anim_types:
            images_and_durations = [
                ('sprites/%s_%s.%s.png' %
                 (sprite_name, anim_type, str(num).rjust(3, '0')),
                 prepare.CONFIG.player_animation_speed) for num in range(4)
            ]

            # Loop through all of our animations and get the top and bottom subsurfaces.
            full_frames = []
            top_frames = []
            bottom_frames = []
            for image, duration in images_and_durations:
                surface = tools.load_image(image)
                w, h = surface.get_size()

                top_surface = surface.subsurface((0, 0, w, h // 2))
                bottom_surface = surface.subsurface((0, h // 2, w, h // 2))

                full_frames.append((surface, duration))
                top_frames.append((top_surface, duration))
                bottom_frames.append((bottom_surface, duration))

            # Create an animation set for the top and bottom halfs of our sprite, so we can draw
            # them on different layers.
            self.sprite[anim_type] = pyganim.PygAnimation(full_frames)
            self.sprite[anim_type + '-top'] = pyganim.PygAnimation(top_frames)
            self.sprite[anim_type +
                        '-bottom'] = pyganim.PygAnimation(bottom_frames)

        # Have the animation objects managed by a conductor.
        # With the conductor, we can call play() and stop() on all the animtion
        # objects at the same time, so that way they'll always be in sync with each
        # other.
        self.moveConductor = pyganim.PygConductor(self.sprite)
        self.moveConductor.play()
        self.anim_playing = True