python小游戏代码飞机大战:展开史诗般的python飞机大战之旅

# coding:utf-8import pygame

# coding:utf-8import pygame

# coding:utf-8

import pygame

from pygame.locals import *

import random

# 定义窗口的宽度和高度

width = 480

height = 852

# 初始化pygame

pygame.init()

# 设置游戏界面大小、背景图片及标题

screen = pygame.display.set_mode((width, height)) # 游戏界面大小

pygame.display.set_caption('飞机大战') # 游戏标题

background = pygame.image.load('images/background.png') # 背景图

# 设置玩家飞机不同状态的图片列表,多张图片展示为动画效果

player_rect = pygame.Rect(0, 0, 102, 126) # 玩家飞机所在的区域

player = pygame.image.load('images/me1.png').subsuce(player_rect) # 玩家飞机图片

player_down_imgs = [] # 玩家飞机坠毁的图片列表

player_down_imgs.append(pygame.image.load('images/me_destroy_1.png'))

player_down_imgs.append(pygame.image.load('images/me_destroy_2.png'))

player_down_imgs.append(pygame.image.load('images/me_destroy_3.png'))

player_down_imgs.append(pygame.image.load('images/me_destroy_4.png'))

# 存储敌机的图片

enemy1_rect = pygame.Rect(534, 612, 57, 43)

enemy1 = pygame.image.load('images/enemy1.png').subsuce(enemy1_rect)

enemy1_down_imgs = []

enemy1_down_imgs.append(pygame.image.load('images/enemy1_down1.png'))

enemy1_down_imgs.append(pygame.image.load('images/enemy1_down2.png'))

enemy1_down_imgs.append(pygame.image.load('images/enemy1_down3.png'))

enemy1_down_imgs.append(pygame.image.load('images/enemy1_down4.png'))

# 存储英雄的图片

bullet_rect = pygame.Rect(1004, 987, 9, 21)

bullet = pygame.image.load('images/bullet1.png').subsuce(bullet_rect)

# 存储爆炸效果的图片

bomb_rect = pygame.Rect(852, 697, 57, 43)

bomb_img = pygame.image.load('images/bomb.png').subsuce(bomb_rect)

# 定义一个敌机类

class Enemy:

def __init__(self):

self.rect = pygame.Rect(0, 0, 57, 43) # 敌机的区域

self.img = enemy1 # 敌机的图片

self.destroy_imgs = enemy1_down_imgs # 敌机坠毁的图片

self.speed = 2 # 敌机的速度

self.active = False # 敌机是

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(655)
python技巧:如何使用Python来提高工作效率
上一篇
php setcookie无效:解决php setcookie无效的问题
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(9条)