我正在编写一个2D外星人射击游戏,并设法将飞船顺时针旋转90度。但是,我无法更改子弹对象以从船面对的新方式进行射击。船顺时针面向90度。
我尝试过更改bullet rect对象并将属性从中上切换到右侧。没有成功。
bullet.py
def __init__(self, ai_game):
"""Create a bullet object at the ship's current position."""
# Create a bullet rect at (0, 0) and then set correct position.
self.rect = pygame.Rect(0, 0, self.settings.bullet_width,
self.settings.bullet_height)
self.rect.midtop = ai_game.ship.rect.midtop
# Store the bullet's position as a decimal value.
self.y = float(self.rect.y)
def update(self):
"""Move the bullet up the screen."""
# Update the decimal position of the bullet.
self.y -= self.settings.bullet_speed
# Update the rect position.
self.rect.y = self.y
ship.py
def __init__(self, ai_game):
"""Initialize the ship and set its starting position."""
self.screen = ai_game.screen
self.settings = ai_game.settings
self.screen_rect = ai_game.screen.get_rect()
# Load the ship image and get its rect.
self.image = pygame.image.load('images/ship.bmp').convert()
image = self.image.copy()
rot = -90
self.rect = self.image.get_rect()
self.image = pygame.transform.rotate(image, rot)
子弹从飞船的左翼向上射击。