Python+Pgzrun制作打飞机游戏(附源码)

Posted MermaidBeauty

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python+Pgzrun制作打飞机游戏(附源码)相关的知识,希望对你有一定的参考价值。

目录

基本框架

 创建滚动背景

 创建飞机

 让plane移动

 发射子弹

创建敌机

敌机移动

金币制度

关卡制度 

设置

创建更高级飞机(SRplane和SSRplane )

开始

 炸弹

介绍

源码 


基本框架

import pgzrun
WIDTH, HEIGHT = 500, 700
TITLE = '打飞机'

pgzrun.go()

 创建滚动背景

bg1.png和bg2.png 

 

bg1 = Actor('bg1.png')# 保存在images文件中,下同
bg1.x = 250
bg1.y = 350

bg2 = Actor('bg2.png')
bg2.x = bg1.x
bg2.y = bg1.y - 700

def draw():
    bg1.draw()
    bg2.draw()

def update():

    bg1.y += 2               # 滚动起来
    bg2.y += 2
    if bg1.y > 700 + 350:
        bg1.y = bg2.y - 700
    if bg2.y > 700 + 350:
        bg2.y = bg1.y - 700

 创建飞机

plane = Actor('plane.png')
plane.x = 250
plane.y = 600

注:上边的代码写在框架中 

plane.png

 

 让plane移动

def update():
    #--省略-- 
    if keyboard.left:
        plane.x += 5

    elif keyboard.right:
        plane.x -= 5

    if plane.x < 0:
        plane.x += 10

    elif plane.x > 500:
        plane.x -= 10

 发射子弹

bullets = []

def on_key_down(key):
        if key == keys.SPACE:
            bullet = Actor('bullet1.png')
            bullet.x = plane.x
            bullet.y = plane.y - 30
            bullets.append(bullet)

 bullet1.png

 

def draw():
    --省略--
    for b in bullets:
        b.draw()
def update():
    --省略--
    for b in bullets:
        b.y -= 5
        if b.y < 0:
            bullets.remove(b)

创建敌机

enemys = []
for i in range(6):
    enemy = Actor('enemy.png')

    enemy.x = 70 * (i + 1)
    enemy.y = 20

    enemys.append(enemy)

enemy.png

敌机移动

def update():
    # --省略--
    speed = 2
    for e in enemys:
        e.y += speed
        if e.bottom >= 700:
            e.y = 0
            e.x = randint(50, WIDTH - 50)
        if e.colliderect(plane):
            plane.image = 'plane2.png'
            enemys.remove(e)


        for b in bullets:

            if e.colliderect(b):
                bullets.remove(b)
                e.y = 0
                e.x = randint(50, WIDTH - 50)
                

plane2.png

 

def draw():
    # --省略--
    if plane.image != 'plane2.png':  #重构

        for b in bullets:
            b.draw()
        for i in enemys:
            i.draw()

到此为止,《打飞机》游戏已经可以玩了,以下部分都是其他功能,让游戏更有可玩性 

金币制度 

在主文件夹中创建data文件夹,存放数据

在data文件夹创建金币.txt,写入0

with open('data/金币.txt', 'r') as f:  # 获取金币信息
    coin = int(f.read())
    f.close()
def draw():
    # --省略--
    text1 = 'coin:' + str(coin)
    screen.draw.text(text1, (50, 10), fontsize=50, color='black')
def update():
    # --省略--
    for e in enemys:
        --省略--
        for b in bullets:
            # --省略--
            if e.colliderect(b)
                # --省略--
                coin += 1

                f3 = open('data/金币.txt', 'w')
                f3.write(str(coin))
                f3.close()

关卡制度 

在data文件夹中创建level.txt

f = open('data/level.txt', 'r')  # 获取关卡数据
level = int(f.read())
f.close()
kill = 0 # 关卡中击杀敌机数量
def draw():
    # --省略--
    text = 'level' + str(level)
    screen.draw.text(text, (350, 10), fontsize=50, color='black')

    text2 = str(kill) + '/' + str((level + 1) * 10)
    screen.draw.text(text2, (230, 10), fontsize=50, color='black')
