import pygame
import random
class diji1:
def __init__(self, screen):
self.name = "九品阴司"
self.hp =10
self.skin = pygame.image.load("alien_2.png")
self.x =random.randint(0,512-128)
self.y =0
self.ache = 0
self.speed = 3
self.screen = screen
def show(self):
self.screen.blit(self.skin, (self.x, self.y))
def down_yi_dong(self):
self.y += self.speed
class tianshi:
def __init__(self, screen):
self.name = "天师"
self.hp = 70
self.skin = pygame.image.load("hero.png").convert_alpha().subsurface(pygame.Rect(120, 0, 78, 87))
self.x = 88
self.y = 99
self.ache = 10
self.speed = 10
self.screen = screen
def show(self):
self.screen.blit(self.skin, (self.x, self.y))
def left_yi_dong(self):
self.x -= self.speed
if self.x < 0:
self.x = 0
def right_yi_dong(self):
self.x += self.speed
if self.x >512-78:
self.x = 512-78
def up_yi_dong(self):
self.y -= self.speed
if self.y < 0:
self.y = 0
def down_yi_dong(self):
self.y += self.speed
if self.y > 768-87:
self.y = 768-87
def key_kong_zhi(ts):
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
ts.left_yi_dong()
elif event.key == pygame.K_d:
ts.right_yi_dong()
elif event.key == pygame.K_w:
ts.up_yi_dong()
elif event.key == pygame.K_s:
ts.down_yi_dong()
def main():
pygame.init()
screen = pygame.display.set_mode((512, 768))
beijing = pygame.image.load("map1.jpg")
ts = tianshi(screen)
dj = []
for i in range(10):
dj.append(diji1(screen))
# 每过多少毫秒响应多少次
pygame.key.set_repeat(1, 1)
while True:
key_kong_zhi(ts)
screen.blit(beijing, (0, 0))
ts.show()
ys=0
for i in range(10):
dj[ys].show()
dj[ys].down_yi_dong()
ys=ys+1
pygame.display.update()
if __name__ == '__main__':
main()
xingtai -飞机大战3.0
最新推荐文章于 2024-03-17 18:02:24 发布