作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以编辑窗口大小。但是,当尝试更改窗口背景颜色时,我遇到了问题。无论我输入什么数字,窗口背景都会保持黑色。我决定尝试在代码中添加一艘船,看看我的背景是否会发生任何变化。什么也没有变。
import sys
import pygame
from settings import Settings
from ship import Ship
class AlienInvasion:
"""Overall class to manage game assets and behavior."""
def __init__(self):
"""Initialize the game, and greate game resources."""
pygame.init()
self.settings = Settings()
self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
pygame.display.set_caption("Alien Invasion")
self.ship = Ship(self)
def run_game(self):
"""Start the main loop for the game."""
while True:
# Watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# Redraw the screen during each pass through the loop.
self.screen.fill(self.settings.bg_color)
self.ship.blitme()
# Make the most recently drawn screen visible.
pygame.display.flip()
if __name__ == '__main__':
# Make a game instance, and run the game.
ai = AlienInvasion()
ai.run_game()
这 :
class Settings:
"""A class to store all settings for Alien Invasion."""
def __init__(self):
# Screen Settings
self.screen_width = 600
self.screen_height = 500
self.bg_color = (230, 230, 230)
和这个 :
import pygame
class Ship:
"""A class to manage the ship."""
def __init__(self, ai_game):
"""Initialize the ship and set its starting position."""
self.screen = ai_game.screen
self.screen_rect = ai_game.screen.get_rect()
# Load the ship image and get its rect.
self.image = pygame.image.load('images/ship.bmp')
self.rect = self.image.get_rect()
# Start each new ship at the bottom enter of the screen.
self.rect.midbottom = self.screen_rect.midbottom
def blitme(self):
"""Draw the ship at its current location."""
self.screen.blit(self.image, self.rect)
最佳答案
缩进需要固定,以便每帧更新所有图形。
def run_game(self):
while True:
# Watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
self.screen.fill(self.settings.bg_color)
self.ship.blitme()
pygame.display.flip()
关于python - 窗口颜色/在 pygame 中添加一艘船,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63371972/
我寻求这种性质的东西 //validation rules in model "User" attributes: { age: { required: true,
sailsjs 0.11, Node 0.12.4。使用护照 0.2.1 和本地护照 1.0 使用 sailsjs 蓝图路线只是为了看看发生了什么。该项目只是一个简单的博客,我尝试在蓝图路径 /use
我的 SailsJS 应用程序中有以下模型,我想在字段“room_name”和“school_id”上添加复合唯一键。 我目前所做的是从 mongo 运行这个命令: db.room.ensureIn
我使用的是 sailsjs 0.12。它支持 models 上的 index 属性,也我正在使用 npm 包 Sails-hooks-mongoat创建反向索引等。 这并不理想,但它奏效了。现在,他们
尝试: sails-migrations --env production migrate 返回: Error: connect ECONNREFUSED 我们在端口 3308 下的所有 IP 地址上
我是一名优秀的程序员,十分优秀!