- 帖子
- 20
- 精华
- 0
- 积分
- 166
- 阅读权限
- 20
- 注册时间
- 2018-10-15
- 最后登录
- 2019-4-13
|
- # !/usr/bin/python
- import pygame
- from sys import exit
- pygame.init()
- screen = pygame.display.set_mode((450,800),0,32)
- pygame.display.set_caption('plane')
- background = pygame.image.load('back.jpg').convert()
- plane = pygame.image.load('plane.png').convert_alpha()
- bullet = pygame.image.load('bullet.png').convert_alpha()
- bullet1=bullet
- #加载子弹图像
- width=plane.get_width()/2
- height=plane.get_height()/2
- bullet_x=0
- bullet_y=-1
- bullet1_x=0
- bullet1_y=-1
- #初始化子弹位置
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- exit()
- screen.blit(background, (0,0))
- x, y = pygame.mouse.get_pos()
- if bullet_y <0:
- #如果子弹位置超出了屏幕上端
- bullet_x = x - bullet.get_width() / 2 -23
- bullet_y = y - bullet.get_height() / 2
- bullet1_x = x - bullet.get_width() / 2 + 25
- bullet1_y = y - bullet.get_height() / 2
- #把子弹的中心位置设为鼠标坐标
- else:
- bullet_y -= 5
- bullet_y -= 5
- #子弹位置上移
- screen.blit(bullet,(bullet_x,bullet_y))
- screen.blit(bullet1,(bullet1_x,bullet1_y))
- #把子弹画到屏幕上
- if y>=800-height:
- if x<width:
- screen.blit(plane,(0,800-2*height))
- elif x>450-width:
- screen.blit(plane,(450-2*width,800-2*height))
- else:
- screen.blit(plane,(x-width,800-2*height))
- elif y<height:
- if x<width:
- screen.blit(plane,(0,0))
- elif x>450-width:
- screen.blit(plane,(450-2*width,0))
- else:
- screen.blit(plane,(x-width,0))
- else:
- if x<width:
- screen.blit(plane,(0,y-height))
- elif x>450-width:
- screen.blit(plane,(450-2*width,y-height))
- else:
- screen.blit(plane,(x-width,y-height))
- pygame.display.update()
复制代码 老师,为什么我左右两边的子弹的射速不一样,左边的快 |
|