def update():
    --省略--
    standard = (level + 1) * 10
    if kill > standard:
        kill = 0
        level += 1
        f = open('data/level.txt', 'w')
        f.write(str(level))
        f.close()
def update():
    # --省略--
    speed = 2 + level*0.1 # 重构

设置

创建settings.py

# coding=gbk
import wx


def set():
    class MyFrame(wx.Frame):
        def __init__(self):
            global beijing
            super().__init__(None, title='设置', size=(500, 250), pos=(400, 400))
            panel = wx.Panel(parent=self)
            statictext = wx.StaticBox(parent=panel, label="这里是《打飞机》游戏设置", pos=(10, 10))

    app = wx.App()

    frm = MyFrame()
    frm.Show()
    app.MainLoop()

set(1).jpg 

set = Actor('set(1).jpg')
set.x = 20
set.y = 20

def draw():
    # --省略--
    set.draw()

创建更高级飞机(SRplane和SSRplane )

                               

srplane.png    srplane2.png             ssrplane.png               ssrplane2.png

创建shop.py

在data文件夹中创建sr.txt和ssr.txt,写入0

创建plane.txt 写入plane.png

shop.py

import wx


def shopping():
    class MyFrame(wx.Frame):
        def __init__(self):
            super().__init__(None, title='商店', size=(500, 300), pos=(400, 400))
            panel = wx.Panel(parent=self)
            statictext = wx.StaticBox(parent=panel, label="这里是《打飞机》游戏商店", pos=(10, 10))

            statictext = wx.StaticBox(parent=panel, label="你可以在这购买英雄皮肤", pos=(10, 50))

            with open('data/sr.txt', 'r') as f:
                c = f.read()
                f.close()
            if c != '0':
                self.srtext = '已拥有SR级飞机'
            else:
                self.srtext = '购买SR级飞机(1000金币,两条命)'
            self.button = wx.Button(panel, -1, self.srtext, pos=(30, 150))
            self.Bind(wx.EVT_BUTTON, self.srshopping, self.button)
            self.button.SetDefault()

            with open('data/ssr.txt', 'r') as f:
                c2 = f.read()
                f.close()
            if c2 != '0':
                self.ssrtext = '已拥有SSR级飞机'
            else:
                self.ssrtext = '购买SSR级飞机(3000金币,两条命,一次发射两枚子弹)'
            self.button = wx.Button(panel, -1, self.ssrtext, pos=(30, 210))
            self.Bind(wx.EVT_BUTTON, self.ssrshopping, self.button)
            self.button.SetDefault()

        def srshopping(self, event):
            with open('data/金币.txt') as f:
                c = int(f.read())
                f.close()
            if self.srtext == '购买SR级飞机(两条命)' and c >= 1000:
                self.srtext = '已获得'
                self.button.SetLabel(self.srtext)
                with open('data/金币.txt', 'w') as f:
                    f.write(str(c - 1000))
                    f.close()
                with open('data/sr.txt', 'w') as f:
                    f.write('1')
                    f.close()

        def ssrshopping(self, event):
            with open('data/金币.txt') as f:
                c = int(f.read())
                f.close()
            if self.ssrtext == '购买SSR级飞机(3000金币,两条命,一次发射两枚子弹)' and c >= 3000:
                self.ssrtext = '已获得'
                self.button.SetLabel(self.ssrtext)

                with open('data/金币.txt', 'w') as f:
                    f.write(str(c - 3000))
                    f.close()
                with open('data/ssr.txt', 'w') as f:
                    f.write('1')
                    f.close()

    app = wx.App()

    frm = MyFrame()
    frm.Show()
    app.MainLoop()

settings.py

