4 Star 0 Fork 2

W_HZ / 算题小游戏

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
supply.py 2.48 KB
一键复制 编辑 原始数据 按行查看 历史
杨Y 提交于 2023-04-24 18:18 . 添加supply.py注释
# -*- coding: utf-8 -*-
# @Author : Sdite
# @DateTime : 2017-07-26 17:56:37
import pygame
from random import *
# 两种随机道具补给
# 子弹供应
class Bullet_Supply(pygame.sprite.Sprite): # 定义一个超级子弹的补给类
"""docstring for Bullet_Supply"""
def __init__(self, bg_size): #初始化
super(Bullet_Supply, self).__init__()
self.image = pygame.image.load('images/bullet_supply.png').convert_alpha() # 加载图片
self.rect = self.image.get_rect() # 图像大小
self.width, self.height = bg_size[0], bg_size[1]
self.rect.left, self.rect.bottom = \
randint(0, self.width - self.rect.width), -100
""" y轴方向用self.rect.bottom 而不是平常经常用的top,变成了左下角的坐标,让它初始化的时候就在界面上方大概100个像素的位置,直接往下扔,
要扔补给的时候会发出一个提示音效,所以我们在一个平均高度往下扔即可,即botton=-100,
补给包出现的水平方向是随机的:从0到屏幕的宽度减去补给包本身的宽度"""
self.speed = 5 # 设置速度
self.active = False # 是否显示?默认情况下不开启
self.mask = pygame.mask.from_surface(self.image) #碰撞检测
def move(self): # 补给包向下移动
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.active = False
def reset(self): # 重新刷新位置
self.active = True
self.rect.left, self.rect.bottom = \
randint(0, self.width - self.rect.width), -100
# 炸弹供应 类似于子弹供应
class Bomb_Supply(pygame.sprite.Sprite):
"""docstring for Bomb_Supply"""
def __init__(self, bg_size):
super(Bomb_Supply, self).__init__()
self.image = pygame.image.load('images/bomb_supply.png').convert_alpha()
self.rect = self.image.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.rect.left, self.rect.bottom = \
randint(0, self.width - self.rect.width), -100
self.speed = 5
self.active = False
self.mask = pygame.mask.from_surface(self.image)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.active = False
def reset(self):
self.active = True
self.rect.left, self.rect.bottom = \
randint(0, self.width - self.rect.width), -100
Python
1
https://gitee.com/WHZ_1718/airplane_battle_games.git
git@gitee.com:WHZ_1718/airplane_battle_games.git
WHZ_1718
airplane_battle_games
算题小游戏
master

搜索帮助