def init(numplayers = 2):
    screen = pygame.display.get_surface()
    em = EventManager()
    bg = load.image("select-bg.png")
    move_snd = load.sound("select-move.wav")
    confirm_snd = load.sound("select-confirm.wav")
    confirm_snd.set_volume(0.4)

    sprites = RenderUpdates()
    portraits = [PortraitDisplay([20, 20]), PortraitDisplay([20, 320])]
    names = [NameDisplay([20, 220]), NameDisplay([20, 520])]
    drops = [DropDisplay([240, 20]), DropDisplay([240, 320])]
    stats = [StatDisplay([240, 150]), StatDisplay([240, 450])]
    descs = [DescDisplay([430, 20]), DescDisplay([430, 320])]
    char_sprites = zip(portraits, names, drops, stats, descs)

    idx = [0, 0]
    confirmed = [False, False]
    for i, sprs in enumerate(char_sprites):
        if i < numplayers:
            for spr in sprs: spr.set_char(Character.available[i])
            sprites.add(sprs)
            idx[i] = i

    init_bg = bg.convert()
    sprites.update(pygame.time.get_ticks())
    sprites.draw(init_bg)
    wipes.wipe_in(init_bg)
    init_bg = None # Let us GC it
    pygame.display.update()
    sprites.clear(screen, bg)

    while False in [(c.confirmed or i >= numplayers)
                    for i, c in enumerate(portraits)]:
        for ev in em.wait():
            if ev.type == PLAYER:
                if ev.key == LEFT:
                    i = (idx[ev.player] - 1) % len(Character.available)
                    idx[ev.player] = i
                elif ev.key == RIGHT:
                    i = (idx[ev.player] + 1) % len(Character.available)
                    idx[ev.player] = i
                elif ev.key in [ROT_CC, ROT_CW, CONFIRM]:
                    confirm_snd.play()
                    portraits[ev.player].confirmed = True

                if ev.key in [LEFT, RIGHT]:
                    move_snd.play()
                    for spr in char_sprites[ev.player]:
                        spr.set_char(Character.available[idx[ev.player]])
                    portraits[ev.player].confirmed = False

            elif ev.type == QUIT:
                return None, None

        sprites.update(pygame.time.get_ticks())
        pygame.display.update(sprites.draw(screen))
        sprites.clear(screen, bg)

    return [Character.available[i] for i in idx]
Exemplo n.º 2
0
 def __init__(self, game: Game):
     super().__init__(game)
     self.bg = pyglet.sprite.Sprite(
         load.image("assets/minecraft/textures/gui/title/mojang.png"),
         x=128,
         y=64)
     self.thread = Thread(target=self.process, name="Initialization")
     self.draw_count = 0
Exemplo n.º 3
0
 def __init__(self, grid, colorkey, name=None, size_x=100, size_y=100):
     pygame.sprite.DirtySprite.__init__(self)
     if name:
         self.image, self.rect = load.image(name, colorkey)
     else:
         self.image = pygame.Surface((size_x, size_y))
         self.rect = self.image.get_rect()
     self.grid = grid
Exemplo n.º 4
0
class gui:
    background = load.image(
        "assets/minecraft/textures/gui/title/background/panorama_0.png")
    background = transform.blur(transform.scale(background, 4, 0), 8)

    mojang = load.image("assets/minecraft/textures/gui/title/mojang.png")
    __raw_minecraft = load.pg.image(
        "assets/minecraft/textures/gui/title/minecraft.png")
    # Re-make Minecraft LOGO
    try:
        __minecraft = pygame.Surface((274, 45), flags=pygame.SRCALPHA)
        __minecraft.blits([(__raw_minecraft.subsurface(
            (0, 0, 155, 44)), (0, 0)),
                           (__raw_minecraft.subsurface(
                               (0, 45, 119, 44)), (154, 0))])
        minecraft = transform.PygameToGL(__minecraft)
    except Exception:
        minecraft = transform.PygameToGL(__raw_minecraft)

    widgets = load.pg.image("assets/minecraft/textures/gui/widgets.png")
    button = widgets.subsurface(0, 66, 200, 20)
    button_highlight = widgets.subsurface(0, 86, 200, 20)
    # Half Button
    button_half = pygame.Surface((75, 20))
    button_half.blits([(button.subsurface((0, 0, 65, 20)), (0, 0)),
                       (button.subsurface((190, 0, 10, 20)), (65, 0))])
    # Half Button high light version
    button_half_highlight = pygame.Surface((75, 20))
    button_half_highlight.blits([(button_highlight.subsurface(
        (0, 0, 65, 20)), (0, 0)),
                                 (button_highlight.subsurface(
                                     (190, 0, 10, 20)), (65, 0))])
    # Convert
    button = transform.PygameToGL(button)
    button_highlight = transform.PygameToGL(button_highlight)
    button_half = transform.PygameToGL(button_half)
    button_half_highlight = transform.PygameToGL(button_half_highlight)

    options_background = transform.brightness(
        load.image("assets/minecraft/textures/gui/options_background.png"),
        0.3)
    options_background_dark = transform.brightness(options_background, 0.4)
 def _set_text(self, string):
     midbottom = self.rect.midbottom
     plat = load.image("platform.png")
     plat.set_colorkey(plat.get_at([0, 0]), RLEACCEL)
     plat_r = plat.get_rect()
     letters = textfx.boxes_from_string(string, pos = self._pos)
     surf = pygame.Surface([max(260, letters.get_width()),
                                plat.get_height() + letters.get_height()])
     plat_r.centerx = surf.get_rect().centerx
     plat_r.bottom = surf.get_height() - 1
     surf.blit(plat, plat_r)
     letters_r = letters.get_rect()
     letters_r.centerx = surf.get_rect().centerx
     letters_r.bottom = surf.get_height() - 16
     surf.blit(letters, letters_r)
     surf.set_colorkey(surf.get_at([0, 0]), RLEACCEL)
     self.image = surf
     self.rect = self.image.get_rect()
     self.rect.midbottom = midbottom