def set():
    # --省略--
    with open('data/sr.txt', 'r') as f:
        c = f.read()
        f.close()
    if c != '0':
        self.sr_go_out = '让SR飞机上场'
    else:
        self.sr_go_out = '未获得SR飞机'

    self.button = wx.Button(panel, -1, self.sr_go_out, pos=(60, 100))
    self.Bind(wx.EVT_BUTTON, self.srgoout, self.button)
    self.button.SetDefault()

    with open('data/ssr.txt', 'r') as f:
        c1 = f.read()
        f.close()
    if c1 != '0':
        self.ssr_go_out = '让SSR飞机上场'
    else:
        self.ssr_go_out = '未获得SSR飞机'

    self.button = wx.Button(panel, -1, self.ssr_go_out, pos=(60, 150))
    self.Bind(wx.EVT_BUTTON, self.ssrgoout, self.button)
    self.button.SetDefault()
    def srgoout(self, event):
        global planemodel
        if self.sr_go_out == '让SR飞机上场':
            with open('data/plane.txt', 'w') as f:
                f.write('srplane.png')
                planemodel = 'srplane'

    def ssrgoout(self, event):
        global planemodel
        if self.ssr_go_out == '让SSR飞机上场':
            with open('data/plane.txt', 'w') as f:
                f.write('ssrplane.png')
                planemodel = 'ssrplane'

打飞机.py

with open('data/plane.txt') as f5:
    p = f5.read()
    f5.close()
live = 0
if p == 'plane.png':
    live = 1
elif p == 'srplane.png' or p == 'ssrplane.png':
    live = 2
def update():
    # --省略--
    if e.colliderect(plane):            
        live -= 1

​def on_key_down(key):
    # --省略--
    if key == keys.SPACE:
        if plane.image == 'ssrplane.png' and len(bullets) < 12: # 重构

            bullet = Actor('bullet1.png')
            bullet1 = Actor('bullet1.png')
            bullet.x = plane.x + 40
            bullet.y = plane.y - 50
            bullet1.x = plane.x - 40
            bullet1.y = plane.y - 50
            bullets.append(bullet)
            bullets.append(bullet1)
        else:
            if plane.image == 'srplane.png' and len(bullets) < 10:
                bullet = Actor('bullet1.png')
                bullet.x = plane.x
                bullet.y = plane.y - 30
                bullets.append(bullet)
            if plane.image == 'plane.png' and len(bullets) < 6:
                bullet = Actor('bullet1.png')
                bullet.x = plane.x
                bullet.y = plane.y - 30
                bullets.append(bullet)
​
def on_mouse_down(pos):
    global live
    if set.collidepoint(pos):
        settings.set()
        plane.image = settings.planemodel
        if settings.planemodel == 'plane.png':
            live = 1
        elif settings.planemodel == 'srplane.png' or settings.planemodel == 'ssrplane.png':
            live = 2

开始

begin = False
def draw():
    # --省略--
    if begin:               #重构
        plane.image = settings.planemodel
        plane.draw()
        if plane.image != 'plane2.png':
            for b in bullets:
                b.draw()

            for i in enemys:
                i.draw()
    else:
        set.draw() # 重构

        screen.draw.text('Press [b] to begin', (100, 350), fontsize=50, color='black')

def on_key_down(key):
    
    if begin:# 重构
        # --省略--
    else:
        if key == keys.B:
            begin = True
def update():    
    if begin:
        # --省略--
        if live == 0:
            begin = False

 炸弹

创建bombs.txt,写入5

with open('data/bombs.txt') as f4:  # 获取炸弹数量信息
    b = int(f4.read())
    f4.close()

bomb = Actor('bomb.png')
bomb.x = 32
bomb.y = 550
bombs = b

def draw():
    # --省略--
    if begin:
        # --省略--
        screen.draw.text(str(bombs), (32, 582), fontsize=30, color='black')
        bomb.draw()

def on_key_down(key):
    if begin:
        # --省略--
        if key == keys.Z:
            if bombs > 0:
                for e in enemys:
                    e.y = 0
                    e.x = randint(50, WIDTH - 50)
                    kill += 1
            bombs -= 1
            with open('data/bombs.txt', 'w') as f:
                f.write(str(bombs))
                f.close()
import wx


