- 帖子
- 12
- 精华
- 0
- 积分
- 101
- 阅读权限
- 20
- 注册时间
- 2013-10-17
- 最后登录
- 2015-12-3
|
两弹齐发。。- # -*- coding: utf-8 -*-
- import pygame
- from sys import exit
- pygame.init()
- screen = pygame.display.set_mode((450, 600), 0, 32)
- background = pygame.image.load("back.jpg").convert()
- plane = pygame.image.load("plane.png").convert_alpha()
- pygame.display.set_icon(plane)
- pygame.display.set_caption("打飞机")
- class Bullet:
- def __init__(self):
- #初始化成员变量,x,y,image
- self.x = 0
- self.y = -1
- self.image = pygame.image.load('bullet.png').convert_alpha()
- def move(self):
- #处理子弹的运动
- if self.y < 0:
- mouseX, mouseY = pygame.mouse.get_pos()
- self.x = mouseX - self.image.get_width() / 2
- self.y = mouseY - self.image.get_height() / 2
- else:
- self.y -= 5
- bullet = Bullet()
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- exit()
- bullet.move()
- x, y = pygame.mouse.get_pos()
- x -= plane.get_width() / 2
- y -= plane.get_height() / 2
- screen.blit(background, (0,0))
- screen.blit(bullet.image, (bullet.x-23, bullet.y))
- screen.blit(bullet.image, (bullet.x+25, bullet.y))
- screen.blit(plane, (x,y))
- pygame.display.update()
复制代码 |
|