Exemple #1
0
    def __init__(self, name):
        MastermindClientTCP.__init__(self)
        pyglet.resource.path = [
            'tiles', 'tiles/background', 'tiles/monsters', 'tiles/terrain'
        ]
        pyglet.resource.reindex()
        ######################################################################################
        ## when we get an update from the server we update these values from the parsed chunk.
        self.name = name
        self.chunk_size = (51, 27)
        self.player = None
        self.chunk = None
        self.map = None
        self.creatures = None
        self.objects = None
        self.map_grid = glooey.Grid(self.chunk_size[1], self.chunk_size[0], 16,
                                    16)  # chunk_size + tilemap size
        self.map_grid.set_left_padding(16)  # for the border.
        self.map_grid.set_top_padding(16)

        for i in range(self.chunk_size[1]
                       ):  # glooey uses y,x for grids from the top left.
            for j in range(self.chunk_size[0]):
                self.map_grid.add(
                    i, j,
                    glooey.images.Image(pyglet.resource.texture('t_grass.png'))
                )  # before we get an update we need to init the map with grass.

        ######################################################################################

        window = pyglet.window.Window(854, 480)
        gui = glooey.Gui(window)

        bg = glooey.Background()
        bg.set_appearance(
            center=pyglet.resource.texture('center.png'),
            top=pyglet.resource.texture('top.png'),
            bottom=pyglet.resource.texture('bottom.png'),
            left=pyglet.resource.texture('left.png'),
            right=pyglet.resource.texture('right.png'),
            top_left=pyglet.resource.texture('top_left.png'),
            top_right=pyglet.resource.texture('top_right.png'),
            bottom_left=pyglet.resource.texture('bottom_left.png'),
            bottom_right=pyglet.resource.texture('bottom_right.png'))
        gui.add(bg)
        gui.add(self.map_grid)

        @window.event
        def on_key_press(symbol, modifiers):
            if symbol == KEY.RETURN:
                print('return')
            if symbol == KEY.W:
                command = Command(args.name, 'move', ['north'])
                client.send(command)
Exemple #2
0
def test_image():
    frame = TestFrame()
    widget = TestBackground()
    frame.add(widget)
    gui.add(frame)
    yield "A orange tiled background in green tiled frame."

    frame.padding = 32
    yield "Pad around the frame."

    frame.box.padding = 48
    yield "Pad inside the frame."

    bg = glooey.Background()
    bg.set_appearance(center=pyglet.image.load('assets/64x64/purple.png'))
    frame.decoration = bg
    yield "Dynamically change the background."
Exemple #3
0
    def __init__(self):
        self.state = "login"  # character_select, character_gen, main
        MastermindClientTCP.__init__(self)

        self.window = pyglet.window.Window(896, 498)
        self.client_name = ''

        pyglet.gl.glEnable(pyglet.gl.GL_BLEND)
        pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA,
                              pyglet.gl.GL_ONE_MINUS_SRC_ALPHA)

        self.gui = glooey.Gui(self.window)

        self.bg = glooey.Background()
        self.bg.set_appearance(
            center=pyglet.resource.texture("center.png"),
            top=pyglet.resource.texture("top.png"),
            bottom=pyglet.resource.texture("bottom.png"),
            left=pyglet.resource.texture("left.png"),
            right=pyglet.resource.texture("right.png"),
            top_left=pyglet.resource.texture("top_left.png"),
            top_right=pyglet.resource.texture("top_right.png"),
            bottom_left=pyglet.resource.texture("bottom_left.png"),
            bottom_right=pyglet.resource.texture("bottom_right.png"),
        )

        self.gui.add(self.bg)

        self.TileManager = TileManager
        self.ItemManager = ItemManager
        self.RecipeManager = RecipeManager

        # TODO: make new hotbar in pyglet.
        self.hotbars = []

        self.LoginWindow = LoginWindow()
        self.LoginWindow.grid[6, 1].push_handlers(
            on_click=self.login)  # Connect Button

        self.gui.add(self.LoginWindow)

        self.character = None
        self.localmap = None

        # init but don't show the window
        self.mainWindow = mainWindow
Exemple #4
0
#!/usr/bin/env python3

import glooey
import pyglet

window = pyglet.window.Window()
gui = glooey.Gui(window)

bg = glooey.Background()
bg.set_appearance(
    center=pyglet.resource.texture('center.png'),
    top=pyglet.resource.texture('top.png'),
    bottom=pyglet.resource.texture('bottom.png'),
    left=pyglet.resource.texture('left.png'),
    right=pyglet.resource.texture('right.png'),
    top_left=pyglet.resource.texture('top_left.png'),
    top_right=pyglet.resource.texture('top_right.png'),
    bottom_left=pyglet.resource.texture('bottom_left.png'),
    bottom_right=pyglet.resource.texture('bottom_right.png'),
)
gui.add(bg)