def shopping():
    class MyFrame(wx.Frame):
        def __init__(self):
            # --省略--
            self.button1 = wx.Button(panel, 1, '购买炸弹(100金币)', pos=(50, 100))
            self.Bind(wx.EVT_BUTTON, self.bombshopping, self.button1)
            self.button1.SetDefault()
          
            # --省略--
        def bombshopping(self, event):
            with open('data/金币.txt') as f:
                c = int(f.read())
                f.close()
            if c>=100:
                self.button1.SetLabel('购买成功')

                with open('data/bombs.txt') as f:
                    b = int(f.read())
                    f.close()
                with open('data/bombs.txt', 'w') as f:
                    f.write((str(b + 1)))
                    f.close()
                with open('data/金币.txt') as f:
                    c = int(f.read())
                    f.close()
                with open('data/金币.txt', 'w') as f:
                    f.write(str(c - 100))
                    f.close()
# --省略--

打飞机.py

def draw():
    # --省略--
    if begin:
        # --省略--
    else:
        # --省略--
        screen.draw.text('Press [s] to go shopping', (50, 460), fontsize=50, color='black')
def on_key_down():
    if begin:
        # --省略--
    else:
        # --省略--
        if key == keys.S:
            shopping()

介绍

创建information.py 

import wx


def check_information():
    class MyFrame(wx.Frame):
        def __init__(self):
            super().__init__(None, title='信息简介', size=(500, 200), pos=(400, 400))
            panel = wx.Panel(parent=self)
            statictext = wx.StaticBox(parent=panel, label="欢迎进入《打飞机》游戏", pos=(10, 10))
            statictext = wx.StaticBox(parent=panel, label="你可以按下左右方向键控制英雄移动", pos=(10, 50))
            statictext = wx.StaticBox(parent=panel, label="按空格键发射子弹,并击杀敌人", pos=(10, 90))
            statictext = wx.StaticBox(parent=panel, label="你拥有5个炸弹,按【z】试一试!", pos=(10, 120))

    app = wx.App()

    frm = MyFrame()
    frm.Show()
    app.MainLoop()
def draw():
    if begin:
        # --省略--
    else:
        # --省略--
        screen.draw.text('Press [i] to get information', (30, 410), fontsize=50, color='black')
def draw():
    if begin:
        # --省略--
    else:
        # --省略--
        if key == keys.S:
            shopping()
            f2 = open('data/金币.txt', 'r')  # 获取金币信息
            coin = int(f2.read())
            f2.close()

到此为止,游戏正式编写结束了!

源码 

打飞机.py

# coding=gbk

from random import randint

from pgzrun import go

import settings
from information import check_information
from shop import shopping

# 打开文件,获取数据
f = open('data/level.txt', 'r')  # 获取关卡数据
level = int(f.read())
f.close()

f2 = open('data/金币.txt', 'r')  # 获取金币信息
coin = int(f2.read())
f2.close()

with open('data/bombs.txt') as f4:  # 获取炸弹数量信息
    b = int(f4.read())
    f4.close()

with open('data/plane.txt') as f5:
    p = f5.read()
    f5.close()
live = 0
if p == 'plane.png':
    live = 1
elif p == 'srplane.png' or p == 'ssrplane.png':
    live = 2

with open('data/log.txt') as f:
    logged = f.read()
    f.close()

# 窗口数据
WIDTH, HEIGHT = 500, 700
TITLE = '打飞机'
# 创建角色
bg1 = Actor('bg2.png')
bg1.x = 250
bg1.y = 350

bg2 = Actor('bg1.png')
bg2.x = bg1.x
bg2.y = bg1.y - 700

plane = Actor(settings.planemodel)
plane.x = 250
plane.y = 600

set = Actor('set(1).jpg')
set.x = 20
set.y = 20
bullets = []

bomb = Actor('bomb.png')
bomb.x = 32
bomb.y = 550
bombs = b
enemys = []
kill = 0
begin = False

for i in range(6):
    enemy = Actor('enemy.png')

    enemy.x = 70 * (i + 1)
    enemy.y = 20

    enemys.append(enemy)


