1 Star 0 Fork 0

zhuo木鸟/AlienInvasionGame

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bullet.py 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
1259975740 提交于 2021-03-09 15:39 +08:00 . The alien invasion game first version
import pygame
from pygame.sprite import Sprite
class Bullet(Sprite):
""" A class to manage bullets fired from the ship. """
def __init__(self, ai_settings, screen, ship):
""" Create a bullet object at the ship's current position. """
super().__init__()
self.screen = screen
# Create a bullet rect at (0,0) and then set correct position.
self.rect = pygame.Rect(0, 0, ai_settings.bullet_width, \
ai_settings.bullet_height)
self.rect.centerx = ship.rect.centerx
self.rect.top = ship.rect.top
# Store the bullet's position as a decimal value
self.y = float(self.rect.y)
# Paint the bullet with some color
self.color = ai_settings.bullet_color
self.speed_factor = ai_settings.bullet_speed_factor
def update(self):
""" Move the bullet up the screen. """
# Update the decimal position of the bullet
self.y -= self.speed_factor
self.rect.y = self.y
def draw_bullet(self):
pygame.draw.rect(self.screen, self.color, self.rect)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zhuowoodbird/alien-invasion-game.git
[email protected]:zhuowoodbird/alien-invasion-game.git
zhuowoodbird
alien-invasion-game
AlienInvasionGame
master

搜索帮助