示例#1
0
 def __init__(self, image, position, direction, speed):
     pygame.sprite.Sprite.__init__(self)
     self.src_image = load_image(image)
     self.position = position
     self.direction = direction
     self.speed = speed + 10
     self.rect = self.src_image.get_rect()
示例#2
0
 def __init__(self, image, position, direction, speed):
     pygame.sprite.Sprite.__init__(self)
     self.src_image = load_image(image)
     self.position = position
     self.direction = direction
     self.speed = speed + 10
     self.rect = self.src_image.get_rect()
示例#3
0
 def __init__(self, image, position):
     pygame.sprite.Sprite.__init__(self)
     self.src_image = self.image = load_image(image)
     self.position = position
     self.x, self.y = position
     self.direction = self.speed = 0
     self.k_left = self.k_right = self.k_down = self.k_up = 0
     self.rect = self.src_image.get_rect()
示例#4
0
 def __init__(self, image, position):
     pygame.sprite.Sprite.__init__(self)
     self.src_image = self.image = load_image(image)
     self.position = position
     self.x, self.y = position
     self.direction = self.speed = 0
     self.k_left = self.k_right = self.k_down = self.k_up = 0
     self.rect = self.src_image.get_rect()
示例#5
0
def run_game():
    # Game parameters
    WINDOW_HEIGHT, WINDOW_WIDTH = 640, 480
    pygame.init()
    screen = pygame.display.set_mode((WINDOW_HEIGHT, WINDOW_WIDTH))

    pygame.display.set_caption('Zombie survival')
    pygame.mouse.set_visible(1)

    rect = screen.get_rect()
    position = rect.center

    pygame.mouse.set_cursor((8, 8), (4, 4), (24, 24, 24, 231, 231, 24, 24, 24), (0, 0, 0, 0, 0, 0, 0, 0))

    # Prepare objects
    player = Player('bluecreep.bmp', position)
    running = True

    # Create The Backgound
    background = load_image("background.bmp")
    backgroundRect = background.get_rect()

    # Display The Background
    pygame.display.flip()
    clock = pygame.time.Clock()
    #
    # The main game loop
    #
    while running:
        clock.tick(30)
        for event in pygame.event.get():

            if event.type == pygame.QUIT:
                running = False

            if not hasattr(event, 'key'):
                continue
            if event.key == K_ESCAPE:
                sys.exit(0)
            down = event.type == KEYDOWN

            # Arrow keys
            if event.key == K_RIGHT:
                player.k_right = down * -10
            elif event.key == K_LEFT:
                player.k_left = down * 10
            elif event.key == K_UP:
                player.k_up = down * 2
            elif event.key == K_DOWN:
                player.k_down = down * -2

            # WSAD
            elif event.key == K_w:
                player.k_up = down * 2
            elif event.key == K_s:
                player.k_down = down * -2
            elif event.key == K_d:
                player.k_right = down * -10
            elif event.key == K_a:
                player.k_left = down * 10

        screen.blit(background, backgroundRect)
        screen.blit(player.image, (player.x, player.y))
        pygame.display.flip()
        player.update()
示例#6
0
def run_game():
    # Game parameters
    WINDOW_HEIGHT, WINDOW_WIDTH = 640, 480
    pygame.init()
    screen = pygame.display.set_mode((WINDOW_HEIGHT, WINDOW_WIDTH))

    pygame.display.set_caption('Zombie survival')
    pygame.mouse.set_visible(1)

    rect = screen.get_rect()
    position = rect.center

    pygame.mouse.set_cursor((8, 8), (4, 4), (24, 24, 24, 231, 231, 24, 24, 24),
                            (0, 0, 0, 0, 0, 0, 0, 0))

    # Prepare objects
    player = Player('bluecreep.bmp', position)
    running = True

    # Create The Backgound
    background = load_image("background.bmp")
    backgroundRect = background.get_rect()

    # Display The Background
    pygame.display.flip()
    clock = pygame.time.Clock()
    #
    # The main game loop
    #
    while running:
        clock.tick(30)
        for event in pygame.event.get():

            if event.type == pygame.QUIT:
                running = False

            if not hasattr(event, 'key'):
                continue
            if event.key == K_ESCAPE:
                sys.exit(0)
            down = event.type == KEYDOWN

            # Arrow keys
            if event.key == K_RIGHT:
                player.k_right = down * -10
            elif event.key == K_LEFT:
                player.k_left = down * 10
            elif event.key == K_UP:
                player.k_up = down * 2
            elif event.key == K_DOWN:
                player.k_down = down * -2

            # WSAD
            elif event.key == K_w:
                player.k_up = down * 2
            elif event.key == K_s:
                player.k_down = down * -2
            elif event.key == K_d:
                player.k_right = down * -10
            elif event.key == K_a:
                player.k_left = down * 10

        screen.blit(background, backgroundRect)
        screen.blit(player.image, (player.x, player.y))
        pygame.display.flip()
        player.update()