def draw():
    global bombs
    bg1.draw()
    bg2.draw()

    text = 'level' + str(level)
    text2 = str(kill) + '/' + str((level + 1) * 10)
    text3 = 'coin:' + str(coin)
    screen.draw.text(text2, (230, 10), fontsize=50, color='black')
    screen.draw.text(text, (350, 10), fontsize=50, color='black')
    screen.draw.text(text3, (50, 10), fontsize=50, color='black')
    if begin:
        screen.draw.text(str(bombs), (32, 582), fontsize=30, color='black')
        bomb.draw()
        plane.image = settings.planemodel
        plane.draw()
        if plane.image != 'plane2.png':
            for b in bullets:
                b.draw()

            for i in enemys:
                i.draw()
    else:
        set.draw()

        screen.draw.text('Press [b] to begin', (100, 350), fontsize=50, color='black')
        screen.draw.text('Press [i] to get information', (30, 410), fontsize=50, color='black')
        screen.draw.text('Press [s] to go shopping', (50, 460), fontsize=50, color='black')


def on_key_down(key):
    global begin, bombs, kill, coin, p, live
    if begin:
        if key == keys.SPACE:
            if plane.image == 'ssrplane.png' and len(bullets) < 6:

                bullet = Actor('bullet1.png')
                bullet1 = Actor('bullet1.png')
                bullet.x = plane.x + 40
                bullet.y = plane.y - 50
                bullet1.x = plane.x - 40
                bullet1.y = plane.y - 50
                bullets.append(bullet)
                bullets.append(bullet1)
            else:
                if plane.image == 'srplane.png' and len(bullets) < 6:
                    bullet = Actor('bullet1.png')
                    bullet.x = plane.x
                    bullet.y = plane.y - 30
                    bullets.append(bullet)
                if plane.image == 'plane.png' and len(bullets) < 6:
                    bullet = Actor('bullet1.png')
                    bullet.x = plane.x
                    bullet.y = plane.y - 30
                    bullets.append(bullet)

        if key == keys.Z:
            if bombs > 0:
                for e in enemys:
                    if bombs > 0:
                        e.y = 0
                        e.x = randint(50, WIDTH - 50)
                        kill += 1
            bombs -= 1
            with open('data/bombs.txt', 'w') as f:
                f.write(str(bombs))
                f.close()

    else:
        if key == keys.B:
            begin = True
        if key == keys.I:
            check_information()
        if key == keys.S:
            shopping()
            f2 = open('data/金币.txt', 'r')  # 获取金币信息
            coin = int(f2.read())
            f2.close()


def on_mouse_down(pos):
    global beijing, live
    if set.collidepoint(pos):
        settings.set()
        beijing = settings.beijing
        plane.image = settings.planemodel
        if settings.planemodel == 'plane.png':
            live = 1
        elif settings.planemodel == 'srplane.png' or settings.planemodel == 'ssrplane.png':
            live = 2


def update():
    global kill, level, begin, coin, beijing, p, live

    standard = (level + 1) * 10
    bg1.y += 2
    bg2.y += 2
    if bg1.y > 700 + 350:
        bg1.y = bg2.y - 700
    if bg2.y > 700 + 350:
        bg2.y = bg1.y - 700
    if begin:
        if kill > standard:
            kill = 0
            level += 1
            f = open('data/level.txt', 'w')
            f.write(str(level))
            f.close()

        speed = 2 + level * 0.1

        if keyboard.left:
            plane.x -= 5
        elif keyboard.right:
            plane.x += 5

        if plane.x < 0:
            plane.x += 10
        elif plane.x > 500:
            plane.x -= 10

        for b in bullets:
            b.y -= 5
            if b.y < 0:
                bullets.remove(b)

        for e in enemys:
            e.y += speed
            if e.bottom >= 700:
                e.y = 0
                e.x = randint(50, WIDTH - 50)
            if e.colliderect(plane):
                live -= 1
                if live == 0:

                    plane.image = 'plane2.png'
                    enemys.remove(e)
                    kill = 0
                    live = 2
                    begin = False
                    enemys.clear()
                    bullets.clear()
                    for i in range(6):
                        enemy = Actor('enemy.png')
                        enemy.x = 70 * (i + 1)
                        enemy.y = 20

                        enemys.append(enemy)
                else:

                    e.y = 0
                    e.x = randint(50, WIDTH - 50)
            for b in bullets:

                if e.colliderect(b):
                    bullets.remove(b)
                    e.y = 0
                    e.x = randint(50, WIDTH - 50)
                    kill += 1
                    coin += 1

                    f3 = open('data/金币.txt', 'w')
                    f3.write(str(coin))
                    f3.close()


