- 帖子
- 4
- 精华
- 0
- 积分
- 20
- 阅读权限
- 10
- 注册时间
- 2018-2-19
- 最后登录
- 2018-2-24
|
- import pygame
- from sys import exit
- class Bullet():
- def __init__(self):
- self.x=0
- self.y=-1
- self.image=pygame.image.load('bullet.png').convert_alpha()
- self.width=self.image.get_width()/2
- self.height=self.image.get_height()/2
- def move(self):
- if self.y<0:
- mouse_x,mouse_y=pygame.mouse.get_pos()
- self.x=mouse_x-self.width
- self.y=mouse_y-self.height
- else:
- self.y-=5
- class Plane():
- def __init__(self):
- self.image=pygame.image.load('plane.png').convert_alpha()
- self.width = self.image.get_width() / 2
- self.height = self.image.get_height() / 2
- def postion(self):
- mouse_x, mouse_y = pygame.mouse.get_pos()
- x = mouse_x - self.width
- y = mouse_y - self.height
- return (x,y)
- pygame.init()
- screen=pygame.display.set_mode((450,600),0,32)
- pygame.display.set_caption('飞机大战')
- background=pygame.image.load('back.jpg')
- bullet=Bullet()
- plane=Plane()
- while True:
- for event in pygame.event.get():
- if event.type==pygame.QUIT:
- pygame.quit()
- exit()
- screen.blit(background,(0,0))
- bullet.move()
- plane.postion()
- screen.blit(bullet.image,(bullet.x,bullet.y))
- screen.blit(plane.image,plane.postion())
- pygame.display.update()
复制代码 |
|