如何在随机的y位置上放大图像? Pygame

时间:2018-12-02 11:59:46

标签: python python-3.x pygame

所以我需要为我的游戏将我的礼物精灵变成随机的y坐标,我已经尝试了很长时间了,但我做对了。我是编程的一个新手,所以我希望这里的人可以帮助我。我需要上课吗?

代码:

import pygame
import random

pygame.init()

clock = pygame.time.Clock()
pygame.display.set_caption("Santa Dash!")
win = pygame.display.set_mode((1200, 800))
gift = pygame.image.load("gift1.png")
santa = [pygame.image.load("santa1.png").convert_alpha(), pygame.image.load("santa2.png").convert_alpha()]
map = pygame.image.load("santadashmap.png").convert_alpha()
x = 100
y = 500
vel = 5
gift_x = 1000
gift_vel = 10

# --Animation count--
santacount = 1

# --Gameloop--
run = True
while run:

    # --Sets the santa animation speed--
    clock.tick(120)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    # --Player Movement--
    keys = pygame.key.get_pressed()

    if keys[pygame.K_w] and vel <= y:
        y -= vel
    if keys[pygame.K_s] and y < 740 - 120:
        y += vel
    if keys[pygame.K_a] and vel <= x:
        x -= vel
    if keys[pygame.K_d] and x < 1200 - 240:
        x += vel

    # --Santa Animation--
    if santacount == 0:
        win.blit(map, (0, 0))
        win.blit(santa[0], (x, y))
        santacount += 1
    else:
        win.blit(map, (0, 0))
        win.blit(santa[1], (x, y))
        santacount -= 1

    pygame.display.update()

我非常感谢我能提供的帮助。

0 个答案:

没有答案
相关问题