go()

 shop.py

import wx


def shopping():
    class MyFrame(wx.Frame):
        def __init__(self):
            super().__init__(None, title='商店', size=(500, 300), pos=(400, 400))
            panel = wx.Panel(parent=self)
            statictext = wx.StaticBox(parent=panel, label="这里是《打飞机》游戏商店", pos=(10, 10))

            statictext = wx.StaticBox(parent=panel, label="你可以在这购买英雄皮肤", pos=(10, 50))

            self.button1 = wx.Button(panel, 1, '购买炸弹(100金币)', pos=(50, 100))
            self.Bind(wx.EVT_BUTTON, self.bombshopping, self.button1)
            self.button1.SetDefault()
            with open('data/sr.txt', 'r') as f:
                c = f.read()
                f.close()
            if c != '0':
                self.srtext = '已拥有SR级飞机'
            else:
                self.srtext = '购买SR级飞机(1000金币,两条命)'
            self.button = wx.Button(panel, -1, self.srtext, pos=(30, 150))
            self.Bind(wx.EVT_BUTTON, self.srshopping, self.button)
            self.button.SetDefault()

            with open('data/ssr.txt', 'r') as f:
                c2 = f.read()
                f.close()
            if c2 != '0':
                self.ssrtext = '已拥有SSR级飞机'
            else:
                self.ssrtext = '购买SSR级飞机(3000金币,两条命,一次发射两枚子弹)'
            self.button = wx.Button(panel, -1, self.ssrtext, pos=(30, 210))
            self.Bind(wx.EVT_BUTTON, self.ssrshopping, self.button)
            self.button.SetDefault()

        def bombshopping(self, event):
            with open('data/金币.txt') as f:
                c = int(f.read())
                f.close()
            if c>=100:
                self.button1.SetLabel('购买成功')

                with open('data/bombs.txt') as f:
                    b = int(f.read())
                    f.close()
                with open('data/bombs.txt', 'w') as f:
                    f.write((str(b + 1)))
                    f.close()
                with open('data/金币.txt') as f:
                    c = int(f.read())
                    f.close()
                with open('data/金币.txt', 'w') as f:
                    f.write(str(c - 100))
                    f.close()

        def srshopping(self, event):
            with open('data/金币.txt') as f:
                c = int(f.read())
                f.close()
            if self.srtext == '购买SR级飞机(两条命)' and c >= 1000:
                self.srtext = '已获得'
                self.button.SetLabel(self.srtext)
                with open('data/金币.txt', 'w') as f:
                    f.write(str(c - 1000))
                    f.close()
                with open('data/sr.txt', 'w') as f:
                    f.write('1')
                    f.close()

        def ssrshopping(self, event):
            with open('data/金币.txt') as f:
                c = int(f.read())
                f.close()
            if self.ssrtext == '购买SSR级飞机(3000金币,两条命,一次发射两枚子弹)' and c >= 3000:
                self.ssrtext = '已获得'
                self.button.SetLabel(self.ssrtext)

                with open('data/金币.txt', 'w') as f:
                    f.write(str(c - 3000))
                    f.close()
                with open('data/ssr.txt', 'w') as f:
                    f.write('1')
                    f.close()

    app = wx.App()

    frm = MyFrame()
    frm.Show()
    app.MainLoop()

settings.py

# coding=gbk
import wx


f = open('data/plane.txt')
planemodel = f.read()
f.close()


