我无法在 Pygame 中获取我的对象来改变我的代码方向。
import pygame
pygame.init()
width = 900
height = 700
background_image = pygame.image.load("board.png")
background_image = pygame.transform.scale(background_image, (900, 700))
virus_pic = pygame.image.load("virus.png")
trojanvirus_pic = pygame.image.load("trojan_virus.png")
armouredvirus_pic = pygame.image.load("armoured_virus.png")
antivirus_pic = pygame.image.load("antivirus.png")
trojanantivirus_pic = pygame.image.load("trojan_antivirus.png")
armouredantivirus_pic = pygame.image.load("armoured_antivirus.png")
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Anti Virus")
#def anitvirus():
def virus(x_virus,y_virus):
screen.blit(virus_pic, (x_virus, y_virus))
def intro():
background_image = pygame.image.load("intro_background.png")
background_image = pygame.transform.scale(background_image, (900, 700))
logo_image = pygame.image.load("logo.png")
logo_image = pygame.transform.scale(logo_image, (600, 200))
pygame.display.update()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
main()
screen.blit(background_image, (0, 0))
screen.blit(logo_image, (width/2-300,100))
pygame.display.update()
def main():
x_virus = 0
y_virus = 70
pygame.display.update()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
screen.blit(background_image, (0, 0))
if x_virus != 320:
x_virus += 1
virus(x_virus,y_virus)
这是进行游戏移动的代码^
pygame.display.update()
intro()
我不知道是否所有的 if 语句都是最有效的方法。我尝试了不同的东西,但 if 语句似乎在大多数情况下都有效。我将不胜感激任何帮助。谢谢。
侃侃无极
相关分类