pyglet.app.run()
    def message_handler(self, sender, message):
        if legume.messages.message_factory.is_a(message, 'TankCreate'):
            if tanks.get(message.id.value) is None:
                tanks[message.id.value] = Tank.create_from_message(message)
                if message.id.value == self.cl_id:
                    self.logger.info("Creating self")
                    self.start_game()
            else:
                tanks[message.id.value].update_from_message(message)
        elif legume.messages.message_factory.is_a(message, 'TankUpdate'):
            if tanks.get(message.id.value) is None:
                tanks[message.id.value] = Tank.create_from_message(message)
                if message.id.value == self.cl_id:
                    self.logger.info("Creating self")
                    self.start_game()
            else:
                tanks[message.id.value].update_from_message(message)
        elif legume.messages.message_factory.is_a(message, 'GameOver'):
            if message.winner_id.value == self.CLIENT_ID:
                game_over_bg = glooey.Background()
                game_over_bg.image = pyglet.image.load(
                    "res/PNG/GUI/overlay.png")
                game_over_bg.custom_alignment = 'fill'
                self.gui.add(game_over_bg)
                game_over_vbox = glooey.VBox()
                game_over_vbox.custom_alignment = 'center'
                game_over_label = TitleLabel("You Win!")
                score_label = SubtitleLabel("Your score is %d" %
                                            message.score.value)
                score_label.custom_font_size = 10
                ex_button = Exit_Button()
                game_over_vbox.add(game_over_label)
                game_over_vbox.add(score_label)
                game_over_vbox.add(ex_button)
                self.gui.add(game_over_vbox)
            else:
                game_over_bg = glooey.Background()
                game_over_bg.image = pyglet.image.load(
                    "res/PNG/GUI/overlay.png")
                game_over_bg.custom_alignment = 'fill'
                self.gui.add(game_over_bg)
                game_over_vbox = glooey.VBox()
                game_over_vbox.custom_alignment = 'center'
                game_over_label = TitleLabel("You Lose")
                ex_button = Exit_Button()
                game_over_vbox.add(game_over_label)
                game_over_vbox.add(ex_button)
                self.gui.add(game_over_vbox)
        elif legume.messages.message_factory.is_a(message, 'UpdateTime'):
            time = message.time.value
            self.time_label.text = '<font face="Arial" size="50" color="white"><b>%s</b></font>' % (
                time)
        elif legume.messages.message_factory.is_a(message, 'TankFireClient'):
            tank = tanks[message.id.value]
            if tank.idn != self.tank.idn:
                tank.fire(message.projectile_id.value)
        elif legume.messages.message_factory.is_a(message, 'TankSwitchAmmo'):
            tank = tanks[message.id.value]
            tank.ammo_type = message.ammo_type.value
        elif legume.messages.message_factory.is_a(message, 'TankHit'):
            tank = tanks[message.id.value]
            projectile = projectiles.get(message.projectile_id.value)
            if projectile is not None:
                tank.hit(projectile.damage)
                if tank.idn == self.tank.idn and not self.tank.alive and not self.tank.destroyed:
                    self.tank.destroyed = True
                    game_over_bg = glooey.Background()
                    game_over_bg.image = pyglet.image.load(
                        "res/PNG/GUI/overlay.png")
                    game_over_bg.custom_alignment = 'fill'
                    self.gui.add(game_over_bg)
                    game_over_vbox = glooey.VBox()
                    game_over_vbox.alignment = 'center'
                    game_over_label = TitleLabel("You have been eliminated")
                    retry_button = PlayAgain_Button()
                    ex_button = Exit_Button()

                    def on_click(widget):
                        self.gui.remove(game_over_bg)
                        self.gui.remove(game_over_vbox)
                        self.gui.add(stack)
                        self._client.disconnect()
                        self.cl_id = random.randint(1, 100000)
                        self.started = False
                        self.running = False

                    retry_button.on_click = on_click
                    game_over_vbox.add(game_over_label)
                    game_over_vbox.add(retry_button)
                    game_over_vbox.add(ex_button)
                    self.gui.add(game_over_vbox)
                projectile.destroy()
                projectiles.pop(projectile.idn)

        elif legume.messages.message_factory.is_a(message,
                                                  'ProjectileDestroy'):
            projectile = projectiles.get(message.projectile_id.value)
            if projectile is not None:
                projectile.destroy()
                projectiles.pop(projectile.idn)
        elif legume.messages.message_factory.is_a(message, 'ProjectileCreate'):
            if projectiles.get(message.id.value) is None:
                projectiles[message.id.value] = Projectile.create_from_message(
                    message)
            else:
                projectiles[message.id.value].update_from_message(message)
        elif legume.messages.message_factory.is_a(message, 'ProjectileUpdate'):
            if projectiles.get(message.id.value) is None:
                projectiles[message.id.value] = Projectile.create_from_message(
                    message)
            else:
                projectiles[message.id.value].update_from_message(message)
        elif legume.messages.message_factory.is_a(message, 'MapCreate'):
            l = message.l.value
            w = message.w.value
            seed_a = message.seed_a.value
            seed_b = message.seed_b.value
            self.game_map = Game_Map.generate_map(l, w, seed_a, seed_b)
            self.minimap = Minimap(self.game_map, self.cl_id)
        else:
            self.logger.info('Message: %s' % message)