from pygame.locals import *
import pygame
from sys import exit
bg_img = './sources/background.png'
obj = './sources/bullet.png'
pygame.init()
screen = pygame.display.set_mode((480,852),0,32)
background = pygame.image.load(bg_img).convert()
one_obj = pygame.image.load(obj).convert_alpha()
pygame.key.set_repeat(3, 50)
x = 0
y = 0
def move_right_down():
global x
global y
x += 4
y += 4
def move_right_up():
global x
global y
x +=4
y -=4
def move_down():
global y
y +=4
def move_up():
global y
y -=4
def move_left():
global x
x -=4
def move_right():
global x
x +=4
def move_left_down():
global x
global y
x -=4
y +=4
def move_left_up():
global x
global y
x +=4
y -=4
while True:
keys = pygame.key.get_pressed()
screen.blit(background,(0,0))
screen.blit(one_obj,(x,y))
for event in pygame.event.get():
if event.type == QUIT:
exit()
elif keys[pygame.K_RIGHT]:
move_right()
elif keys[pygame.K_UP]:
move_up()
elif keys[pygame.K_DOWN]:
pygame 探索_斜着运动的方法
最新推荐文章于 2022-09-01 22:11:44 发布