环境:Ubuntu 16.04 LTS

Python 2.7.11 +  Pygame + Pycharm

代码:

 # -*- coding: UTF-8 -*-
import pygame, random
from sys import exit 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 class Enemy:
def start(self):
self.speed = random.random() + 0.1
self.x = random.randint(0, 450)
self.y = 0 def __init__(self):
self.start()
self.image = pygame.image.load('enemy.png').convert_alpha() def move(self):
if self.y < 800:
self.y += self.speed
if self.y > 800:
self.start() class Bullet:
def __init__(self):
self.x = 0
self.y = 0
self.image = pygame.image.load('bullet.png').convert_alpha()
self.active = False def move(self):
if self.active:
self.y -= 3
if self.y < 0:
self.active = False def start(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 Shoot(bullet, enemy):
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()):
bullet.active = False
enemy.start()
return True
else:
return False def Crash(plane, enemy):
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
else:
return False pygame.init()
screen = pygame.display.set_mode((450, 800), 0, 32)
pygame.display.set_caption('World of plane craft')
bg = pygame.image.load('bg.jpg').convert_alpha()
bullet = Bullet()
bullets = []
for i in range(5):
bullets.append(bullet)
count_b = len(bullets)
index_b = 0
interval_b = 0 enemy = Enemy()
enemys = []
for i in range(5):
enemys.append(enemy) plane = Plane()
gameover = False
score = 0
font = pygame.font.Font(None, 32)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
if gameover and event.type == pygame.MOUSEBUTTONUP:
plane.restart()
for e in enemys:
e.start()
for b in bullets:
b.active = False
score = 0
gameover = False
screen.blit(bg, (0, 0))
if not gameover:
interval_b -= 1
if interval_b < 0:
bullets[index_b].start()
interval_b = 100
index_b = (index_b + 1) % count_b
for b in bullets:
if b.active:
for e in enemys:
if Shoot(b, e):
score += 100
b.move()
screen.blit(b.image, (b.x, b.y)) for e in enemys:
if Crash(plane, e):
gameover = True
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:
text = font.render("Socre : %d" % score, 1, (0, 0, 0))
screen.blit(text, (150, 300))
text = font.render("Click mouse and restart", 1, (0, 0, 0))
screen.blit(text, (100, 330))
pygame.display.update()

运行所需图片:

python实现微信打飞机游戏的更多相关文章

  1. python实现微信打飞机游戏(by crossin)

    # -*- coding: utf-8 -*- import pygame from sys import exit import random pygame.init() screen = pyga ...

  2. pygame开发PC端微信打飞机游戏

    pygame开发PC端微信打飞机游戏 一.项目简介 1. 介绍 本项目类似曾经火爆的微信打飞机游戏.游戏将使用Python语言开发,主要用到pygame的API.游戏最终将会以python源文件gam ...

  3. Pygame制作微信打飞机游戏PC版

    使用Pygame制作微信打飞机游戏PC版 转至:http://www.cnblogs.com/dukeleo/p/3339780.html   前一阵子看了一篇文章:青少年如何使用Python开始游戏 ...

  4. 实例源码--IOS高仿微信打飞机游戏(完整功能)

    下载源码 技术要点: 1. IOS游戏开发基础框架 2. 高仿打飞机游戏 3. 游戏背景音频技术 4.源码详细的中文注释 ……. 详细介绍: 1. IOS游戏开发基础框架 此套源码为涉及IOS游戏开发 ...

  5. 利用python实现微信小程序游戏跳一跳详细教程

    利用python实现微信小程序游戏跳一跳详细教程 1 先安装python 然后再安装pip <a href="http://newmiracle.cn/wp-content/uploa ...

  6. 使用Pygame制作微信打飞机游戏PC版

    前一阵子看了一篇文章:青少年如何使用Python开始游戏开发 .看完照葫芦画瓢写了一个,觉得挺好玩儿,相当于简单学了下Pygame库.这篇文章是个12岁小孩儿写的,国外小孩儿真心NB,想我12岁的时候 ...

  7. <Win32_20>纯c语言版的打飞机游戏出炉了^_^

    经过昨天的苦战,终于完成了纯C版的打飞机游戏——使用微信打飞机游戏的素材,不过玩法有些不同,下面会有详述 一.概述游戏的玩法.实现效果 1. 游戏第一步,简单判断一下,给你一个准备的时间: 2.选择& ...

  8. python 之路,200行Python代码写了个打飞机游戏!

    早就知道pygame模块,就是没怎么深入研究过,恰逢这周未没约到妹子,只能自己在家玩自己啦,一时兴起,花了几个小时写了个打飞机程序. 很有意思,跟大家分享下. 先看一下项目结构 "" ...

  9. Android原生游戏开发:使用JustWeEngine开发微信打飞机

    使用JustWeEngine开发微信打飞机: 作者博客: 博客园 引擎地址:JustWeEngine 示例代码:EngineDemo JustWeEngine? JustWeEngine是托管在Git ...

随机推荐

  1. GCC编译器代码优化

    代码优化是指编译器通过分析源代码,找出其中尚未达到最优的部分,然后对其重新进行组合,目的是改善程序的执行性能.GCC提供的代码优化功能非常强大,它通过编译选项-On来控制优化代码的生成,其中n是一个代 ...

  2. Get_File_Name Usage in Oracle Forms 6i

    Get_File_Name is built-in function of Oracle Forms 6i, used to get the file name with address by bro ...

  3. Using GET_GROUP_SELECTION For Record Groups in Oracle Forms

    Retrieves the sequence number of the selected row for the given group. Suppose you want to get a par ...

  4. python 列表去重(数组)的几种方法

    一.方法1  代码如下 复制代码 ids = [1,2,3,3,4,2,3,4,5,6,1] news_ids = [] for id in ids:     if id not in news_id ...

  5. 多命令顺序执行、管道符 ; && || |

    多命令顺序执行:

  6. 线程入门之start()和run()的区别

    package com.thread; /** * start()和run()的区别 * start():并行执行 * run():方法调用,顺序执行 * @author 95Yang */ publ ...

  7. CSS笔记(一)CSS规则

    CSS是层叠式样式表(Cascading Style Sheets)的缩写,定义了如何显示HTML元素. CSS规则由两个主要的部分构成:选择器 + 一条或多条声明. 每条声明由一个属性和一个值构成. ...

  8. EntityManager方法简介

    EntityManager 是用来对实体Bean 进行操作的辅助类.他可以用来产生/删除持久化的实体Bean,通过主键查找实体bean,也可以通过EJB3 QL 语言查找满足条件的实体Bean.实体B ...

  9. Java JDBC连接数据库 Access连接数据库

    1.加载JDBC驱动程序:  在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机),再通过java.lang.Class类的静态方法forName(String  classN ...

  10. Python类、模块、包的区别

    类 类的概念在许多语言中出现,很容易理解.它将数据和操作进行封装,以便将来的复用. 模块 模块,在Python可理解为对应于一个文件.在创建了一个脚本文件后,定义了某些函数和变量.你在其他需要这些功能 ...