资源简介
基于Python、pygame的微信打飞机小游戏,由于这个是我自己写的,象征性地要1个资源分。另外还上传了网友贡献的微信打飞机小游戏源码,如果不想花积分的话可以去下那个。

代码片段和文件信息
# -*- coding: utf-8 -*-
import pygame
from myGameRole import *
# 导入按键的检测
from pygame.locals import *
import time
import random
if __name__ == ‘__main__‘:
# pygame初始化
pygame.init()
# 载入效果音乐
bullet_sound = pygame.mixer.Sound(‘resources/sound/bullet.wav‘)
enemy_down_sound = pygame.mixer.Sound(‘resources/sound/enemy1_down.wav‘)
game_over_sound = pygame.mixer.Sound(‘resources/sound/game_over.wav‘)
bullet_sound.set_volume(0.3)
enemy_down_sound.set_volume(0.3)
game_over_sound.set_volume(0.3)
# 载入游戏音乐并循环播放
pygame.mixer.music.load(‘resources/sound/game_music.wav‘)
pygame.mixer.music.play(-1 0)
pygame.mixer.music.set_volume(0.25)
# 创建窗口
screen = pygame.display.set_mode((SCREEN_WIDTH SCREEN_HEIGHT))
# 读出背景图片
background = pygame.image.load(‘resources/image/background.png‘).convert()
# 创建对象
playerPlane = Player(screen)
# 敌机列表
enemyList = []
# 敌机产生频率
enemy_frequency = 0
running_control = True
gameOverFlag = False
# 1.显示背景
while running_control:
screen.blit(background(0 0))
# 产生敌方飞机
if enemy_frequency % 50 == 0:
num = random.randint(0 SCREEN_WIDTH - 51)
enemy = Enemy(screen num)
enemyList.append(enemy)
enemy_frequency += 1
if enemy_frequency >= 100:
enemy_frequency = 0
# 判断按键
for event in pygame.event.get():
if event.type == QUIT:
print(‘exit‘)
exit()
elif event.type == KEYDOWN:
if event.key == K_a or event.key == K_LEFT:
# print(‘left‘)
playerPlane.keyHandle(‘left‘)
elif event.key == K_d or event.key == K_RIGHT:
# print(‘right‘)
playerPlane.keyHandle(‘right‘)
elif event.key == K_w or event.key == K_UP:
# print(‘up‘)
playerPlane.keyHandle(‘up‘)
elif event.key == K_s or event.key == K_DOWN:
# print(‘down‘)
playerPlane.keyHandle(‘down‘)
elif event.key == K_SPACE:
# print(‘space‘)
playerPlane.keyHandle(‘space‘)
bullet_sound.play()
# print(len(playerPlane.bulletList))
# 这里只是用于检测敌机的状态,如果出界就直接移除,如果被子弹打中就执行爆炸效果随后与子弹一起移除
# 还有一点,图片刷新不能与此同时进行,会有一顿一顿的感觉,所以只在执行爆炸效果时进行刷新,最后统一刷新
for enemy in enemyList:
enemy.move()
if enemy.checkOut():
enemyList.remove(enemy)
continue
x1y1w1h1 = enemy.getPos()
for bullet in playerPlane.bulletList:
x2y2w2h2 = bullet.getPos()
if (x2 + w2 // 2) >= x1 and (x2 + w2 // 2) <= (x1 + w1):
if y2 <= (y1 + h1):
enemy.crash()
playerPlane.bulletList.remove(bullet)
enemyList.remove(enemy)
enemy.draw()
enemy_down_sound.play()
break
x3y3w3h3 = playerPlane.getPos()
if (x1 + w1 // 2) >= x3 and (x1 + w1 // 2) <= (x3 + w3):
if y3 <= (y1 + h1):
# playerPlane.crash()
# # 更新飞机图片
# playerPlane.draw()
# running_control = False
# break
gameOverFlag = True
for enemy in enemyList:
enemy.draw()
# 子弹移动,更新图片
for bullet in playerPlane.bulletList:
bullet.move()
bullet.draw()
# 清楚发射到顶部的子弹
playerPlane.bulletClear()
if gameOverFlag == True:
playerPlane.cra
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-06-19 22:28 MyPythonGame\
文件 3879 2017-06-19 07:10 MyPythonGame\myGame.py
文件 3583 2017-06-19 05:59 MyPythonGame\myGameRole.py
文件 6346 2017-06-19 06:05 MyPythonGame\myGameRole.pyc
目录 0 2017-06-19 22:28 MyPythonGame\resources\
目录 0 2017-06-19 22:28 MyPythonGame\resources\image\
文件 36620 2017-06-18 21:54 MyPythonGame\resources\image\background.png
文件 5570 2017-06-18 21:54 MyPythonGame\resources\image\bomb.png
文件 8944 2017-06-18 21:54 MyPythonGame\resources\image\btn_finish.png
文件 486 2017-06-18 21:54 MyPythonGame\resources\image\bullet1.png
文件 485 2017-06-18 21:54 MyPythonGame\resources\image\bullet2.png
文件 2968 2017-06-18 21:54 MyPythonGame\resources\image\enemy1.png
文件 3365 2017-06-18 21:54 MyPythonGame\resources\image\enemy1_down1.png
文件 3815 2017-06-18 21:54 MyPythonGame\resources\image\enemy1_down2.png
文件 5239 2017-06-18 21:54 MyPythonGame\resources\image\enemy1_down3.png
文件 1723 2017-06-18 21:54 MyPythonGame\resources\image\enemy1_down4.png
文件 8112 2017-06-18 21:54 MyPythonGame\resources\image\enemy2.png
文件 10408 2017-06-18 21:54 MyPythonGame\resources\image\enemy2_down1.png
文件 11562 2017-06-18 21:54 MyPythonGame\resources\image\enemy2_down2.png
文件 13310 2017-06-18 21:54 MyPythonGame\resources\image\enemy2_down3.png
文件 3356 2017-06-18 21:54 MyPythonGame\resources\image\enemy2_down4.png
文件 9126 2017-06-18 21:54 MyPythonGame\resources\image\enemy2_hit.png
文件 47800 2017-06-18 21:54 MyPythonGame\resources\image\enemy3_down1.png
文件 53349 2017-06-18 21:54 MyPythonGame\resources\image\enemy3_down2.png
文件 60269 2017-06-18 21:54 MyPythonGame\resources\image\enemy3_down3.png
文件 66517 2017-06-18 21:54 MyPythonGame\resources\image\enemy3_down4.png
文件 75014 2017-06-18 21:54 MyPythonGame\resources\image\enemy3_down5.png
文件 8722 2017-06-18 21:54 MyPythonGame\resources\image\enemy3_down6.png
文件 45497 2017-06-18 21:54 MyPythonGame\resources\image\enemy3_hit.png
文件 42482 2017-06-18 21:54 MyPythonGame\resources\image\enemy3_n1.png
文件 42572 2017-06-18 21:54 MyPythonGame\resources\image\enemy3_n2.png
............此处省略47个文件信息
相关资源
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
- python 名字用字排行
评论
共有 条评论