Upload files to "/"
jauns dizains
parent
353ae21df2
commit
6bf1ee9ee1
Binary file not shown.
|
After Width: | Height: | Size: 144 KiB |
430
game.py
430
game.py
|
|
@ -1,6 +1,7 @@
|
|||
import pygame
|
||||
import random
|
||||
import sys
|
||||
import os
|
||||
|
||||
# --- Inicializācija ---
|
||||
pygame.init()
|
||||
|
|
@ -11,7 +12,7 @@ SCREEN = pygame.display.set_mode((WIDTH, HEIGHT))
|
|||
pygame.display.set_caption("Pixel Kombat: Ultimate")
|
||||
CLOCK = pygame.time.Clock()
|
||||
|
||||
# --- Krāsas ---
|
||||
# --- KRĀSAS ---
|
||||
WHITE = (255, 255, 255)
|
||||
BLACK = (0, 0, 0)
|
||||
RED = (255, 0, 0)
|
||||
|
|
@ -19,13 +20,35 @@ BLUE = (0, 0, 255)
|
|||
GRAY = (50, 50, 50)
|
||||
DARK_GRAY = (20, 20, 20)
|
||||
YELLOW = (255, 215, 0)
|
||||
BROWN = (139, 69, 19)
|
||||
GREEN = (50, 200, 50)
|
||||
CYAN = (0, 255, 255)
|
||||
PURPLE = (160, 32, 240)
|
||||
|
||||
# Pieejamās raksturu krāsas
|
||||
COLORS = [
|
||||
# --- Fonti ---
|
||||
def get_font(name, size):
|
||||
if os.path.exists(name):
|
||||
try:
|
||||
return pygame.font.Font(name, size)
|
||||
except:
|
||||
return pygame.font.SysFont('arial', size)
|
||||
else:
|
||||
return pygame.font.SysFont('arial', size)
|
||||
|
||||
FONT_BIG = get_font("Act_Of_Rejection.ttf", 80)
|
||||
FONT_MED = get_font("PressStart2P-Regular.ttf", 36)
|
||||
FONT_SMALL = get_font("PressStart2P-Regular.ttf", 20)
|
||||
FONT_TINY = get_font("PressStart2P-Regular.ttf", 14)
|
||||
|
||||
# --- GLOBĀLIE MAINĪGIE ---
|
||||
STATE = "MENU"
|
||||
SELECTED_BG = "BEACH"
|
||||
|
||||
# ============================================================
|
||||
# --- TĒLU UN FONA DATU BĀZES ---
|
||||
# ============================================================
|
||||
|
||||
# Krāsu palešu fallback attēliem
|
||||
FALLBACK_COLORS = [
|
||||
(235, 64, 52), # Red
|
||||
(52, 119, 235), # Blue
|
||||
(52, 235, 86), # Green
|
||||
|
|
@ -34,67 +57,129 @@ COLORS = [
|
|||
(255, 105, 180) # Pink
|
||||
]
|
||||
|
||||
# --- Fonti (ar rezerves variantu) ---
|
||||
def get_font(name, size):
|
||||
CHARACTER_FILES = [
|
||||
"characters/first_char.png",
|
||||
"characters/second_char.png",
|
||||
"characters/third_char.png",
|
||||
"characters/forth_char.png",
|
||||
"characters/fifth_char.png",
|
||||
"characters/sixth_char.png"
|
||||
]
|
||||
|
||||
P1_CHAR_INDEX = 0
|
||||
P2_CHAR_INDEX = 1
|
||||
|
||||
# Fona faili (failu nosaukumi)
|
||||
BG_FILES = {
|
||||
"BEACH": "backgrounds/beach.jpg",
|
||||
"EVENINGSTREET": "backgrounds/evening_street.jpg",
|
||||
"MARKET": "backgrounds/market.jpg",
|
||||
"RESTAURANT": "backgrounds/restaurant.jpg",
|
||||
"SAKURASTREET": "backgrounds/sakura_street.jpg",
|
||||
"SHIP": "backgrounds/ship.jpg",
|
||||
"STREETMARKETS": "backgrounds/street_markets.jpg"
|
||||
}
|
||||
|
||||
# Failu ielādes funkcijas
|
||||
def create_placeholder_image(color, size=(80, 160), text=""):
|
||||
"""Izveido vienkāršu attēlu, ja fails nav atrasts."""
|
||||
surf = pygame.Surface(size)
|
||||
surf.fill(color)
|
||||
pygame.draw.rect(surf, BLACK, (0, 0, size[0], size[1]), 2)
|
||||
|
||||
# Galva (piemērota lielākam izmēram)
|
||||
head_w = size[0] * 0.4
|
||||
head_h = size[1] * 0.3
|
||||
head_rect = pygame.Rect(size[0]//2 - head_w//2, 10, head_w, head_h)
|
||||
pygame.draw.rect(surf, (200, 200, 200), head_rect)
|
||||
pygame.draw.rect(surf, BLACK, head_rect, 2)
|
||||
|
||||
# Acis
|
||||
eye_y = head_rect.y + head_h // 3
|
||||
pygame.draw.circle(surf, BLACK, (int(head_rect.centerx - head_w//5), int(eye_y)), 4)
|
||||
pygame.draw.circle(surf, BLACK, (int(head_rect.centerx + head_w//5), int(eye_y)), 4)
|
||||
|
||||
if text:
|
||||
font = pygame.font.SysFont('arial', 18)
|
||||
txt = font.render(text, True, WHITE)
|
||||
surf.blit(txt, (size[0]//2 - txt.get_width()//2, size[1] - 30))
|
||||
|
||||
return surf
|
||||
|
||||
def load_character_images():
|
||||
chars_data = []
|
||||
|
||||
# === IZMĒRU IESTATĪJUMI (ŠEIT MAINĪTS) ===
|
||||
SPRITE_SIZE = (80, 150)
|
||||
ICON_SIZE = (100, 100)
|
||||
|
||||
for i, filename in enumerate(CHARACTER_FILES):
|
||||
color = FALLBACK_COLORS[i % len(FALLBACK_COLORS)]
|
||||
try:
|
||||
if os.path.exists(filename):
|
||||
img = pygame.image.load(filename).convert_alpha()
|
||||
game_img = pygame.transform.scale(img, SPRITE_SIZE)
|
||||
icon_img = pygame.transform.scale(img, ICON_SIZE)
|
||||
else:
|
||||
raise FileNotFoundError
|
||||
except:
|
||||
# Ja faila nav, veidojam lielu "placeholder"
|
||||
game_img = create_placeholder_image(color, SPRITE_SIZE, f"T{i+1}")
|
||||
|
||||
# Ikonas placeholder
|
||||
icon_surf = pygame.Surface(ICON_SIZE)
|
||||
icon_surf.fill(color)
|
||||
pygame.draw.rect(icon_surf, WHITE, (0,0,ICON_SIZE[0], ICON_SIZE[1]), 2)
|
||||
font = pygame.font.SysFont('arial', 24)
|
||||
txt = font.render(f"Char {i+1}", True, WHITE)
|
||||
icon_surf.blit(txt, (ICON_SIZE[0]//2 - txt.get_width()//2, ICON_SIZE[1]//2 - txt.get_height()//2))
|
||||
icon_img = icon_surf
|
||||
|
||||
chars_data.append({
|
||||
'game_img': game_img,
|
||||
'icon': icon_img,
|
||||
'color': color
|
||||
})
|
||||
return chars_data
|
||||
|
||||
def load_image_safe(filename, fallback_color):
|
||||
try:
|
||||
return pygame.font.Font(name, size)
|
||||
except FileNotFoundError:
|
||||
# Ja fonts nav atrasts, izmanto noklusējuma sistēmas fontu
|
||||
return pygame.font.SysFont('arial', size)
|
||||
if os.path.exists(filename):
|
||||
img = pygame.image.load(filename)
|
||||
img = pygame.transform.scale(img, (WIDTH, HEIGHT))
|
||||
return img
|
||||
else:
|
||||
raise FileNotFoundError
|
||||
except:
|
||||
surf = pygame.Surface((WIDTH, HEIGHT))
|
||||
surf.fill(fallback_color)
|
||||
return surf
|
||||
|
||||
FONT_BIG = get_font("Act_Of_Rejection.ttf", 80)
|
||||
FONT_MED = get_font("PressStart2P-Regular.ttf", 36)
|
||||
FONT_SMALL = get_font("PressStart2P-Regular.ttf", 20)
|
||||
FONT_TINY = get_font("PressStart2P-Regular.ttf", 14)
|
||||
# --- RESURSU IELĀDE ---
|
||||
CHARACTERS = load_character_images()
|
||||
|
||||
# --- Globālie mainīgie (Spēles stāvokļi) ---
|
||||
STATE = "MENU" # MENU, CHAR_SELECT, BG_SELECT, DIALOGUE, GAME, GAMEOVER
|
||||
SELECTED_BG = "CITY"
|
||||
P1_COLOR = COLORS[0] # Noklusējums
|
||||
P2_COLOR = COLORS[1] # Noklusējums
|
||||
|
||||
# --- Fona Ģenerators (Lai novērstu mirgošanu) ---
|
||||
BG_ELEMENTS = []
|
||||
|
||||
def generate_bg_elements(bg_name):
|
||||
global BG_ELEMENTS
|
||||
BG_ELEMENTS = []
|
||||
if bg_name == "CITY":
|
||||
for i in range(5):
|
||||
w = random.randint(80, 150)
|
||||
h = random.randint(200, 400)
|
||||
x = i * (WIDTH // 5) + 20
|
||||
BG_ELEMENTS.append({'rect': pygame.Rect(x, HEIGHT - 50 - h, w-10, h)})
|
||||
elif bg_name == "FOREST":
|
||||
for i in range(8):
|
||||
x = i * (WIDTH // 8) + 40
|
||||
BG_ELEMENTS.append({'x': x})
|
||||
|
||||
# Inicializējam pirmo reizi
|
||||
generate_bg_elements("CITY")
|
||||
bg_images = {}
|
||||
for key, path in BG_FILES.items():
|
||||
# Vienkāršotas krāsas fallback
|
||||
cols = {"BEACH": (194, 178, 128), "EVENINGSTREET": (30, 30, 50), "MARKET": (100, 80, 60),
|
||||
"RESTAURANT": (150, 100, 50), "SAKURASTREET": (255, 183, 197), "SHIP": (0, 105, 148),
|
||||
"STREETMARKETS": (90, 90, 90)}
|
||||
bg_images[key] = load_image_safe(path, cols.get(key, GRAY))
|
||||
|
||||
# --- UI Klases ---
|
||||
|
||||
class Button:
|
||||
def __init__(self, x, y, w, h, text, color, hover_color, action_code):
|
||||
# Rect tiek izmantots tikai klikšķu noteikšanai (invisible hitbox)
|
||||
self.rect = pygame.Rect(x, y, w, h)
|
||||
self.text = text
|
||||
self.color = color # Teksta krāsa (normāla)
|
||||
self.hover_color = hover_color # Teksta krāsa (pele virsū)
|
||||
self.color = color
|
||||
self.hover_color = hover_color
|
||||
self.action_code = action_code
|
||||
|
||||
def draw(self, surface):
|
||||
mouse_pos = pygame.mouse.get_pos()
|
||||
is_hovered = self.rect.collidepoint(mouse_pos)
|
||||
|
||||
# Izvēlamies krāsu atkarībā no peles pozīcijas
|
||||
current_color = self.hover_color if is_hovered else self.color
|
||||
|
||||
# Taisnstūrus ZĪMĒT NEVARAM (dzēsts pēc pieprasījuma)
|
||||
# pygame.draw.rect(surface, current_color, self.rect)
|
||||
|
||||
# Zīmējam tikai tekstu, kas ir centrēts rect iekšpusē
|
||||
text_surf = FONT_SMALL.render(self.text, True, current_color)
|
||||
surface.blit(text_surf, (self.rect.centerx - text_surf.get_width()//2, self.rect.centery - text_surf.get_height()//2))
|
||||
|
||||
|
|
@ -106,15 +191,19 @@ class Button:
|
|||
|
||||
# --- Klase Spēlētājam ---
|
||||
class Fighter(pygame.sprite.Sprite):
|
||||
def __init__(self, x, y, color, facing_right, controls):
|
||||
def __init__(self, x, y, char_data, facing_right, controls):
|
||||
super().__init__()
|
||||
self.original_color = color
|
||||
self.color = color
|
||||
self.char_data = char_data
|
||||
self.image = char_data['game_img']
|
||||
self.color_accent = char_data['color']
|
||||
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect.center = (x, y)
|
||||
self.rect.bottom = HEIGHT - 50 # Grīdas līmenis
|
||||
|
||||
self.rect = pygame.Rect(x, y, 50, 100)
|
||||
self.vel_y = 0
|
||||
self.speed = 7
|
||||
self.jump_power = -18
|
||||
self.jump_power = -20 # Nedaudz lielāks lecams augstums lielākam tēlam
|
||||
self.gravity = 0.8
|
||||
self.on_ground = False
|
||||
|
||||
|
|
@ -155,10 +244,11 @@ class Fighter(pygame.sprite.Sprite):
|
|||
if self.attack_cooldown == 0:
|
||||
self.attacking = True
|
||||
self.attack_cooldown = 20
|
||||
# Uzbrukuma kaste pieregulēta lielākam tēlam
|
||||
if self.facing_right:
|
||||
self.attack_box = pygame.Rect(self.rect.right, self.rect.y + 20, 60, 50)
|
||||
self.attack_box = pygame.Rect(self.rect.right, self.rect.y + 40, 80, 80)
|
||||
else:
|
||||
self.attack_box = pygame.Rect(self.rect.left - 60, self.rect.y + 20, 60, 50)
|
||||
self.attack_box = pygame.Rect(self.rect.left - 80, self.rect.y + 40, 80, 80)
|
||||
|
||||
def update(self):
|
||||
if self.attack_cooldown > 0: self.attack_cooldown -= 1
|
||||
|
|
@ -166,23 +256,14 @@ class Fighter(pygame.sprite.Sprite):
|
|||
|
||||
if self.hit_timer > 0:
|
||||
self.hit_timer -= 1
|
||||
self.color = WHITE
|
||||
else:
|
||||
self.color = self.original_color
|
||||
|
||||
def draw(self, surface):
|
||||
pygame.draw.rect(surface, self.color, self.rect)
|
||||
pygame.draw.rect(surface, BLACK, self.rect, 2)
|
||||
|
||||
head_rect = pygame.Rect(self.rect.x + 10, self.rect.y - 20, 30, 20)
|
||||
pygame.draw.rect(surface, self.color, head_rect)
|
||||
pygame.draw.rect(surface, BLACK, head_rect, 2)
|
||||
|
||||
eye_color = BLACK
|
||||
if self.facing_right:
|
||||
pygame.draw.rect(surface, eye_color, (self.rect.x + 30, self.rect.y - 15, 5, 5))
|
||||
img_to_draw = self.image
|
||||
else:
|
||||
pygame.draw.rect(surface, eye_color, (self.rect.x + 15, self.rect.y - 15, 5, 5))
|
||||
img_to_draw = pygame.transform.flip(self.image, True, False)
|
||||
|
||||
surface.blit(img_to_draw, self.rect)
|
||||
|
||||
if self.attacking:
|
||||
pygame.draw.rect(surface, YELLOW, self.attack_box)
|
||||
|
|
@ -195,58 +276,15 @@ class Fighter(pygame.sprite.Sprite):
|
|||
if self.rect.centerx < WIDTH // 2: self.rect.x -= 20
|
||||
else: self.rect.x += 20
|
||||
|
||||
# --- Fona Zīmēšanas Funkcijas ---
|
||||
|
||||
def draw_city(surface):
|
||||
surface.fill((20, 30, 50)) # Nakts debesis
|
||||
pygame.draw.circle(surface, (200, 200, 200), (WIDTH//2, 100), 60) # Mēness
|
||||
|
||||
# Zīmējam iepriekš ģenerētās ēkas
|
||||
for elem in BG_ELEMENTS:
|
||||
pygame.draw.rect(surface, (10, 10, 20), elem['rect'])
|
||||
|
||||
pygame.draw.rect(surface, BROWN, (0, HEIGHT - 50, WIDTH, 50)) # Zeme
|
||||
|
||||
def draw_forest(surface):
|
||||
surface.fill((50, 150, 50)) # Gaiši zaļš debesis/ugs
|
||||
pygame.draw.circle(surface, (255, 255, 100), (WIDTH - 100, 80), 50) # Saule
|
||||
|
||||
# Zīmējam iepriekš ģenerētos kokus
|
||||
for elem in BG_ELEMENTS:
|
||||
x = elem['x']
|
||||
# Koku stumbri
|
||||
pygame.draw.rect(surface, (80, 50, 20), (x, HEIGHT - 200, 40, 150))
|
||||
# Koku vainagi (trīsstūri stilā)
|
||||
pygame.draw.polygon(surface, (20, 100, 20), [(x-40, HEIGHT-200), (x+40, HEIGHT-200), (x, HEIGHT-300)])
|
||||
pygame.draw.polygon(surface, (20, 100, 20), [(x-35, HEIGHT-240), (x+35, HEIGHT-240), (x, HEIGHT-340)])
|
||||
|
||||
pygame.draw.rect(surface, (30, 100, 30), (0, HEIGHT - 50, WIDTH, 50)) # Zāle
|
||||
|
||||
def draw_dojo(surface):
|
||||
surface.fill((180, 100, 50)) # Koka sieni
|
||||
# Girdīngs
|
||||
pygame.draw.rect(surface, (100, 50, 0), (0, HEIGHT - 200, WIDTH, 50))
|
||||
pygame.draw.rect(surface, (100, 50, 0), (0, 0, WIDTH, 50))
|
||||
# Vairogzīmes
|
||||
for i in range(1, 10):
|
||||
x = i * (WIDTH // 10)
|
||||
pygame.draw.line(surface, (50, 0, 0), (x, 50), (x, HEIGHT - 200), 2)
|
||||
pygame.draw.rect(surface, (50, 0, 0), (0, HEIGHT - 50, WIDTH, 50)) # Sarkanā grīda
|
||||
|
||||
def get_bg_function(name):
|
||||
if name == "CITY": return draw_city
|
||||
if name == "FOREST": return draw_forest
|
||||
return draw_dojo
|
||||
# --- Fona Zīmēšana ---
|
||||
def draw_background(surface, bg_name):
|
||||
img = bg_images.get(bg_name, list(bg_images.values())[0])
|
||||
surface.blit(img, (0, 0))
|
||||
|
||||
# --- Dialogi ---
|
||||
class DialogueManager:
|
||||
def __init__(self):
|
||||
self.lines = [
|
||||
"PREPARE FOR BATTLE!",
|
||||
"Who will win today?",
|
||||
"Fight with honor!",
|
||||
"Show me your moves!"
|
||||
]
|
||||
self.lines = ["PREPARE FOR BATTLE!", "Who will win today?", "Fight with honor!", "Show me your moves!"]
|
||||
self.current_text = random.choice(self.lines)
|
||||
self.active = False
|
||||
self.timer = 0
|
||||
|
|
@ -258,54 +296,46 @@ class DialogueManager:
|
|||
|
||||
def draw(self, surface):
|
||||
if not self.active: return
|
||||
|
||||
# Kaste
|
||||
box_rect = pygame.Rect(WIDTH//2 - 300, HEIGHT//2 - 50, 600, 100)
|
||||
pygame.draw.rect(surface, BLACK, box_rect)
|
||||
pygame.draw.rect(surface, WHITE, box_rect, 4)
|
||||
|
||||
# Teksts
|
||||
text_surf = FONT_MED.render(self.current_text, True, YELLOW)
|
||||
surface.blit(text_surf, (box_rect.centerx - text_surf.get_width()//2, box_rect.centery - text_surf.get_height()//2))
|
||||
|
||||
# Instrukcija
|
||||
sub_surf = FONT_SMALL.render("Nospiediet [SPACE] lai sāktu", True, WHITE)
|
||||
sub_surf = FONT_SMALL.render("Nospiediet [SPACE] lai saktu", True, WHITE)
|
||||
surface.blit(sub_surf, (box_rect.centerx - sub_surf.get_width()//2, box_rect.bottom + 10))
|
||||
|
||||
# --- Galvenā Spēle ---
|
||||
|
||||
def main():
|
||||
global STATE, P1_COLOR, P2_COLOR, SELECTED_BG, BG_ELEMENTS
|
||||
global STATE, P1_CHAR_INDEX, P2_CHAR_INDEX, SELECTED_BG
|
||||
|
||||
# Kontroles
|
||||
controls_p1 = {'left': pygame.K_a, 'right': pygame.K_d, 'jump': pygame.K_w, 'attack': pygame.K_SPACE}
|
||||
controls_p2 = {'left': pygame.K_LEFT, 'right': pygame.K_RIGHT, 'jump': pygame.K_UP, 'attack': pygame.K_RETURN}
|
||||
|
||||
dialogue_mgr = DialogueManager()
|
||||
|
||||
# Izveidojam pogas (Bez taisnstūriem, teksta krāsas)
|
||||
# Zila krāsa parasti, Sarkana izceļot (pelei virsū)
|
||||
menu_buttons = [
|
||||
Button(WIDTH//2 - 100, 250, 200, 50, "Sakt Cinu", BLUE, RED, "START"),
|
||||
Button(WIDTH//2 - 100, 320, 200, 50, "Telu Izvele", BLUE, RED, "CHARS"),
|
||||
Button(WIDTH//2 - 100, 390, 200, 50, "Fona Izvele", BLUE, RED, "BG"),
|
||||
Button(WIDTH//2 - 100, 460, 200, 50, "Iziet", RED, YELLOW, "QUIT") # Iziet ir sarkans, kļūst dzeltens
|
||||
Button(WIDTH//2 - 100, 460, 200, 50, "Iziet", RED, YELLOW, "QUIT")
|
||||
]
|
||||
|
||||
# Šeit arī nomainām krāsas, lai būtu redzams uz fona (jo rect vairs nav)
|
||||
bg_buttons = [
|
||||
Button(200, 300, 150, 100, "CITY", WHITE, YELLOW, "CITY"),
|
||||
Button(425, 300, 150, 100, "FOREST", WHITE, YELLOW, "FOREST"),
|
||||
Button(650, 300, 150, 100, "DOJO", WHITE, YELLOW, "DOJO"),
|
||||
Button(150, 200, 200, 50, "Beach", WHITE, YELLOW, "BEACH"),
|
||||
Button(412, 200, 200, 50, "Evening St.", WHITE, YELLOW, "EVENINGSTREET"),
|
||||
Button(674, 200, 200, 50, "Market", WHITE, YELLOW, "MARKET"),
|
||||
Button(150, 280, 200, 50, "Restaurant", WHITE, YELLOW, "RESTAURANT"),
|
||||
Button(412, 280, 200, 50, "Sakura St.", WHITE, YELLOW, "SAKURASTREET"),
|
||||
Button(674, 280, 200, 50, "Ship", WHITE, YELLOW, "SHIP"),
|
||||
Button(WIDTH//2 - 100, 360, 200, 50, "Street Markets", WHITE, YELLOW, "STREETMARKETS"),
|
||||
Button(WIDTH//2 - 100, 450, 200, 50, "Atpakal", GRAY, WHITE, "BACK")
|
||||
]
|
||||
|
||||
back_btn = Button(20, 20, 100, 40, "Atpakal", GRAY, WHITE, "BACK")
|
||||
back_btn_chars = Button(WIDTH//2 - 100, HEIGHT - 80, 200, 50, "Atpakal", GRAY, WHITE, "BACK")
|
||||
|
||||
# Spēlētāji
|
||||
fighter1 = None
|
||||
fighter2 = None
|
||||
winner = "PLAYER 1" # Noklusējuma vērtība
|
||||
winner = "PLAYER 1"
|
||||
|
||||
run = True
|
||||
while run:
|
||||
|
|
@ -315,7 +345,6 @@ def main():
|
|||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
# Pogu apstrāde atkarībā no stāvokļa
|
||||
if STATE == "MENU":
|
||||
for btn in menu_buttons:
|
||||
if btn.is_clicked(event):
|
||||
|
|
@ -330,19 +359,26 @@ def main():
|
|||
run = False
|
||||
|
||||
elif STATE == "CHAR_SELECT":
|
||||
# P1 izvēle
|
||||
for i, color in enumerate(COLORS):
|
||||
rect = pygame.Rect(150 + i*60, 200, 50, 50)
|
||||
if event.type == pygame.MOUSEBUTTONDOWN and rect.collidepoint(event.pos):
|
||||
P1_COLOR = color
|
||||
# P1 izvēle (Augšējā rinda)
|
||||
icon_w = 100
|
||||
gap = 10
|
||||
total_w = len(CHARACTERS) * icon_w + (len(CHARACTERS)-1) * gap
|
||||
start_x = (WIDTH - total_w) // 2
|
||||
y_p1 = 150
|
||||
|
||||
# P2 izvēle
|
||||
for i, color in enumerate(COLORS):
|
||||
rect = pygame.Rect(WIDTH - 450 + i*60, 200, 50, 50)
|
||||
if event.type == pygame.MOUSEBUTTONDOWN and rect.collidepoint(event.pos):
|
||||
P2_COLOR = color
|
||||
for i, char in enumerate(CHARACTERS):
|
||||
icon_rect = pygame.Rect(start_x + i * (icon_w + gap), y_p1, icon_w, icon_w)
|
||||
if event.type == pygame.MOUSEBUTTONDOWN and icon_rect.collidepoint(event.pos):
|
||||
P1_CHAR_INDEX = i
|
||||
|
||||
if back_btn.is_clicked(event):
|
||||
# P2 izvēle (Apakšējā rinda)
|
||||
y_p2 = 350
|
||||
for i, char in enumerate(CHARACTERS):
|
||||
icon_rect = pygame.Rect(start_x + i * (icon_w + gap), y_p2, icon_w, icon_w)
|
||||
if event.type == pygame.MOUSEBUTTONDOWN and icon_rect.collidepoint(event.pos):
|
||||
P2_CHAR_INDEX = i
|
||||
|
||||
if back_btn_chars.is_clicked(event):
|
||||
STATE = "MENU"
|
||||
|
||||
elif STATE == "BG_SELECT":
|
||||
|
|
@ -352,14 +388,12 @@ def main():
|
|||
STATE = "MENU"
|
||||
else:
|
||||
SELECTED_BG = btn.action_code
|
||||
generate_bg_elements(SELECTED_BG) # Ģenerējam jaunu fonu
|
||||
|
||||
elif STATE == "DIALOGUE":
|
||||
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
|
||||
dialogue_mgr.active = False
|
||||
# Inicializējam spēli
|
||||
fighter1 = Fighter(200, 300, P1_COLOR, True, controls_p1)
|
||||
fighter2 = Fighter(800, 300, P2_COLOR, False, controls_p2)
|
||||
fighter1 = Fighter(200, 300, CHARACTERS[P1_CHAR_INDEX], True, controls_p1)
|
||||
fighter2 = Fighter(800, 300, CHARACTERS[P2_CHAR_INDEX], False, controls_p2)
|
||||
STATE = "GAME"
|
||||
|
||||
elif STATE == "GAME":
|
||||
|
|
@ -371,80 +405,81 @@ def main():
|
|||
if event.type == pygame.KEYDOWN and event.key == pygame.K_r:
|
||||
STATE = "MENU"
|
||||
|
||||
# --- Zīmēšanas Loģika un Update ---
|
||||
# --- Zīmēšana ---
|
||||
|
||||
if STATE == "MENU":
|
||||
SCREEN.fill(BLACK)
|
||||
|
||||
# --- LOGOTIPS (Street Fighter stils) ---
|
||||
title_text = "PIXEL KOMBAT"
|
||||
|
||||
# Ēna (Sarkana)
|
||||
shadow_text = FONT_BIG.render(title_text, True, (180, 0, 0))
|
||||
SCREEN.blit(shadow_text, (WIDTH//2 - shadow_text.get_width()//2 + 3, 53))
|
||||
|
||||
# Galvenais teksts (Dzeltena)
|
||||
main_text = FONT_BIG.render(title_text, True, YELLOW)
|
||||
SCREEN.blit(main_text, (WIDTH//2 - main_text.get_width()//2, 50))
|
||||
|
||||
# Apakšvirsraksts
|
||||
sub_text = "- ULTIMATE EDITION -"
|
||||
sub_surf = FONT_SMALL.render(sub_text, True, WHITE)
|
||||
SCREEN.blit(sub_surf, (WIDTH//2 - sub_surf.get_width()//2, 130))
|
||||
|
||||
# --- POGAS (Tikai teksts) ---
|
||||
for btn in menu_buttons:
|
||||
btn.draw(SCREEN)
|
||||
for btn in menu_buttons: btn.draw(SCREEN)
|
||||
|
||||
# --- APAKŠĒJĀ INFORMĀCIJA ---
|
||||
# Copyright
|
||||
cp_text = "© PIXEL KOMBAT 2024"
|
||||
cp_text = "© PIXEL KOMBAT 2026"
|
||||
cp_surf = FONT_TINY.render(cp_text, True, WHITE)
|
||||
SCREEN.blit(cp_surf, (WIDTH//2 - cp_surf.get_width()//2, HEIGHT - 30))
|
||||
|
||||
# Credits (Labajā pusē)
|
||||
credit_text = "CREDIT 01"
|
||||
credit_surf = FONT_SMALL.render(credit_text, True, YELLOW)
|
||||
SCREEN.blit(credit_surf, (WIDTH - 180, HEIGHT - 30))
|
||||
|
||||
elif STATE == "CHAR_SELECT":
|
||||
SCREEN.fill(DARK_GRAY)
|
||||
title = FONT_MED.render("IZVELIES TELU", True, WHITE)
|
||||
SCREEN.blit(title, (WIDTH//2 - title.get_width()//2, 50))
|
||||
|
||||
p1_text = FONT_SMALL.render("PLAYER 1", True, P1_COLOR)
|
||||
SCREEN.blit(p1_text, (200, 150))
|
||||
for i, color in enumerate(COLORS):
|
||||
r = pygame.Rect(150 + i*60, 200, 50, 50)
|
||||
pygame.draw.rect(SCREEN, color, r)
|
||||
pygame.draw.rect(SCREEN, WHITE, r, 2 if color != P1_COLOR else 5)
|
||||
# Teksts
|
||||
title1 = FONT_SMALL.render("IZVELIES TELU", True, WHITE)
|
||||
SCREEN.blit(title1, (WIDTH//2 - title1.get_width()//2, 30))
|
||||
title2 = FONT_TINY.render("(Uzspied uz ikonas)", True, GRAY)
|
||||
SCREEN.blit(title2, (WIDTH//2 - title2.get_width()//2, 60))
|
||||
|
||||
# Zīmējam P2 paneli
|
||||
p2_text = FONT_SMALL.render("PLAYER 2", True, P2_COLOR)
|
||||
SCREEN.blit(p2_text, (WIDTH - 350, 150))
|
||||
for i, color in enumerate(COLORS):
|
||||
r = pygame.Rect(WIDTH - 450 + i*60, 200, 50, 50)
|
||||
pygame.draw.rect(SCREEN, color, r)
|
||||
pygame.draw.rect(SCREEN, WHITE, r, 2 if color != P2_COLOR else 5)
|
||||
# Ikonu izmēri un novietojums
|
||||
icon_w = 100
|
||||
gap = 10
|
||||
total_w = len(CHARACTERS) * icon_w + (len(CHARACTERS)-1) * gap
|
||||
start_x = (WIDTH - total_w) // 2
|
||||
|
||||
back_btn.draw(SCREEN)
|
||||
# P1 Zīmēšana
|
||||
p1_text = FONT_SMALL.render("PLAYER 1", True, CHARACTERS[P1_CHAR_INDEX]['color'])
|
||||
SCREEN.blit(p1_text, (WIDTH//2 - p1_text.get_width()//2, 110))
|
||||
|
||||
y_p1 = 150
|
||||
for i, char in enumerate(CHARACTERS):
|
||||
icon_rect = pygame.Rect(start_x + i * (icon_w + gap), y_p1, icon_w, icon_w)
|
||||
SCREEN.blit(char['icon'], icon_rect.topleft)
|
||||
border_color = WHITE if i != P1_CHAR_INDEX else YELLOW
|
||||
border_width = 2 if i != P1_CHAR_INDEX else 4
|
||||
pygame.draw.rect(SCREEN, border_color, icon_rect, border_width)
|
||||
|
||||
# P2 Zīmēšana
|
||||
p2_text = FONT_SMALL.render("PLAYER 2", True, CHARACTERS[P2_CHAR_INDEX]['color'])
|
||||
SCREEN.blit(p2_text, (WIDTH//2 - p2_text.get_width()//2, 300))
|
||||
|
||||
y_p2 = 340
|
||||
for i, char in enumerate(CHARACTERS):
|
||||
icon_rect = pygame.Rect(start_x + i * (icon_w + gap), y_p2, icon_w, icon_w)
|
||||
SCREEN.blit(char['icon'], icon_rect.topleft)
|
||||
border_color = WHITE if i != P2_CHAR_INDEX else YELLOW
|
||||
border_width = 2 if i != P2_CHAR_INDEX else 4
|
||||
pygame.draw.rect(SCREEN, border_color, icon_rect, border_width)
|
||||
|
||||
back_btn_chars.draw(SCREEN)
|
||||
|
||||
elif STATE == "BG_SELECT":
|
||||
SCREEN.fill(BLACK)
|
||||
title = FONT_MED.render("IZVELIES VIDI", True, WHITE)
|
||||
SCREEN.blit(title, (WIDTH//2 - title.get_width()//2, 50))
|
||||
|
||||
SCREEN.blit(title, (WIDTH//2 - title.get_width()//2, 100))
|
||||
for btn in bg_buttons:
|
||||
btn.draw(SCREEN)
|
||||
|
||||
elif STATE == "DIALOGUE":
|
||||
get_bg_function(SELECTED_BG)(SCREEN)
|
||||
draw_background(SCREEN, SELECTED_BG)
|
||||
dialogue_mgr.draw(SCREEN)
|
||||
|
||||
elif STATE == "GAME":
|
||||
keys = pygame.key.get_pressed()
|
||||
|
||||
# Spēles loģika
|
||||
fighter1.move(keys)
|
||||
fighter2.move(keys)
|
||||
fighter1.update()
|
||||
|
|
@ -459,29 +494,26 @@ def main():
|
|||
STATE = "GAMEOVER"
|
||||
winner = "PLAYER 1" if fighter2.health <= 0 else "PLAYER 2"
|
||||
|
||||
# Zīmēšana
|
||||
bg_func = get_bg_function(SELECTED_BG)
|
||||
bg_func(SCREEN)
|
||||
draw_background(SCREEN, SELECTED_BG)
|
||||
|
||||
fighter1.draw(SCREEN)
|
||||
fighter2.draw(SCREEN)
|
||||
|
||||
# Health bars
|
||||
# Health bars (saglabāts vecais stils)
|
||||
pygame.draw.rect(SCREEN, BLACK, (20, 20, 400, 40))
|
||||
pygame.draw.rect(SCREEN, RED, (20, 20, 400, 40))
|
||||
pygame.draw.rect(SCREEN, P1_COLOR, (20, 20, (fighter1.health/100)*400, 40))
|
||||
pygame.draw.rect(SCREEN, fighter1.color_accent, (20, 20, (fighter1.health/100)*400, 40))
|
||||
pygame.draw.rect(SCREEN, WHITE, (20, 20, 400, 40), 2)
|
||||
|
||||
pygame.draw.rect(SCREEN, BLACK, (WIDTH-420, 20, 400, 40))
|
||||
pygame.draw.rect(SCREEN, RED, (WIDTH-420, 20, 400, 40))
|
||||
pygame.draw.rect(SCREEN, P2_COLOR, (WIDTH-420, 20, (fighter2.health/100)*400, 40))
|
||||
pygame.draw.rect(SCREEN, fighter2.color_accent, (WIDTH-420, 20, (fighter2.health/100)*400, 40))
|
||||
pygame.draw.rect(SCREEN, WHITE, (WIDTH-420, 20, 400, 40), 2)
|
||||
|
||||
elif STATE == "GAMEOVER":
|
||||
SCREEN.fill(BLACK)
|
||||
txt = FONT_BIG.render(f"{winner} WINS!", True, YELLOW)
|
||||
restart = FONT_SMALL.render("Nospied [R] atgriezties uz izvelni", True, WHITE)
|
||||
|
||||
SCREEN.blit(txt, (WIDTH//2 - txt.get_width()//2, HEIGHT//2 - 50))
|
||||
SCREEN.blit(restart, (WIDTH//2 - restart.get_width()//2, HEIGHT//2 + 50))
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 217 KiB |
Loading…
Reference in New Issue