def init():
    if os.name == 'posix': # We need to force stereo in many cases.
        try: mixer.pre_init(44100, -16, 2)
        except pygame.error: pass

    pygame.init()
    config.init(rc_file)
    os.chdir(angrydd_path)
    pygame.display.set_caption("Angry, Drunken Programmers")
    try: pygame.display.set_icon(pygame.image.load("angrydd.png"))
    except pygame.error: pass
    pygame.mouse.set_visible(False)
    if config.getboolean("settings", "fullscreen"): flags = FULLSCREEN
    else: flags = 0
    pygame.display.set_mode([800, 600], flags)

    import game
    import menu
    import boxes
    import characters

    boxes.TickBox.sound = load.sound("tick.wav")
    boxes.TickBox.sound.set_volume(0.3)

    boxes.BreakBox.sound = load.sound("break.wav")
    boxes.BreakBox.sound.set_volume(0.3)

    boxes.Special.sound = load.sound("select-confirm.wav")
    boxes.Special.sound.set_volume(0.5)

    game.FallingBoxes.rotate_sound = load.sound("rotate.wav")
    game.FallingBoxes.rotate_sound.set_volume(0.2)

    menu.Menu.bg = load.image("menu-bg.png").convert()

    characters.init()

    mixer.music.load(os.path.join("music", "intro.ogg"))
    mixer.music.play(-1)
Exemplo n.º 7
0
def dream_with_image_at_path(path_image):
    image = load.image(path_image)
    image_augmented = dream.with_image(image)
    store.image(image_augmented)
Exemplo n.º 8
0
import pygame
import entities
import sys
import load
from pygame.locals import *

pygame.init()

# setup initial window
screen = pygame.display.set_mode((1600, 800))
pygame.display.set_caption('Project: Right Click')
icon = load.image('cursor.bmp', (255, 255, 255))
pygame.display.set_icon(icon)
clock = pygame.time.Clock()

# setup background
background = pygame.Surface(screen.get_size())
background.fill((50, 50, 50))
screen.blit(background, (0, 0))

# load game objects
button = entities.TestButton()

# main loop
while True:
    clock.tick(60)

    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()
        elif event.type == KEYUP and event.key == K_ESCAPE:
 def load(cls, type):
     if type == SCRAMBLE:
         return textfx.shadow("? ?", 20, [255, 255, 255])
     else:
         fn = ["", "clear", "reverse", "flip", "blink", "gray"][type]
         return load.image("special-%s.png" % fn)
Exemplo n.º 10
0
    img = pyglet.image.load(f"swap/IMG_PIL_TO_GL_{h}.png")
    if mode == 0:
        img = img.get_texture()
        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                           gl.GL_NEAREST)
        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_NEAREST)
    remove(path)
    return img


def brightness(image, rate):
    return PILtoGL(ImageEnhance.Brightness(GLtoPIL(image)).enhance(rate))


def blur(image, radius=1):
    return PILtoGL(
        GLtoPIL(image).filter(ImageFilter.GaussianBlur(radius=radius)))


def scale(image, rate, mode=0):
    img = GLtoPygame(image)
    img = pygame.transform.scale(
        img, (img.get_width() * rate, img.get_height() * rate))
    return PygameToGL(img, mode=mode)


if __name__ == '__main__':
    import threading, load
    img = load.image("icon_32x32.png")
    threading.Thread(target=GLtoPygame, args=(img, )).start()
