代码拉取完成,页面将自动刷新
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。