- 帖子
- 14
- 精华
- 0
- 积分
- 84
- 阅读权限
- 20
- 注册时间
- 2013-8-10
- 最后登录
- 2014-1-13
|
在今天内容的基础上增加一行子弹。ps:两行子弹真霸气- # !/usr/bin/python
- import pygame
- from sys import exit
- pygame.init()
- screen = pygame.display.set_mode((450, 800), 0, 32)
- pygame.display.set_caption("Hello, World!")
- bullet = pygame.image.load('bullet.png').convert_alpha() #load bullet image
- bullet1 = bullet
- backgroud = pygame.image.load('back.jpg').convert()
- plane = pygame.image.load('plane.png') #load plane image
- bullet_x = 0
- bullet_y = -1
- bullet1_x = 0
- bullet1_y = -1
- running = True
- while running:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- exit()
- screen.blit(backgroud, (0, 0))
- x, y = pygame.mouse.get_pos() # get the position of mouse
- 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 -= 3
- bullet1_y -= 3
- plane_x = x - plane.get_width() / 2
- plane_y = y - plane.get_height() / 2
- screen.blit(bullet, (bullet_x, bullet_y))
- screen.blit(bullet1, (bullet1_x, bullet1_y))
- screen.blit(plane, (plane_x, plane_y))
- pygame.display.update()
复制代码 |
|