Upload files to "/"
parent
742dc6e779
commit
bf5254d64d
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
311
game.py
311
game.py
|
|
@ -4,13 +4,17 @@ import sys
|
|||
import os
|
||||
import math
|
||||
|
||||
# --- Inicializācija ---
|
||||
pygame.init()
|
||||
pygame.mixer.init()
|
||||
|
||||
# Ekrāna iestatījumi
|
||||
WIDTH, HEIGHT = 1024, 576
|
||||
SCREEN = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||
pygame.display.set_caption("Pixel Kombat: Ultimate")
|
||||
|
||||
# --- CUSTOM CURSOR IESTATĪJUMI (SĀKUMS) ---
|
||||
# Paslēpjam noklusējuma sistēmas kursoru
|
||||
pygame.mouse.set_visible(False)
|
||||
# --- CUSTOM CURSOR IESTATĪJUMI (BEIGAS) ---
|
||||
CLOCK = pygame.time.Clock()
|
||||
|
||||
# --- KRĀSAS ---
|
||||
|
|
@ -27,6 +31,9 @@ PURPLE = (160, 32, 240)
|
|||
ORANGE = (255, 165, 0)
|
||||
LIGHT_BLUE = (100, 149, 237)
|
||||
|
||||
|
||||
|
||||
|
||||
# --- Fonti ---
|
||||
def get_font(name, size):
|
||||
if os.path.exists(name):
|
||||
|
|
@ -36,22 +43,54 @@ def get_font(name, size):
|
|||
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 ---
|
||||
|
||||
|
||||
|
||||
# --- Globālie mainīgie ---
|
||||
STATE = "MENU"
|
||||
SELECTED_BG = "BEACH"
|
||||
GAME_MODE = "PVP"
|
||||
|
||||
# ============================================================
|
||||
# --- HIGH SCORE FUNKCIJAS ---
|
||||
# ============================================================
|
||||
HIGHSCORE_FILE = "highscores.txt"
|
||||
|
||||
|
||||
# --- Mūzika ---
|
||||
MUSIC_FILE = "lofiewme-pixel-fantasia-355123.mp3"
|
||||
sound_on = True
|
||||
if os.path.exists(MUSIC_FILE):
|
||||
try:
|
||||
pygame.mixer.music.load(MUSIC_FILE)
|
||||
pygame.mixer.music.set_volume(0.5)
|
||||
pygame.mixer.music.play(-1)
|
||||
except Exception as e:
|
||||
print(f"Kļūda ielādējot mūziku: {e}")
|
||||
else:
|
||||
print(f"Mūzikas fails '{MUSIC_FILE}' nav atrasts.")
|
||||
|
||||
|
||||
|
||||
|
||||
# --- Sitiena skaņa ---
|
||||
HIT_SOUND_FILE = "freesound_community-pixel-sound-effect-3-82880.mp3"
|
||||
hit_sound = None
|
||||
if os.path.exists(HIT_SOUND_FILE):
|
||||
try:
|
||||
hit_sound = pygame.mixer.Sound(HIT_SOUND_FILE)
|
||||
hit_sound.set_volume(0.7)
|
||||
except Exception as e:
|
||||
print(f"Kļūda ielādējot sitiena skaņu: {e}")
|
||||
else:
|
||||
print(f"Skaņas fails '{HIT_SOUND_FILE}' nav atrasts.")
|
||||
|
||||
|
||||
|
||||
|
||||
# --- High score ---
|
||||
HIGHSCORE_FILE = "highscores.txt"
|
||||
def save_highscore(winner_name):
|
||||
try:
|
||||
with open(HIGHSCORE_FILE, "a") as f:
|
||||
|
|
@ -70,17 +109,17 @@ def load_highscores():
|
|||
pass
|
||||
return scores
|
||||
|
||||
# ============================================================
|
||||
# --- TĒLU UN FONA DATU BĀZES ---
|
||||
# ============================================================
|
||||
|
||||
|
||||
|
||||
# --- Tēlu un fona datu bāzes ---
|
||||
FALLBACK_COLORS = [
|
||||
(235, 64, 52), (52, 119, 235), (52, 235, 86), (255, 215, 0), (160, 32, 240), (255, 105, 180)
|
||||
]
|
||||
|
||||
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"
|
||||
"characters/first1_char.png", "characters/second2_char.png", "characters/third3_char.png",
|
||||
"characters/forth4_char.png", "characters/fifth5_char.png", "characters/sixth6_char.png"
|
||||
]
|
||||
|
||||
BOSS_FILES = ["boss/boss1.png", "boss/boss2.png", "boss/boss3.png"]
|
||||
|
|
@ -95,43 +134,20 @@ BG_FILES = {
|
|||
"STREETMARKETS": "backgrounds/street_markets.jpg"
|
||||
}
|
||||
|
||||
|
||||
|
||||
# --- Safe character(nav svarīgi) ---
|
||||
def create_placeholder_image(color, size=(80, 160), text="", is_boss=False):
|
||||
surf = pygame.Surface(size)
|
||||
surf.fill(color)
|
||||
pygame.draw.rect(surf, BLACK, (0, 0, size[0], size[1]), 2)
|
||||
|
||||
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)
|
||||
|
||||
eye_y = head_rect.y + head_h // 3
|
||||
eye_size = 6 if is_boss else 4
|
||||
pygame.draw.circle(surf, BLACK, (int(head_rect.centerx - head_w//5), int(eye_y)), eye_size)
|
||||
pygame.draw.circle(surf, BLACK, (int(head_rect.centerx + head_w//5), int(eye_y)), eye_size)
|
||||
|
||||
if is_boss:
|
||||
horn_scale = size[0] // 10
|
||||
pygame.draw.polygon(surf, RED, [
|
||||
(head_rect.left, head_rect.top),
|
||||
(head_rect.left - horn_scale, head_rect.top - horn_scale*2),
|
||||
(head_rect.left + horn_scale, head_rect.top)
|
||||
])
|
||||
pygame.draw.polygon(surf, RED, [
|
||||
(head_rect.right, head_rect.top),
|
||||
(head_rect.right + horn_scale, head_rect.top - horn_scale*2),
|
||||
(head_rect.right - horn_scale, head_rect.top)
|
||||
])
|
||||
|
||||
if text:
|
||||
font_size = 24 if is_boss else 18
|
||||
font = pygame.font.SysFont('arial', font_size)
|
||||
font = pygame.font.SysFont('arial', 20)
|
||||
txt = font.render(text, True, WHITE)
|
||||
surf.blit(txt, (size[0]//2 - txt.get_width()//2, size[1] - 40))
|
||||
surf.blit(txt, (size[0]//2 - txt.get_width()//2, size[1]//2 - txt.get_height()//2))
|
||||
return surf
|
||||
|
||||
|
||||
# --- Tēlu ielade ---
|
||||
def load_character_images():
|
||||
chars_data = []
|
||||
SPRITE_SIZE = (80, 150)
|
||||
|
|
@ -145,6 +161,7 @@ def load_character_images():
|
|||
icon_img = pygame.transform.scale(img, ICON_SIZE)
|
||||
else:
|
||||
raise FileNotFoundError
|
||||
# --- Ja ne atrod attēlu ---
|
||||
except:
|
||||
game_img = create_placeholder_image(color, SPRITE_SIZE, f"T{i+1}")
|
||||
icon_surf = pygame.Surface(ICON_SIZE)
|
||||
|
|
@ -157,6 +174,9 @@ def load_character_images():
|
|||
chars_data.append({'game_img': game_img, 'icon': icon_img, 'color': color})
|
||||
return chars_data
|
||||
|
||||
|
||||
|
||||
# --- Bossu ielade ---
|
||||
def load_boss_images():
|
||||
bosses = []
|
||||
BOSS_SIZE = (160, 300)
|
||||
|
|
@ -175,6 +195,9 @@ def load_boss_images():
|
|||
bosses.append(img)
|
||||
return bosses
|
||||
|
||||
|
||||
|
||||
# --- Ja fons un logu bildes nav atrastas ---
|
||||
def load_image_safe(filename, fallback_color, size=None):
|
||||
try:
|
||||
if os.path.exists(filename):
|
||||
|
|
@ -191,15 +214,21 @@ def load_image_safe(filename, fallback_color, size=None):
|
|||
surf.fill(fallback_color)
|
||||
return surf
|
||||
|
||||
# --- RESURSU IELĀDE ---
|
||||
|
||||
|
||||
# --- Attēlu ielade ---
|
||||
CHARACTERS = load_character_images()
|
||||
BOSS_IMAGES = load_boss_images()
|
||||
|
||||
# Menu bildes
|
||||
|
||||
|
||||
# --- Menu bildes ---
|
||||
MENU_PIC_WIDTH = 250
|
||||
menupic1 = load_image_safe("menupic1.png", FALLBACK_COLORS[1], (MENU_PIC_WIDTH, HEIGHT))
|
||||
menupic2 = load_image_safe("menupic2.png", FALLBACK_COLORS[0], (MENU_PIC_WIDTH, HEIGHT))
|
||||
|
||||
# --- Fonu attēli ---
|
||||
|
||||
bg_images = {}
|
||||
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),
|
||||
|
|
@ -207,7 +236,7 @@ cols = {"BEACH": (194, 178, 128), "EVENINGSTREET": (30, 30, 50), "MARKET": (100,
|
|||
for key, path in BG_FILES.items():
|
||||
bg_images[key] = load_image_safe(path, cols.get(key, GRAY))
|
||||
|
||||
# --- BOOM. PNG IELĀDE ---
|
||||
# --- Boom attēla ielade ---
|
||||
try:
|
||||
if os.path.exists("boom.png"):
|
||||
BOOM_IMG_ORIGINAL = pygame.image.load("boom.png").convert_alpha()
|
||||
|
|
@ -220,7 +249,32 @@ except:
|
|||
BOOM_IMG = pygame.Surface((80, 80)); BOOM_IMG.fill(YELLOW)
|
||||
BOOM_IMG_LARGE = pygame.Surface((160, 160)); BOOM_IMG_LARGE.fill(ORANGE)
|
||||
|
||||
# --- UI Klases ---
|
||||
|
||||
|
||||
# --- Custom cursor ielade ---
|
||||
CURSOR_IMG = None
|
||||
CURSOR_FILE = "custom_cursor.png"
|
||||
if os.path.exists(CURSOR_FILE):
|
||||
try:
|
||||
CURSOR_IMG = pygame.image.load(CURSOR_FILE).convert_alpha()
|
||||
CURSOR_IMG = pygame.transform.scale(CURSOR_IMG, (32, 32))
|
||||
print("Kursors veiksmīgi ielādēts.")
|
||||
except Exception as e:
|
||||
print(f"Kļūda ielādējot kursoru: {e}")
|
||||
else:
|
||||
print(f"Kursora fails '{CURSOR_FILE}' nav atrasts.")
|
||||
CURSOR_IMG = pygame.Surface((20, 20), pygame.SRCALPHA)
|
||||
pygame.draw.circle(CURSOR_IMG, WHITE, (10, 10), 10)
|
||||
pygame.draw.circle(CURSOR_IMG, BLACK, (10, 10), 10, 2)
|
||||
|
||||
|
||||
|
||||
|
||||
# ---- UI Klases ----
|
||||
|
||||
|
||||
|
||||
# --- Visas pogas(to visparīgums un pārbaude)
|
||||
class Button:
|
||||
def __init__(self, x, y, w, h, text, color, hover_color, action_code):
|
||||
self.rect = pygame.Rect(x, y, w, h)
|
||||
|
|
@ -242,41 +296,46 @@ class Button:
|
|||
return True
|
||||
return False
|
||||
|
||||
# --- Palīgfunkcija Instrukciju pogām ---
|
||||
|
||||
|
||||
|
||||
# ---Consolēs zīmejums ---
|
||||
def draw_key_visual(surface, x, y, w, h, key_text, action_text, color):
|
||||
# Zīmē pogas rāmi
|
||||
|
||||
pygame.draw.rect(surface, color, (x, y, w, h), 2)
|
||||
pygame.draw.rect(surface, DARK_GRAY, (x+4, y+4, w-8, h-8))
|
||||
|
||||
# Teksts uz pogas
|
||||
txt_surf = FONT_SMALL.render(key_text, True, WHITE)
|
||||
surface.blit(txt_surf, (x + w//2 - txt_surf.get_width()//2, y + 10))
|
||||
|
||||
# Paskaidrojums zem pogas
|
||||
desc_surf = FONT_TINY.render(action_text, True, GRAY)
|
||||
surface.blit(desc_surf, (x + w//2 - desc_surf.get_width()//2, y + h + 5))
|
||||
|
||||
# --- Klase Spēlētājam ---
|
||||
|
||||
|
||||
# ---Cīnītājs ---
|
||||
|
||||
class Fighter(pygame.sprite.Sprite):
|
||||
def __init__(self, x, y, char_data, facing_right, controls):
|
||||
super().__init__()
|
||||
# - Ka izskatas -
|
||||
self.char_data = char_data
|
||||
self.image = char_data['game_img']
|
||||
self.color_accent = char_data['color']
|
||||
self.start_x = x
|
||||
self.start_y = y
|
||||
self.facing_right_start = facing_right
|
||||
|
||||
# - Fizika -
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect.center = (x, y)
|
||||
self.rect.bottom = HEIGHT - 50
|
||||
|
||||
# - Fizikas un Kustības -
|
||||
self.vel_y = 0
|
||||
self.speed = 7
|
||||
self.jump_power = -20
|
||||
self.gravity = 0.8
|
||||
self.on_ground = False
|
||||
|
||||
# - Stāvokļa un cīnas -
|
||||
self.facing_right = facing_right
|
||||
self.controls = controls
|
||||
self.attacking = False
|
||||
|
|
@ -284,7 +343,7 @@ class Fighter(pygame.sprite.Sprite):
|
|||
self.attack_box = pygame.Rect(0, 0, 0, 0)
|
||||
self.health = 100
|
||||
self.hit_timer = 0
|
||||
|
||||
# - Sagatavot nākamajai kārtai -
|
||||
def reset_round(self):
|
||||
self.health = 100
|
||||
self.vel_y = 0
|
||||
|
|
@ -294,8 +353,9 @@ class Fighter(pygame.sprite.Sprite):
|
|||
self.attacking = False
|
||||
self.attack_cooldown = 0
|
||||
self.hit_timer = 0
|
||||
|
||||
# - tēla pārvietošana -
|
||||
def move(self, keys):
|
||||
# - Horizontāla kustība -
|
||||
dx = 0
|
||||
if keys[self.controls['left']]:
|
||||
dx = -self.speed
|
||||
|
|
@ -303,15 +363,16 @@ class Fighter(pygame.sprite.Sprite):
|
|||
if keys[self.controls['right']]:
|
||||
dx = self.speed
|
||||
self.facing_right = True
|
||||
|
||||
# - robežas -
|
||||
self.rect.x += dx
|
||||
if self.rect.left < 0: self.rect.left = 0
|
||||
if self.rect.right > WIDTH: self.rect.right = WIDTH
|
||||
|
||||
# - Lekšana -
|
||||
if keys[self.controls['jump']] and self.on_ground:
|
||||
self.vel_y = self.jump_power
|
||||
self.on_ground = False
|
||||
|
||||
# - Gravitācija -
|
||||
self.vel_y += self.gravity
|
||||
self.rect.y += self.vel_y
|
||||
|
||||
|
|
@ -319,7 +380,7 @@ class Fighter(pygame.sprite.Sprite):
|
|||
self.rect.bottom = HEIGHT - 50
|
||||
self.vel_y = 0
|
||||
self.on_ground = True
|
||||
|
||||
# - Uzbrukuma uzsākšana -
|
||||
def attack(self):
|
||||
if self.attack_cooldown == 0:
|
||||
self.attacking = True
|
||||
|
|
@ -328,12 +389,12 @@ class Fighter(pygame.sprite.Sprite):
|
|||
self.attack_box = pygame.Rect(self.rect.right, self.rect.y + 40, 80, 80)
|
||||
else:
|
||||
self.attack_box = pygame.Rect(self.rect.left - 80, self.rect.y + 40, 80, 80)
|
||||
|
||||
# - Taimeris -
|
||||
def update(self):
|
||||
if self.attack_cooldown > 0: self.attack_cooldown -= 1
|
||||
else: self.attacking = False
|
||||
if self.hit_timer > 0: self.hit_timer -= 1
|
||||
|
||||
# - Tēla darbība uz ekranā -
|
||||
def draw(self, surface):
|
||||
img_to_draw = pygame.transform.flip(self.image, not self.facing_right, False)
|
||||
surface.blit(img_to_draw, self.rect)
|
||||
|
|
@ -347,7 +408,9 @@ class Fighter(pygame.sprite.Sprite):
|
|||
if self.rect.centerx < WIDTH // 2: self.rect.x -= 20
|
||||
else: self.rect.x += 20
|
||||
|
||||
# --- Klase Bossam ---
|
||||
|
||||
|
||||
# --- Boss ---
|
||||
class Boss(pygame.sprite.Sprite):
|
||||
def __init__(self, image):
|
||||
super().__init__()
|
||||
|
|
@ -376,7 +439,7 @@ class Boss(pygame.sprite.Sprite):
|
|||
def ai_move(self, targets):
|
||||
closest_dist = 99999
|
||||
target = None
|
||||
|
||||
# - Attālums līdz target -
|
||||
for t in targets:
|
||||
if t.health > 0:
|
||||
dist = abs(self.rect.centerx - t.rect.centerx)
|
||||
|
|
@ -429,15 +492,15 @@ class Boss(pygame.sprite.Sprite):
|
|||
if self.rect.centerx < WIDTH // 2: self.rect.x -= 5
|
||||
else: self.rect.x += 5
|
||||
|
||||
# --- 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 = ["SAGATAVOJIES CĪŅAI!", "Kurš šodien uzvarēs?", "Cīnies ar godu!", "Parādi savas kustības!"]
|
||||
self.current_text = random.choice(self.lines)
|
||||
self.active = False
|
||||
self.timer = 0
|
||||
|
|
@ -468,32 +531,32 @@ class DialogueManager:
|
|||
|
||||
# --- Galvenā Spēle ---
|
||||
def main():
|
||||
global STATE, P1_CHAR_INDEX, P2_CHAR_INDEX, SELECTED_BG, GAME_MODE
|
||||
global STATE, P1_CHAR_INDEX, P2_CHAR_INDEX, SELECTED_BG, GAME_MODE, sound_on
|
||||
|
||||
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()
|
||||
|
||||
# Pogas (novietotas centrā, ņemot vērā malu bildes)
|
||||
# Pogas (novietotas centrā)
|
||||
btn_x = WIDTH//2 - 100
|
||||
menu_buttons = [
|
||||
Button(btn_x, 180, 200, 50, "PvP", BLUE, RED, "START_PVP"),
|
||||
Button(btn_x, 240, 200, 50, "Cina ar Bossu", PURPLE, ORANGE, "START_BOSS"),
|
||||
Button(btn_x, 300, 200, 50, "Telu Izvele", BLUE, RED, "CHARS"),
|
||||
Button(btn_x, 360, 200, 50, "Fona Izvele", BLUE, RED, "BG"),
|
||||
Button(btn_x, 420, 200, 50, "Kontroles", GREEN, YELLOW, "INSTRUCTIONS"),
|
||||
Button(btn_x, 180, 200, 50, "PvP", YELLOW, RED, "START_PVP"),
|
||||
Button(btn_x, 240, 200, 50, "Cīna ar Bossu", YELLOW, RED, "START_BOSS"),
|
||||
Button(btn_x, 300, 200, 50, "Tēlu Izvēle", YELLOW, RED, "CHARS"),
|
||||
Button(btn_x, 360, 200, 50, "Fona Izvēle", YELLOW, RED, "BG"),
|
||||
Button(btn_x, 420, 200, 50, "Kontroles", YELLOW, RED, "INSTRUCTIONS"),
|
||||
]
|
||||
|
||||
bg_buttons = [
|
||||
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")
|
||||
Button(150, 200, 200, 50, "Pludmale", WHITE, YELLOW, "BEACH"),
|
||||
Button(412, 200, 200, 50, "Nakts iela", WHITE, YELLOW, "EVENINGSTREET"),
|
||||
Button(674, 200, 200, 50, "Tirgus", WHITE, YELLOW, "MARKET"),
|
||||
Button(150, 280, 200, 50, "Restorāns", WHITE, YELLOW, "RESTAURANT"),
|
||||
Button(412, 280, 200, 50, "Sakuras iela", WHITE, YELLOW, "SAKURASTREET"),
|
||||
Button(674, 280, 200, 50, "Ports", WHITE, YELLOW, "SHIP"),
|
||||
Button(WIDTH//2 - 100, 360, 200, 50, "Ielu tirgus", WHITE, YELLOW, "STREETMARKETS"),
|
||||
Button(WIDTH//2 - 100, 450, 200, 50, "Atpakaļ", GRAY, WHITE, "BACK")
|
||||
]
|
||||
|
||||
back_btn_chars = Button(WIDTH//2 - 100, HEIGHT - 80, 200, 50, "Atpakal", GRAY, WHITE, "BACK")
|
||||
|
|
@ -511,6 +574,9 @@ def main():
|
|||
|
||||
state_timer = 0
|
||||
|
||||
# --- SKAŅAS POGA ---
|
||||
mute_btn_rect = pygame.Rect(20, HEIGHT - 35, 140, 25)
|
||||
|
||||
run = True
|
||||
while run:
|
||||
CLOCK.tick(60)
|
||||
|
|
@ -519,6 +585,15 @@ def main():
|
|||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
# --- Skaņas pogas loģika ---
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
if mute_btn_rect.collidepoint(event.pos):
|
||||
sound_on = not sound_on
|
||||
if sound_on:
|
||||
pygame.mixer.music.set_volume(0.5)
|
||||
else:
|
||||
pygame.mixer.music.set_volume(0)
|
||||
|
||||
if STATE == "MENU":
|
||||
for btn in menu_buttons:
|
||||
if btn.is_clicked(event):
|
||||
|
|
@ -600,11 +675,9 @@ def main():
|
|||
if STATE == "MENU":
|
||||
SCREEN.fill(BLACK)
|
||||
|
||||
# Zīmējam malu bildes (no augšas līdz lejai)
|
||||
SCREEN.blit(menupic1, (0, 0)) # Kreisā puse
|
||||
SCREEN.blit(menupic2, (WIDTH - MENU_PIC_WIDTH, 0)) # Labā puse
|
||||
SCREEN.blit(menupic1, (0, 0))
|
||||
SCREEN.blit(menupic2, (WIDTH - MENU_PIC_WIDTH, 0))
|
||||
|
||||
# Virsraksts centrā
|
||||
title_text = "PIXEL KOMBAT"
|
||||
shadow_text = FONT_BIG.render(title_text, True, (180, 0, 0))
|
||||
SCREEN.blit(shadow_text, (WIDTH//2 - shadow_text.get_width()//2 + 3, 53))
|
||||
|
|
@ -620,48 +693,32 @@ def main():
|
|||
elif STATE == "INSTRUCTIONS":
|
||||
SCREEN.fill(BLACK)
|
||||
|
||||
# Virsraksts "KONTROLES" pašā augšā
|
||||
title = FONT_BIG.render("KONTROLES", True, YELLOW)
|
||||
SCREEN.blit(title, (WIDTH//2 - title.get_width()//2, 30))
|
||||
|
||||
# --- Izkārtojuma mainīgie ---
|
||||
# Centri katrai kolonnai (simetriski attiecībā pret ekrāna centru)
|
||||
p1_center_x = WIDTH // 2 - 200
|
||||
p2_center_x = WIDTH // 2 + 200
|
||||
|
||||
# Y pozīcijas (palielinātas atstarpes)
|
||||
title_y = 170 # Kur sākas "PLAYER X" teksts
|
||||
key_row1_y = 240 # Augšējā poga (W / UP)
|
||||
key_row2_y = 320 # Vidējās pogas (A,D / LEFT, RIGHT)
|
||||
key_row3_y = 420 # Apakšējā poga (SPACE / ENTER)
|
||||
title_y = 170
|
||||
key_row1_y = 240
|
||||
key_row2_y = 320
|
||||
key_row3_y = 420
|
||||
|
||||
# --- PLAYER 1 (Kreisā puse) ---
|
||||
p1_title = FONT_MED.render("PLAYER 1", True, BLUE)
|
||||
# Centrējam tekstu virs pogu kolonnas
|
||||
SCREEN.blit(p1_title, (p1_center_x - p1_title.get_width()//2, title_y))
|
||||
|
||||
# W (Jump) - centrēta
|
||||
draw_key_visual(SCREEN, p1_center_x - 35, key_row1_y, 70, 50, "W", "LEKT", BLUE)
|
||||
# A (Left) - pa kreisi no centra
|
||||
draw_key_visual(SCREEN, p1_center_x - 35 - 80, key_row2_y, 70, 50, "A", "KREISI", BLUE)
|
||||
# D (Right) - pa labi no centra
|
||||
draw_key_visual(SCREEN, p1_center_x - 35 + 80, key_row2_y, 70, 50, "D", "LABI", BLUE)
|
||||
# SPACE (Hit) - plata poga apakšā, centrēta
|
||||
space_w = 200
|
||||
draw_key_visual(SCREEN, p1_center_x - space_w//2, key_row3_y, space_w, 50, "SPACE", "SIT", RED)
|
||||
|
||||
# --- PLAYER 2 (Labā puse) ---
|
||||
p2_title = FONT_MED.render("PLAYER 2", True, RED)
|
||||
# Centrējam tekstu virs pogu kolonnas
|
||||
SCREEN.blit(p2_title, (p2_center_x - p2_title.get_width()//2, title_y))
|
||||
|
||||
# UP (Jump)
|
||||
draw_key_visual(SCREEN, p2_center_x - 35, key_row1_y, 70, 50, "UP", "LEKT", RED)
|
||||
# LEFT (Left)
|
||||
draw_key_visual(SCREEN, p2_center_x - 35 - 80, key_row2_y, 70, 50, "LEFT", "KREISI", RED)
|
||||
# RIGHT (Right)
|
||||
draw_key_visual(SCREEN, p2_center_x - 35 + 80, key_row2_y, 70, 50, "RIGHT", "LABI", RED)
|
||||
# ENTER (Hit)
|
||||
enter_w = 150
|
||||
draw_key_visual(SCREEN, p2_center_x - enter_w//2, key_row3_y, enter_w, 50, "ENTER", "SIT", BLUE)
|
||||
|
||||
|
|
@ -756,10 +813,21 @@ def main():
|
|||
fighter2.update()
|
||||
|
||||
if GAME_MODE == "PVP":
|
||||
# P1 sit P2
|
||||
if fighter1.attacking and fighter1.attack_box.colliderect(fighter2.rect):
|
||||
if fighter2.hit_timer == 0: fighter2.take_damage(5)
|
||||
if fighter2.hit_timer == 0:
|
||||
fighter2.take_damage(5)
|
||||
# SKAŅA: P1 sitiena skaņa
|
||||
if sound_on and hit_sound:
|
||||
hit_sound.play()
|
||||
|
||||
# P2 sit P1
|
||||
if fighter2.attacking and fighter2.attack_box.colliderect(fighter1.rect):
|
||||
if fighter1.hit_timer == 0: fighter1.take_damage(5)
|
||||
if fighter1.hit_timer == 0:
|
||||
fighter1.take_damage(5)
|
||||
# SKAŅA: P2 sitiena skaņa
|
||||
if sound_on and hit_sound:
|
||||
hit_sound.play()
|
||||
|
||||
if fighter1.health <= 0 or fighter2.health <= 0:
|
||||
if fighter2.health <= 0:
|
||||
|
|
@ -776,11 +844,18 @@ def main():
|
|||
boss.ai_move(targets)
|
||||
boss.update()
|
||||
|
||||
# Spēlētāji sit Bosu
|
||||
if fighter1.attacking and fighter1.attack_box.colliderect(boss.rect):
|
||||
if boss.hit_timer == 0: boss.take_damage(5)
|
||||
if fighter2.attacking and fighter2.attack_box.colliderect(boss.rect):
|
||||
if boss.hit_timer == 0: boss.take_damage(5)
|
||||
if boss.hit_timer == 0:
|
||||
boss.take_damage(5)
|
||||
if sound_on and hit_sound: hit_sound.play()
|
||||
|
||||
if fighter2.attacking and fighter2.attack_box.colliderect(boss.rect):
|
||||
if boss.hit_timer == 0:
|
||||
boss.take_damage(5)
|
||||
if sound_on and hit_sound: hit_sound.play()
|
||||
|
||||
# Boss sit spēlētājus (Boss sitienam skaņu nevajag pēc pieprasījuma, bet var pievienot)
|
||||
if boss.attacking:
|
||||
if boss.attack_box.colliderect(fighter1.rect):
|
||||
if fighter1.hit_timer == 0: fighter1.take_damage(boss.damage)
|
||||
|
|
@ -898,6 +973,22 @@ def main():
|
|||
restart = FONT_SMALL.render("Nospied [R] atgriezties uz izvelni", True, GRAY)
|
||||
SCREEN.blit(restart, (WIDTH//2 - restart.get_width()//2, HEIGHT - 80))
|
||||
|
||||
# --- Zīmēt skaņas pogu ---
|
||||
btn_color = GREEN if sound_on else RED
|
||||
pygame.draw.rect(SCREEN, DARK_GRAY, mute_btn_rect)
|
||||
pygame.draw.rect(SCREEN, btn_color, mute_btn_rect, 2)
|
||||
|
||||
btn_label = "Skaņa: ON" if sound_on else "Skaņa: OFF"
|
||||
text_surf = FONT_TINY.render(btn_label, True, btn_color)
|
||||
text_x = mute_btn_rect.centerx - text_surf.get_width() // 2
|
||||
text_y = mute_btn_rect.centery - text_surf.get_height() // 2
|
||||
SCREEN.blit(text_surf, (text_x, text_y))
|
||||
|
||||
# --- Zīmēt kursoru ---
|
||||
if CURSOR_IMG:
|
||||
mouse_pos = pygame.mouse.get_pos()
|
||||
SCREEN.blit(CURSOR_IMG, mouse_pos)
|
||||
|
||||
pygame.display.update()
|
||||
|
||||
pygame.quit()
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 107 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
Loading…
Reference in New Issue