mirror of
https://github.com/ada-dmitry/pypet_project.git
synced 2026-09-24 00:00:19 +00:00
pygame 0.2
This commit is contained in:
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"python.analysis.typeCheckingMode": "basic",
|
||||||
|
"python.analysis.autoImportCompletions": true
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,18 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
class AlienShip():
|
||||||
|
'''Модель и взаимодействие НЛО'''
|
||||||
|
|
||||||
|
def __init__(self, ai_game):
|
||||||
|
"""Инициализирует НЛО и задает его начальную позицию."""
|
||||||
|
self.screen = ai_game.screen
|
||||||
|
self.screen_rect = ai_game.screen.get_rect()
|
||||||
|
# Загружает изображение корабля и получает прямоугольник.
|
||||||
|
self.image = pygame.image.load('image/alien.bmp')
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
# Каждый новый корабль появляется у нижнего края экрана.
|
||||||
|
self.rect.center = self.screen_rect.center
|
||||||
|
|
||||||
|
def blitme(self):
|
||||||
|
"""Рисует корабль в текущей позиции."""
|
||||||
|
self.screen.blit(self.image, self.rect)
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -1,6 +1,8 @@
|
|||||||
import sys
|
import sys
|
||||||
import pygame
|
import pygame
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
|
from ship import Ship
|
||||||
|
# from alien import AlienShip
|
||||||
|
|
||||||
class AlienInvasion():
|
class AlienInvasion():
|
||||||
'''Класс всей игры'''
|
'''Класс всей игры'''
|
||||||
@@ -8,19 +10,47 @@ class AlienInvasion():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
pygame.init()
|
pygame.init()
|
||||||
self.settings = Settings()
|
self.settings = Settings()
|
||||||
# Поменять разрешение
|
|
||||||
self.screen = pygame.display.set_mode((self.settings.screen_weight, self.settings.screen_height))
|
self.screen = pygame.display.set_mode((self.settings.screen_weight, self.settings.screen_height))
|
||||||
pygame.display.set_caption("Alien Invasion")
|
pygame.display.set_caption("Alien Invasion")
|
||||||
|
self.ship = Ship(self)
|
||||||
|
# self.alien = AlienShip(self)
|
||||||
|
|
||||||
def run_game(self):
|
def run_game(self):
|
||||||
'''Запуск игры'''
|
'''Запуск игры'''
|
||||||
while(1):
|
while(1):
|
||||||
for event in pygame.event.get():
|
self._check_events()
|
||||||
|
self.ship.update()
|
||||||
|
self._update_screen()
|
||||||
|
|
||||||
|
def _check_events(self):
|
||||||
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
pygame.display.flip()
|
else:
|
||||||
|
self._check_movement(event)
|
||||||
|
|
||||||
|
def _check_movement(self, event):
|
||||||
|
# Перемещение корабля
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
if event.key == pygame.K_RIGHT:
|
||||||
|
self.ship.moving_right = True
|
||||||
|
elif event.key == pygame.K_LEFT:
|
||||||
|
self.ship.moving_left = True
|
||||||
|
elif event.type == pygame.KEYUP:
|
||||||
|
if event.key == pygame.K_RIGHT:
|
||||||
|
self.ship.moving_right = False
|
||||||
|
elif event.key == pygame.K_LEFT:
|
||||||
|
self.ship.moving_left = False
|
||||||
|
|
||||||
|
def _update_screen(self):
|
||||||
# Установить цвет фона из настроек
|
# Установить цвет фона из настроек
|
||||||
self.screen.fill(self.settings.bg_color)
|
self.screen.fill(self.settings.bg_color)
|
||||||
|
# Обновить положение корабля
|
||||||
|
self.ship.blitme()
|
||||||
|
# self.alien.blitme()
|
||||||
|
|
||||||
|
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
AlInv = AlienInvasion()
|
AlInv = AlienInvasion()
|
||||||
|
|||||||
+1
-1
@@ -3,4 +3,4 @@ class Settings():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.screen_weight = 1200
|
self.screen_weight = 1200
|
||||||
self.screen_height = 800
|
self.screen_height = 800
|
||||||
self.bg_color = (230, 230, 230)
|
self.bg_color = (220, 220, 220) # RGB
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
class Ship():
|
||||||
|
'''Класс для управления кораблем.'''
|
||||||
|
|
||||||
|
def __init__(self, ai_game):
|
||||||
|
"""Инициализирует корабль и задает его начальную позицию."""
|
||||||
|
self.screen = ai_game.screen
|
||||||
|
self.screen_rect = ai_game.screen.get_rect()
|
||||||
|
# Загружает изображение корабля и получает прямоугольник.
|
||||||
|
self.image = pygame.image.load('image/ship.bmp')
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
# Каждый новый корабль появляется у нижнего края экрана.
|
||||||
|
self.rect.midbottom = self.screen_rect.midbottom
|
||||||
|
self.moving_right = False
|
||||||
|
self.moving_left = False
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
'''Обновление позиции корабля игрока'''
|
||||||
|
while self.moving_right:
|
||||||
|
self.rect.x += 1
|
||||||
|
while self.moving_left:
|
||||||
|
self.rect.x -= 1
|
||||||
|
|
||||||
|
def blitme(self):
|
||||||
|
"""Рисует корабль в текущей позиции."""
|
||||||
|
self.screen.blit(self.image, self.rect)
|
||||||
Reference in New Issue
Block a user