def set():
    class MyFrame(wx.Frame):
        def __init__(self):
            global beijing
            super().__init__(None, title='设置', size=(500, 250), pos=(400, 400))
            panel = wx.Panel(parent=self)
            statictext = wx.StaticBox(parent=panel, label="这里是《打飞机》游戏设置", pos=(10, 10))

            with open('data/sr.txt', 'r') as f:
                c = f.read()
                f.close()
            if c != '0':
                self.sr_go_out = '让SR飞机上场'
            else:
                self.sr_go_out = '未获得SR飞机'

            self.button = wx.Button(panel, -1, self.sr_go_out, pos=(60, 100))
            self.Bind(wx.EVT_BUTTON, self.srgoout, self.button)
            self.button.SetDefault()

            with open('data/ssr.txt', 'r') as f:
                c1 = f.read()
                f.close()
            if c1 != '0':
                self.ssr_go_out = '让SSR飞机上场'
            else:
                self.ssr_go_out = '未获得SSR飞机'

            self.button = wx.Button(panel, -1, self.ssr_go_out, pos=(60, 150))
            self.Bind(wx.EVT_BUTTON, self.ssrgoout, self.button)
            self.button.SetDefault()

        def srgoout(self, event):
            global planemodel
            if self.sr_go_out == '让SR飞机上场':
                with open('data/plane.txt', 'w') as f:
                    f.write('srplane.png')
                    planemodel = 'srplane'

        def ssrgoout(self, event):
            global planemodel
            if self.ssr_go_out == '让SSR飞机上场':
                with open('data/plane.txt', 'w') as f:
                    f.write('ssrplane.png')
                    planemodel = 'ssrplane'

    app = wx.App()

    frm = MyFrame()
    frm.Show()
    app.MainLoop()

information.py

import wx


def check_information():
    class MyFrame(wx.Frame):
        def __init__(self):
            super().__init__(None, title='信息简介', size=(500, 200), pos=(400, 400))
            panel = wx.Panel(parent=self)
            statictext = wx.StaticBox(parent=panel, label="欢迎进入《打飞机》游戏", pos=(10, 10))
            statictext = wx.StaticBox(parent=panel, label="你可以按下左右方向键控制英雄移动", pos=(10, 50))
            statictext = wx.StaticBox(parent=panel, label="按空格键发射子弹,并击杀敌人", pos=(10, 90))
            statictext = wx.StaticBox(parent=panel, label="你拥有一些炸弹,按【z】试一试!", pos=(10, 120))

    app = wx.App()

    frm = MyFrame()
    frm.Show()
    app.MainLoop()

bombs.txt

5

level.txt

1

plane.txt

plane.png

sr.txt

0

ssr.txt

0

金币.txt

0

Python项目案例介绍,炫酷飞机大战,内附源码文件领取

人工智能时代必然是大势所趋,Python也随之被一再推上神坛,也有着越来越多的人通过一些方式学习Python编程,然而,编程毕竟一门语言,仅仅是靠理论的学习是远远不够的。

今天,小编哥给大家介绍一个Python项目案例 — 飞机大战,是一个用python制作的比较炫酷的游戏哦。

一、游戏效果

注意:游戏是有声音,但是无奈技术实在不到家,没办法实现图片产生声音的功能。最后,如果你的时间不是很紧张,并且又想快速的python提高,最重要的是不怕吃苦,建议你可以架微♥信:762459510 ,那个真的很不错,很多人进步都很快,需要你不怕吃苦哦!大家可以去添加上看一下~

二、游戏代码

获取视频资料,转发此文+点击喜欢

python福利教程领取方式:
1、点赞+评论(勾选“同时转发”)
2、关注小编。并私信回复关键字【19】
(一定要私信哦~点击我的头像就能看到私信按钮了)

python福利教程领取方式:
1、点赞+评论(勾选“同时转发”)
2、关注小编。并私信回复关键字【19】
(一定要私信哦~点击我的头像就能看到私信按钮了)

以上是关于Python+Pgzrun制作打飞机游戏(附源码)的主要内容,如果未能解决你的问题,请参考以下文章

用 Java 开发一个打飞机小游戏(附完整源码)

Python项目案例介绍,炫酷飞机大战,内附源码文件领取

分享30个有趣的 Python小游戏,我能玩一天(附源码)

30个Python小游戏,上班摸鱼我能玩一天内附源码

30个Python小游戏,上班摸鱼我能玩一天内附源码

30个Python小游戏,上班摸鱼我能玩一天内附源码