- 帖子
- 48
- 精华
- 0
- 积分
- 200
- 阅读权限
- 30
- 注册时间
- 2015-12-5
- 最后登录
- 2016-5-12
|
- # -*- coding: utf-8 -*-
- import pygame
- from sys import exit
- pygame.init()
- screen = pygame.display.set_mode((450,800),0,32)
- pygame.display.set_caption('Hello World')
- #加载需要的图片
- background = pygame.image.load('f:\plane\some.jpg')
- plane = pygame.image.load('f:\plane\plane.png').convert_alpha()
- bullet = pygame.image.load('f:\plane\sullet.png')
- #初始化子弹位置
- bullet_x = 0
- bullet_y = -1
- bullet_left_x = 0
- bullet_left_y = -1
- bullet_right_x = 0
- bullet_right_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()
-
- #获取左、右两个子弹起始点位置
- left_x = x - plane.get_width() / 3
- left_y = y
- right_x = x + plane.get_width() / 3
- right_y = y
-
- if bullet_y < 0:
- bullet_x = x - bullet.get_width() / 2
- bullet_y = y - bullet.get_height() / 2
- #把子弹图片的中心设置为鼠标坐标
- else:
- bullet_y -= 5
- if bullet_left_y < 0:
- bullet_left_x = left_x - bullet.get_width() / 2
- bullet_left_y = left_y - bullet.get_height() / 2
- else:
- bullet_left_y -= 5
- if bullet_right_y < 0:
- bullet_right_x = right_x - bullet.get_width() / 2
- bullet_right_y = right_y - bullet.get_height() / 2
- else:
- bullet_right_y -= 5
-
- #加载3个子弹图片
- screen.blit(bullet,(bullet_x,bullet_y))
- screen.blit(bullet,(bullet_left_x,bullet_left_y))
- screen.blit(bullet,(bullet_right_x,bullet_right_y))
-
- #把飞机图片的中心设置为鼠标坐标
- x-= plane.get_width() / 2
- y-= plane.get_height() / 2
- screen.blit(plane,(x,y))
- pygame.display.update()
复制代码 |
|