main
parent
bbfd4eaa6c
commit
81654999d7
34
main.py
34
main.py
|
@ -1,5 +1,6 @@
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
# Загрузка спрайтов движения
|
||||||
def load_movement_sprites(prefix, num_sprites):
|
def load_movement_sprites(prefix, num_sprites):
|
||||||
sprite_list = []
|
sprite_list = []
|
||||||
for i in range(1, num_sprites + 1):
|
for i in range(1, num_sprites + 1):
|
||||||
|
@ -8,13 +9,14 @@ def load_movement_sprites(prefix, num_sprites):
|
||||||
sprite_list.append(sprite)
|
sprite_list.append(sprite)
|
||||||
return sprite_list
|
return sprite_list
|
||||||
|
|
||||||
# Спрайты
|
# Спрайты игрока
|
||||||
player_image = pygame.image.load("player.png")
|
player_image = pygame.image.load("player.png")
|
||||||
forward_sprites = load_movement_sprites("forward", 5)
|
forward_sprites = load_movement_sprites("forward", 5)
|
||||||
backward_sprites = load_movement_sprites("backward", 5)
|
backward_sprites = load_movement_sprites("backward", 5)
|
||||||
left_sprites = load_movement_sprites("left", 5)
|
left_sprites = load_movement_sprites("left", 5)
|
||||||
right_sprites = load_movement_sprites("right", 5)
|
right_sprites = load_movement_sprites("right", 5)
|
||||||
|
|
||||||
|
# Игрок
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
self.x = x
|
self.x = x
|
||||||
|
@ -39,6 +41,7 @@ class Player:
|
||||||
def draw(self):
|
def draw(self):
|
||||||
screen.blit(self.movement_sprites[self.current_movement][self.current_sprite_index], (self.x, self.y))
|
screen.blit(self.movement_sprites[self.current_movement][self.current_sprite_index], (self.x, self.y))
|
||||||
|
|
||||||
|
# Камера
|
||||||
class Camera:
|
class Camera:
|
||||||
def __init__(self, width, height):
|
def __init__(self, width, height):
|
||||||
self.width = width
|
self.width = width
|
||||||
|
@ -55,6 +58,7 @@ class Camera:
|
||||||
self.x = -target.x + self.width // 2
|
self.x = -target.x + self.width // 2
|
||||||
self.y = -target.y + self.height // 2
|
self.y = -target.y + self.height // 2
|
||||||
|
|
||||||
|
# Стена
|
||||||
class Wall(pygame.sprite.Sprite):
|
class Wall(pygame.sprite.Sprite):
|
||||||
def __init__(self, color, size, pos):
|
def __init__(self, color, size, pos):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -62,6 +66,7 @@ class Wall(pygame.sprite.Sprite):
|
||||||
self.image.fill(color)
|
self.image.fill(color)
|
||||||
self.rect = self.image.get_rect(center=pos)
|
self.rect = self.image.get_rect(center=pos)
|
||||||
|
|
||||||
|
# Кнопка
|
||||||
class Button:
|
class Button:
|
||||||
def __init__(self, up_image_path, over_image_path, position):
|
def __init__(self, up_image_path, over_image_path, position):
|
||||||
self.up_image = pygame.image.load(up_image_path)
|
self.up_image = pygame.image.load(up_image_path)
|
||||||
|
@ -79,20 +84,30 @@ class Button:
|
||||||
else:
|
else:
|
||||||
self.image = self.up_image
|
self.image = self.up_image
|
||||||
|
|
||||||
|
# Класс игрового состояния
|
||||||
|
class GameState:
|
||||||
|
MENU = 0
|
||||||
|
GAMEPLAY = 1
|
||||||
|
|
||||||
|
# Инициализация Pygame
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
# Настройки
|
# Настройки
|
||||||
FPS = 60
|
FPS = 60
|
||||||
BACKGROUND_IMAGE = "background.png"
|
BACKGROUND_IMAGE = "background.png"
|
||||||
FONT, SIZE = 'comicsansms', 14
|
FONT, SIZE = 'comicsansms', 14
|
||||||
|
|
||||||
screen_info = pygame.display.Info() # Пока-что пусть будет
|
# Информация о экране
|
||||||
|
screen_info = pygame.display.Info()
|
||||||
screen = pygame.display.set_mode((1920, 1080), pygame.FULLSCREEN)
|
screen = pygame.display.set_mode((1920, 1080), pygame.FULLSCREEN)
|
||||||
pygame.display.set_caption('Hell Circus')
|
pygame.display.set_caption('Hell Circus')
|
||||||
programIcon = pygame.image.load('icon.png')
|
programIcon = pygame.image.load('icon.png')
|
||||||
pygame.display.set_icon(programIcon)
|
pygame.display.set_icon(programIcon)
|
||||||
|
|
||||||
|
# Шрифт
|
||||||
font = pygame.font.SysFont(FONT, SIZE)
|
font = pygame.font.SysFont(FONT, SIZE)
|
||||||
|
|
||||||
|
# Часы и время
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
deltatime = 0
|
deltatime = 0
|
||||||
running = True
|
running = True
|
||||||
|
@ -102,11 +117,13 @@ play_button = Button("play1.png", "play2.png", (125, 3))
|
||||||
continue_button = Button("continue1.png", "continue2.png", (110, 3))
|
continue_button = Button("continue1.png", "continue2.png", (110, 3))
|
||||||
menu_button = Button("menu1.png", "menu2.png", (95, 3))
|
menu_button = Button("menu1.png", "menu2.png", (95, 3))
|
||||||
|
|
||||||
|
# Стены, тут надо всё менять
|
||||||
walls = pygame.sprite.Group(Wall("white", (1280, 20), (640, 0)), Wall("white", (1280, 20), (640, 720)),
|
walls = pygame.sprite.Group(Wall("white", (1280, 20), (640, 0)), Wall("white", (1280, 20), (640, 720)),
|
||||||
Wall("white", (20, 720), (0, 360)), Wall("white", (1280, 20), (1280, 720)),
|
Wall("white", (20, 720), (0, 360)), Wall("white", (1280, 20), (1280, 720)),
|
||||||
Wall("white", (200, 20), (640, 360)), Wall("white", (20, 200), (640, 360)),
|
Wall("white", (200, 20), (640, 360)), Wall("white", (20, 200), (640, 360)),
|
||||||
Wall("white", (1280, 20), (1280, 320)))
|
Wall("white", (1280, 20), (1280, 320)))
|
||||||
|
|
||||||
|
# Класс персонажа
|
||||||
class Character(pygame.sprite.Sprite):
|
class Character(pygame.sprite.Sprite):
|
||||||
def __init__(self, x, y, width, height, color, name):
|
def __init__(self, x, y, width, height, color, name):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -115,6 +132,7 @@ class Character(pygame.sprite.Sprite):
|
||||||
self.rect = self.image.get_rect(topleft=(x, y))
|
self.rect = self.image.get_rect(topleft=(x, y))
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
# Класс игрока
|
||||||
class Player(pygame.sprite.Sprite):
|
class Player(pygame.sprite.Sprite):
|
||||||
def __init__(self, x, y, width, height, color):
|
def __init__(self, x, y, width, height, color):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -122,19 +140,18 @@ class Player(pygame.sprite.Sprite):
|
||||||
self.image.fill(color)
|
self.image.fill(color)
|
||||||
self.rect = self.image.get_rect(topleft=(x, y))
|
self.rect = self.image.get_rect(topleft=(x, y))
|
||||||
|
|
||||||
|
# Камера
|
||||||
camera = Camera(1920, 1080)
|
camera = Camera(1920, 1080)
|
||||||
|
|
||||||
player = Player(200, 200, 50, 50, (255, 0, 0))
|
player = Player(200, 200, 50, 50, (255, 0, 0))
|
||||||
character1 = Character(200, 200, 50, 50, "red", "Character 1")
|
character1 = Character(200, 200, 50, 50, "red", "Character 1")
|
||||||
character2 = Character(400, 300, 50, 50, "blue", "Character 2")
|
character2 = Character(400, 300, 50, 50, "blue", "Character 2")
|
||||||
|
|
||||||
|
# Группы спрайтов
|
||||||
character_sprites = pygame.sprite.Group(character1, character2)
|
character_sprites = pygame.sprite.Group(character1, character2)
|
||||||
player_sprite = pygame.sprite.Group(player)
|
player_sprite = pygame.sprite.Group(player)
|
||||||
|
|
||||||
# Менюм / Игровой режим
|
# Игровое состояние
|
||||||
class GameState:
|
|
||||||
MENU = 0
|
|
||||||
GAMEPLAY = 1
|
|
||||||
|
|
||||||
current_state = GameState.MENU
|
current_state = GameState.MENU
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
|
@ -146,16 +163,13 @@ while running:
|
||||||
running = False
|
running = False
|
||||||
|
|
||||||
if current_state == GameState.MENU:
|
if current_state == GameState.MENU:
|
||||||
|
|
||||||
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
||||||
mouse_x, mouse_y = pygame.mouse.get_pos()
|
mouse_x, mouse_y = pygame.mouse.get_pos()
|
||||||
|
|
||||||
if play_button.is_hovered((mouse_x, mouse_y)):
|
if play_button.is_hovered((mouse_x, mouse_y)):
|
||||||
# Переход в игровой режим
|
# Переход в игровой режим
|
||||||
current_state = GameState.GAMEPLAY
|
current_state = GameState.GAMEPLAY
|
||||||
|
|
||||||
elif current_state == GameState.GAMEPLAY:
|
elif current_state == GameState.GAMEPLAY:
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_e:
|
if event.key == pygame.K_e:
|
||||||
nearest_character = min(character_sprites, key=lambda c: pygame.math.Vector2(c.rect.center).distance_to(player.rect.center))
|
nearest_character = min(character_sprites, key=lambda c: pygame.math.Vector2(c.rect.center).distance_to(player.rect.center))
|
||||||
|
|
Loading…
Reference in New Issue