Exemplo n.º 11
0
def main():
    # load the icon to display up on the top left
    icon, icon_rect = load.image('cursor.bmp', WHITE)
    pygame.display.set_icon(icon)

    # pretty background
    background = pygame.Surface(screen.get_size())
    background.fill(WHITE)
    screen.blit(background, (0, 0))
    pygame.display.update()

    # construct some test game objects
    test1 = entities.Item('button_unpressed_green-240x60.bmp', grid_size)
    test2 = entities.Item('menu.bmp', grid_size)
    test3 = entities.Item('button_unpressed_red-52x60.bmp', grid_size)
    items = pygame.sprite.RenderUpdates((test1, test2, test3))
    for i in xrange(25):
        thing = entities.Item('button_unpressed_red-52x60.bmp', grid_size)
        items.add(thing)
    posdisplays = pygame.sprite.RenderUpdates()
    selections = pygame.sprite.RenderUpdates()
    clock = pygame.time.Clock()

    # dirty rects
    dirtyitems = []
    dirtyselections = []
    dirtypos = []
    dirtystats = []

    # FPS info
    fps = entities.TextFPS(clock, 24, BLACK)

    # dragbox
    selectbox = None

    # delays
    nudge_delay = 0

    # main loop
    while True:
        clock.tick(60)

        # ===============================================================
        # ------------------------- HOLDED KEYS -------------------------
        # ===============================================================

        if selections.sprites():
            if not nudge_delay:
                keys = pygame.key.get_pressed()
                result = []

                # ====================== MOVEMENTZ ======================
                if keys[K_LEFT] or keys[K_a]:
                    result.append('left')
                if keys[K_RIGHT] or keys[K_d]:
                    result.append('right')
                if keys[K_UP] or keys[K_w]:
                    result.append('up')
                if keys[K_DOWN] or keys[K_s]:
                    result.append('down')

                for item in selections.sprites():
                    item.ref.nudge = result

                nudge_delay = 3
            else:
                nudge_delay -= 1

        for e in pygame.event.get():
            # ===========================================================
            # -------------------- MOUSE BUTTON DOWN --------------------
            # ===========================================================
            if e.type == MOUSEBUTTONDOWN:
                nudge_delay = 3

                # ==================== LEFT CLICK ===================
                if e.button == 1:
                    keys = pygame.key.get_pressed()
                    ctrl = False
                    no_select = True
                    pos = pygame.mouse.get_pos()

                    if keys[K_LCTRL]:
                        ctrl = True

                    for item in reversed(items.sprites()):
                        if item.rect.collidepoint(pos):
                            load.selectbot(selections, posdisplays, item, ctrl)
                            no_select = False
                            break

                    if no_select:
                        selectbox = entities.SelectBox()

                # =================== RIGHT CLICK ===================
                if e.button == 3:
                    while True:
                        result = menu.right_click(['test', 'PIE'])

                        if not result:
                            break

            # ===========================================================
            # --------------------- MOUSE BUTTON UP ---------------------
            # ===========================================================
            elif e.type == MOUSEBUTTONUP:
                for item in selections.sprites():
                    item.ref.ungrab()

                if selectbox:
                    keys = pygame.key.get_pressed()
                    ctrl = False
                    result = []

                    for item in items.sprites():
                        if selectbox.rect.colliderect(item.rect):
                            result.append(item)

                    screen.blit(background, selectbox.rect, selectbox.rect)
                    selectbox = None

                    if keys[K_LCTRL]:
                        ctrl = True
                    load.selectbot(selections, posdisplays, result, ctrl)

            # ===========================================================
            # ------------------------- KEY DOWN ------------------------
            # ===========================================================
            elif e.type == KEYDOWN:

                # ====================== DELETE =====================
                if e.key == K_DELETE:
                    for item in selections.sprites():
                        item.ref.kill()

                    selections.empty()
                    posdisplays.empty()

                # ====================== ESCAPE =====================
                elif e.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()

            # ===========================================================
            # --------------------------- QUIT --------------------------
            # ===========================================================
            elif e.type == QUIT:
                pygame.quit()
                sys.exit()

        # clear necessary wizzles
        items.clear(screen, background)
        posdisplays.clear(screen, background)
        screen.blit(background, fps.rect, fps.rect)
        if selectbox:
            dirtystats = [selectbox.rect, None]
            screen.blit(background, selectbox.rect, selectbox.rect)

        items.update()
        posdisplays.update()
        selections.update()
        fps.update()

        dirtyitems = items.draw(screen)
        dirtyselections = selections.draw(screen)
        dirtypos = posdisplays.draw(screen)
        screen.blit(fps.image, fps.rect)
        if selectbox:
            selectbox.update()
            dirtystats[1] = selectbox.rect
            screen.blit(selectbox.image, selectbox.rect)

        # update
        pygame.display.update(dirtyitems)
        pygame.display.update(dirtypos)
        pygame.display.update(dirtyselections)
        pygame.display.update(dirtystats)
Exemplo n.º 12
0
if __name__ == '__main__':
    # Initialization
    pyglet.resource.path.append('.')
    load.font("assets/minecraft/Minecraftia.ttf")
    #
    window = Game(width=856,
                  height=482,
                  caption=f"Minecraft 2D v{version}",
                  resizable=True)
    pyglet.clock.schedule_interval(window.update, window.frame_rate)
    pyglet.clock.schedule_interval(window.cal_fps, 0.5)
    from Scenes.Initialization import Initialization

    window.set_minimum_size(128, 128)
    window.set_icon(
        load.image("assets/minecraft/textures/blocks/crafting_table_side.png"))
    window.scene = Initialization(window)
    try:
        pyglet.app.run()
    except Exception as e:
        log.err(f"Fatal Error: {e}")
        raise e

    log.info("Stopping Game")

    window.run = False
    log.info("Cleaning swap folder")
    for name in os.listdir("swap"):
        os.remove(f"swap/{name}")
    log.info("Game is stopped")