Answer the question
In order to leave comments, you need to log in
How to make animation in a starship game?
Here is the cat of the program:
1) Game_main.py
import sys
import pygame
from settings import Settings
from ship import Ship
import game_functions as gf
def run_game():
# Инициализирование pygame, settings и объекта экрана
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
# Создание корабля
ship = Ship(screen)
# Назначение цвета фона
#bg_color = (230, 230, 230)
# Запуск основного цикла игры
while True:
gf.check_events(ship)
gf.update_screen(ai_settings, screen, ship)
run_game()
2) ship.py
import pygame
class Ship():
def __init__(self, screen):
"""Инициализация корабля и задавание ему начальной позиции."""
self.screen = screen
SHIPS = ["images/ship1.png", "images/ship2.png"]
i = 0
while i < 2:
# Загрузка изображения корабля и получение прямоугольника
self.image = pygame.image.load(SHIPS[i])
i += 1
#self.image = pygame.image.load("images/ship.png")
self.rect = self.image.get_rect()
self.screen_rect = screen.get_rect()
# Каждый новый корабль появляется у нижнего края экрана
self.rect.centerx = self.screen_rect.centerx
self.rect.bottom = self.screen_rect.bottom
def blitme(self):
"""Рисует корабль в текущей позиции"""
self.screen.blit(self.image, self.rect)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question