示例#1
0
 def render(self, screen, pos):
     if self.animating:
         old_pixel_pos = Convert.world_to_pixels(self.old_pos)
         new_pixel_pos = Convert.world_to_pixels(self.pos)
         animation_ratio = 1 - (self.animation_stage / EntityPuzzlePiece.ANIMATION_MAX)
         difference = ((old_pixel_pos[0] - new_pixel_pos[0]) * animation_ratio,
                       (old_pixel_pos[1] - new_pixel_pos[1]) * animation_ratio)
         screen.blit(self.img, (pos[0] + difference[0], pos[1] + difference[1]))
     else:
         screen.blit(self.img, pos)
示例#2
0
文件: Game.py 项目: rystills/Oceania
def update():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            close()
        elif event.type == pygame.MOUSEBUTTONDOWN:
            if gamemode == MENU:
                menu.mouse_press()
            if gamemode == PLAYING:
                world.break_block(player, pygame.mouse.get_pos(), viewport)
        elif event.type == pygame.MOUSEBUTTONUP:
            if gamemode == MENU:
                menu.mouse_release()
        elif event.type == pygame.KEYDOWN:
            if pygame.key.get_pressed()[pygame.K_e]:
                global gui
                if gui is None:
                    gui = InventoryGUI.InventoryGUI(player)
                else:
                    gui = None
            if pygame.key.get_pressed()[pygame.K_F3]:
                global DEBUG
                DEBUG = not DEBUG
    pressed = pygame.key.get_pressed()
    if pressed[pygame.K_ESCAPE]:
        close()
    
    if gamemode == MENU:
        menu.update()
    
    elif gamemode == PLAYING:
        player.dir = [0, 0]
        if pressed[pygame.K_LEFT] or pressed[pygame.K_a]:
            player.dir[0] -= 1
        if pressed[pygame.K_RIGHT] or pressed[pygame.K_d]:
            player.dir[0] += 1
        if pressed[pygame.K_UP] or pressed[pygame.K_w]:
            player.dir[1] -= 1
        if pressed[pygame.K_DOWN] or pressed[pygame.K_s]:
            player.dir[1] += 1
        player.update(world)
        viewport.x = Convert.world_to_pixels(player.pos)[0] - SCREEN_WIDTH / 2 #replace with center
        viewport.y = Convert.world_to_pixels(player.pos)[1] - SCREEN_HEIGHT / 2
        world.update()
示例#3
0
def update():
    pressed = pygame.key.get_pressed()
    shift = pressed[pygame.K_LSHIFT] or pressed[pygame.K_RSHIFT]
    global gamemode
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            close()
        elif event.type == pygame.MOUSEBUTTONDOWN:
            if gamemode == MENU:
                menu.mouse_press()
            elif gamemode == PLAYING:
                if event.button == 1:
                    #left click
                    pass
                elif event.button == 2:
                    #scroll wheel click
                    pass
                elif event.button == 3:
                    #right click
                    player.right_click_discrete(world, pygame.mouse.get_pos(), viewport, shift)
                elif event.button == 4:
                    #scroll wheel up
                    player.change_slot(False)
                elif event.button == 5:
                    #scroll wheel down
                    player.change_slot(True)
            elif gamemode == OPENGUI:
                global gui
                gui.click(pygame.mouse.get_pos(), event.button, shift)
        
        elif event.type == pygame.MOUSEBUTTONUP:
            if gamemode == MENU:
                menu.mouse_release()
        elif event.type == pygame.KEYDOWN:
            #typed a key
            if gamemode == PLAYING:
                if event.key == pygame.K_e:
                    gui = InventoryGUI(player, "img/gui/inventory.png")
                    gamemode = OPENGUI
                if event.key == pygame.K_F3:
                    global DEBUG
                    DEBUG = not DEBUG
                if event.key == pygame.K_1:
                    player.selected_slot = 0
                if event.key == pygame.K_2:
                    player.selected_slot = 1
                if event.key == pygame.K_3:
                    player.selected_slot = 2
                if event.key == pygame.K_4:
                    player.selected_slot = 3
                if event.key == pygame.K_5:
                    player.selected_slot = 4
                if event.key == pygame.K_6:
                    player.selected_slot = 5
                if event.key == pygame.K_7:
                    player.selected_slot = 6
                if event.key == pygame.K_8:
                    player.selected_slot = 7
                if event.key == pygame.K_9:
                    player.selected_slot = 8
                if event.key == pygame.K_0:
                    player.selected_slot = 9
                if event.key == pygame.K_ESCAPE:
                    close()
            elif gamemode == OPENGUI:
                if event.key == pygame.K_e:
                    gui.close(world)
                    gui = None
                    gamemode = PLAYING
    
    if gamemode == MENU:
        menu.update()
    
    elif gamemode == PLAYING:
        player.dir = [0, 0]
        if pressed[pygame.K_LEFT] or pressed[pygame.K_a]:
            player.dir[0] -= 1
        if pressed[pygame.K_RIGHT] or pressed[pygame.K_d]:
            player.dir[0] += 1
        if pressed[pygame.K_UP] or pressed[pygame.K_w]:
            player.dir[1] -= 1
        if pressed[pygame.K_DOWN] or pressed[pygame.K_s]:
            player.dir[1] += 1
        mousebuttons = pygame.mouse.get_pressed()
        if mousebuttons[0]:
            player.break_block(world, pygame.mouse.get_pos(), viewport, shift)
        if mousebuttons[2]:
            player.right_click_continuous(world, pygame.mouse.get_pos(), viewport, shift)
        player.update(world)
        viewport.x = Convert.world_to_pixels(player.pos)[0] - SCREEN_WIDTH / 2
        viewport.y = Convert.world_to_pixels(player.pos)[1] - SCREEN_HEIGHT / 2
        world.update()