1
임프린은 왼쪽 상단 모서리에 외계 우주선 이미지를 배치해야하는 책 코스입니다. 지침에 따라 동일한 코드를 사용했지만 이미지가 너무 낮게 배치되었습니다. 나는 문제의 근원을 알아낼 수 없다. 나는 투명한 PNG 이미지를 사용하고있다. 여기에 외계인에 대한 코드, 설정 및 주요 classes.Many 도움을 주셔서 감사합니다.화면에 이미지를 올리는 데 파이 게임 문제가 발생했습니다.
외국인 클래스 :이
import pygame
from pygame.sprite import Sprite
class Alien(Sprite):
"""A class to represent a single alien in the fleet."""
def __init__(self, ai_settings, screen):
"""Initialize the alien and set its starting position."""
super(Alien, self).__init__()
self.screen = screen
self.ai_settings = ai_settings
# Load the alien image and set its rect attribute.
self.image = pygame.image.load('Images/alien.png')
self.rect = self.image.get_rect()
# Start each new alien near the top left of the screen.
self.rect.x = self.rect.width
self.rect.y = self.rect.height
# Store the alien's exact position.
self.x = float(self.rect.x)
def blitme(self):
"""Draw the alien at its current location."""
self.screen.blit(self.image, self.rect)
설정 클래스 :이
class Settings():
"""A class to store all settings for Alien Invasion."""
def __init__(self):
"""Initialize the game's settings."""
# Screen settings
self.screen_width = 1200
self.screen_height = 800
self.bg_color = (230, 230, 230)
#Ship setting
self.ship_speed_factor = 1.5
# Bullet settings
self.bullet_speed_factor =1
self.bullet_width = 3
self.bullet_height = 15
self.bullet_color = 60 ,60, 60
self.bullets_allowed = 3
메인 클래스 :
from settings import Settings
import pygame
from ship import Ship
from alien import Alien
from pygame.sprite import Group
import game_functions as gf
def run_game():
# Initialize game and create a screen object.
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
# Make a ship
ship = Ship(ai_settings, screen)
# Make a group to store bullets in.
bullets = Group()
# Make an alien.
alien = Alien(ai_settings, screen)
# Start the main loop for the game.
while True:
gf.check_events(ai_settings, screen, ship, bullets)
ship.update()
# Get rid of bullets that have disappeared.
gf.update_bullets(bullets)
gf.update_screen(ai_settings, screen, ship, alien, bullets)
run_game()
PRMoureu 정말 감사드립니다. 좋은 주간 친구가 되라! –