python实现微信打飞机游戏(by crossin)
# -*- coding: utf-8 -*- import pygame
from sys import exit
import random 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 Enemy:
def restart(self):
#重置敌机位置和速度
self.x = random.randint(50, 400)
self.y = random.randint(-200, -50)
self.speed = random.random() + 0.1 def __init__(self):
#初始化
self.restart()
self.image = pygame.image.load('enemy.png').convert_alpha() def move(self):
if self.y < 600:
#向下移动
self.y += 0.3
else:
#重置
self.restart()
#enemy = Enemy()
enemies = []
for i in range(3):
enemies.append(Enemy()) class Bullet:
def __init__(self):
#初始化成员变量,x,y,image
self.x = 0
self.y = -1
self.image = pygame.image.load('bullet.png').convert_alpha()
self.active = False
def restart(self):
mouseX, mouseY = pygame.mouse.get_pos()
self.x = mouseX - self.image.get_width() / 2
self.y = mouseY - self.image.get_height() /2
self.active = True
def move(self):
#处理子弹的运动
if self.y < 0:
self.active = False
if self.active:
self.y -= 3
#创建子弹的list
bullets = []
#向list中添加5发子弹
for i in range(5):
bullets.append(Bullet())
#子弹总数
count_b = len(bullets)
#即将激活的子弹序号
index_b = 0
#发射子弹的间隔
interval_b = 0 class Plane:
def restart(self):
self.x = 200
self.y = 600 def __init__(self):
self.restart()
self.image = pygame.image.load('plane.png').convert_alpha() def move(self):
x, y = pygame.mouse.get_pos()
x-= self.image.get_width() / 2
y-= self.image.get_height() / 2
self.x = x
self.y = y plane = Plane()
bullet = Bullet()
enemy = Enemy()
def checkHit(enemy, bullet):
if (bullet.x > enemy.x and bullet.x < enemy.x + enemy.image.get_width()) and (bullet.y > enemy.y and bullet.y < enemy.y + enemy.image.get_height()):
enemy.restart()
bullet.active = False
return True
return False def checkCrash(enemy, plane):
if (plane.x + 0.7*plane.image.get_width() > enemy.x) and (plane.x + 0.3*plane.image.get_width() < enemy.x + enemy.image.get_width()) and (plane.y + 0.7*plane.image.get_height() > enemy.y) and (plane.y + 0.3*plane.image.get_height() < enemy.y + enemy.image.get_height()):
return True
return False gameover = False
score = 0
Hscore = []
font = pygame.font.SysFont('楷体', 16)
text1 = font.render(u"点击鼠标左键重新开始", 1, (0, 0, 0)) while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
#判断在gameover状态下点击了鼠标
if gameover and event.type == pygame.MOUSEBUTTONUP:
#重置游戏
plane.restart()
for e in enemies:
e.restart()
for b in bullets:
b.active = False
score = 0
gameover = False
screen.blit(background, (0,0))
if not gameover:
interval_b -= 1
if interval_b < 0:
bullets[index_b].restart()
interval_b = 100
index_b = (index_b+1) % count_b
for b in bullets:
if b.active:
for e in enemies:
if checkHit(e, b):
score += 100
if checkCrash(e, plane):
gameover = True b.move()
screen.blit(b.image, (b.x-23, b.y))
screen.blit(b.image, (b.x+25, b.y))
for e in enemies:
e.move()
screen.blit(e.image, (e.x, e.y))
plane.move()
screen.blit(plane.image, (plane.x, plane.y))
text = font.render("Socre:%d" % score, 1, (0, 0, 0))
screen.blit(text, (0, 0))
else:
screen.blit(text, (0, 0))
screen.blit(text1,(100,32))
Hscore.append(score)
text2 = font.render(u"HScore:%d" % sorted(Hscore)[-1], 1, (0, 0, 0))
screen.blit(text2, (250, 0))
pass
pygame.display.update()
python实现微信打飞机游戏(by crossin)的更多相关文章
- python实现微信打飞机游戏
环境:Ubuntu 16.04 LTS Python 2.7.11 + Pygame + Pycharm 代码: # -*- coding: UTF-8 -*- import pygame, ran ...
- pygame开发PC端微信打飞机游戏
pygame开发PC端微信打飞机游戏 一.项目简介 1. 介绍 本项目类似曾经火爆的微信打飞机游戏.游戏将使用Python语言开发,主要用到pygame的API.游戏最终将会以python源文件gam ...
- Pygame制作微信打飞机游戏PC版
使用Pygame制作微信打飞机游戏PC版 转至:http://www.cnblogs.com/dukeleo/p/3339780.html 前一阵子看了一篇文章:青少年如何使用Python开始游戏 ...
- 实例源码--IOS高仿微信打飞机游戏(完整功能)
下载源码 技术要点: 1. IOS游戏开发基础框架 2. 高仿打飞机游戏 3. 游戏背景音频技术 4.源码详细的中文注释 ……. 详细介绍: 1. IOS游戏开发基础框架 此套源码为涉及IOS游戏开发 ...
- 利用python实现微信小程序游戏跳一跳详细教程
利用python实现微信小程序游戏跳一跳详细教程 1 先安装python 然后再安装pip <a href="http://newmiracle.cn/wp-content/uploa ...
- 使用Pygame制作微信打飞机游戏PC版
前一阵子看了一篇文章:青少年如何使用Python开始游戏开发 .看完照葫芦画瓢写了一个,觉得挺好玩儿,相当于简单学了下Pygame库.这篇文章是个12岁小孩儿写的,国外小孩儿真心NB,想我12岁的时候 ...
- <Win32_20>纯c语言版的打飞机游戏出炉了^_^
经过昨天的苦战,终于完成了纯C版的打飞机游戏——使用微信打飞机游戏的素材,不过玩法有些不同,下面会有详述 一.概述游戏的玩法.实现效果 1. 游戏第一步,简单判断一下,给你一个准备的时间: 2.选择& ...
- python 之路,200行Python代码写了个打飞机游戏!
早就知道pygame模块,就是没怎么深入研究过,恰逢这周未没约到妹子,只能自己在家玩自己啦,一时兴起,花了几个小时写了个打飞机程序. 很有意思,跟大家分享下. 先看一下项目结构 "" ...
- Android原生游戏开发:使用JustWeEngine开发微信打飞机
使用JustWeEngine开发微信打飞机: 作者博客: 博客园 引擎地址:JustWeEngine 示例代码:EngineDemo JustWeEngine? JustWeEngine是托管在Git ...
随机推荐
- 2.1-2.2 HBase数据存储
一.HBase数据检索流程 一篇介绍HBase数据读写流程的解析的博文:http://hbasefly.com/2016/12/21/hbase-getorscan/?wsfatm=uqvhl3 1. ...
- 【Hadoop】HDFS笔记(三):HDFS的Shell操作
HDFS处理文件的命令和Linux命令差不多,但注意区分大小写. (Linux区分大小写,Windows不区分大小写) 一.fs命令 键入命令"./bin/hadoop fs"将输 ...
- 20个Flutter实例视频教程-第05节: 酷炫的路由动画-1
视屏地址: https://www.bilibili.com/video/av39709290/?p=5 博客地址: https://jspang.com/post/flutterDemo.html# ...
- Linux 静态库 & 动态库
转自:http://blog.chinaunix.net/uid-26833883-id-3219335.html 一.什么是库 本质上来说库是一种可执行代码的二进制形式,可以被操作系统载入内存执 ...
- HDU - 1241 POJ - 1562 Oil Deposits DFS FloodFill漫水填充法求连通块问题
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil de ...
- GcSpreadSheet自定义Tab键选择
最开始的时候需要在GcSpreadSheet中按Tab在需要输入的cell中切换,在模板中定义Tab的切换规则:后来又有一个新的要求,因为在使用的时候会出现数据不平的情况,这个时候需要在标记中的不平数 ...
- lightoj1066【BFS】
题意: 就是按照A->B->C->D....去拿,求步数: 思路: 有一个注意点:如果碰到合法字母吃掉,再以后的某次可以重新到改点: BFS的因为标记而减少了重复位置的到达,但是按照 ...
- DMOJ IOI '17 P3 - Toy Train【拓扑排序】
传送:https://dmoj.ca/problem/ioi17p3 参考:https://blog.csdn.net/qq_27327327/article/details/80711824 妙啊- ...
- hyperledger fabric 1.0.5 分布式部署 (七)
fabric 使用 fabric-ca 服务 准备部分 首先需要用户从github上download fabric-ca 的工程代码 cd $GOPATH/src/github.com/hyperle ...
- 应用日志获取-web系统
1 场景 应用使开发写的,但应用使部署再服务器上,而开发没有ssh登陆服务器的权限. so,开发总是请运维查日志,下载日志. so and so,运维要花很多时间帮开发去搞日志. 这是件很没意义的事, ...