main
Artjoms Daškevičs 2026-02-25 10:39:07 +02:00
parent a605a9f955
commit b1ae908136
1 changed files with 4 additions and 34 deletions

38
main.py
View File

@ -36,7 +36,6 @@ score_knight = 0
paused = False
floor_score = 1
MAX_FLOOR_SCORE = 8
@ -88,7 +87,6 @@ class Player:
self.surface = self.stand
self.rect = self.surface.get_rect(midbottom=(self.x, self.y))
def reset(self):
self.x = self.start_x
self.y = self.start_y
@ -100,7 +98,6 @@ class Player:
self.rect = self.surface.get_rect(midbottom=(self.x, self.y))
def handle_input(self, keys):
# classic per-frame movement (no dt)
self.moving = False
if keys[self.controls["right"]]:
@ -123,7 +120,6 @@ class Player:
self.x = WIDTH
def apply_gravity(self):
# classic per-frame gravity (no dt)
self.y_velocity += GRAVITY
self.y += self.y_velocity
@ -154,13 +150,9 @@ class Player:
self.rect = self.surface.get_rect(midbottom=(int(self.x), int(self.y)))
def draw(self, screen):
screen.blit(self.surface, self.rect)
goblin = Player(
200, GROUND_Y,
{
@ -197,15 +189,12 @@ knight = Player(
}
)
door_image = pygame.image.load("images/door.png")
door_rect = door_image.get_rect(center=(800, 700))
button_play = pygame.image.load("images/play_button.png")
button_rect = button_play.get_rect(center=(500, 400))
# BUTTONS PLAY (original images)
buttonlvl1 = pygame.image.load("images/button_lvl/F1.png")
buttonlvl2 = pygame.image.load("images/button_lvl/F2.png")
buttonlvl3 = pygame.image.load("images/button_lvl/F3.png")
@ -215,8 +204,7 @@ buttonlvl6 = pygame.image.load("images/button_lvl/F6.png")
buttonlvl7 = pygame.image.load("images/button_lvl/F7.png")
buttonlvl8 = pygame.image.load("images/button_lvl/F8.png")
# make level buttons larger
BUTTON_BIG_SIZE = (220, 140) # можно подправить под нужный размер
BUTTON_BIG_SIZE = (220, 140)
buttonlvl1_big = pygame.transform.scale(buttonlvl1, BUTTON_BIG_SIZE)
buttonlvl2_big = pygame.transform.scale(buttonlvl2, BUTTON_BIG_SIZE)
buttonlvl3_big = pygame.transform.scale(buttonlvl3, BUTTON_BIG_SIZE)
@ -226,7 +214,6 @@ buttonlvl6_big = pygame.transform.scale(buttonlvl6, BUTTON_BIG_SIZE)
buttonlvl7_big = pygame.transform.scale(buttonlvl7, BUTTON_BIG_SIZE)
buttonlvl8_big = pygame.transform.scale(buttonlvl8, BUTTON_BIG_SIZE)
# rects (centers kept as before)
buttonlvl1_rect = buttonlvl1_big.get_rect(center=(300, 300))
buttonlvl2_rect = buttonlvl2_big.get_rect(center=(600, 300))
buttonlvl3_rect = buttonlvl3_big.get_rect(center=(900, 300))
@ -248,7 +235,6 @@ level_buttons = [
(buttonlvl8_big, buttonlvl8_rect),
]
# Levels (backgrounds) - scale to screen size so entering level shows its background
level1 = pygame.image.load("images/Levels/floor1.png")
level2 = pygame.image.load("images/Levels/floor2.png")
level3 = pygame.image.load("images/Levels/floor3.png")
@ -270,7 +256,6 @@ level_bgs = [
pygame.transform.scale(level8, (WIDTH, HEIGHT)),
]
# helper: map F-key constants to level numbers
KEY_TO_LEVEL = {
pygame.K_F1: 1,
pygame.K_F2: 2,
@ -288,8 +273,7 @@ def restart_level():
goblin.reset()
knight.reset()
level = 0 # 0 = initial splash (BACKGROUND + Play), -1 = level select (BACK_MAIN), 1..8 = playing levels
level = 0
level_start_time = None
while True:
@ -298,18 +282,14 @@ while True:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
# ESC only toggles pause while playing a level
if event.key == pygame.K_ESCAPE and level > 0:
paused = not paused
# R returns to initial splash
if event.key == pygame.K_r:
restart_level()
level = 0
# Level hotkeys: F1..F8 available on level-select screen (level == -1)
if level == -1 and event.key in KEY_TO_LEVEL:
target = KEY_TO_LEVEL[event.key]
if target <= floor_score: # only if unlocked
if target <= floor_score:
restart_level()
level = target
level_start_time = pygame.time.get_ticks()
@ -323,7 +303,6 @@ while True:
SCREEN.fill((0, 0, 0))
# Initial splash: BACKGROUND with only Play button
if level == 0:
SCREEN.blit(BACKGROUND, (0, 0))
SCREEN.blit(button_play, button_rect)
@ -332,31 +311,25 @@ while True:
SCREEN.blit(title_surf, (WIDTH//2 - title_surf.get_width()//2, 120))
if button_rect.collidepoint(mouse_pos) and pygame.mouse.get_pressed()[0]:
# go to level-select screen
level = -1
# Level-select screen: BACK_MAIN with level buttons (F1..F8)
elif level == -1:
SCREEN.blit(BACK_MAIN, (0, 0))
title_surf = FONT.render('Select Level (F1..F8) — unlocked in order', True, (255,255,255))
SCREEN.blit(title_surf, (WIDTH//2 - title_surf.get_width()//2, 80))
# draw level buttons (dim locked ones)
for i in range(1, 9):
btn_surf, btn_rect = level_buttons[i]
if i <= floor_score:
SCREEN.blit(btn_surf, btn_rect)
else:
# draw dimmed (locked) version
locked = btn_surf.copy()
locked.set_alpha(90)
SCREEN.blit(locked, btn_rect)
# draw small lock text
lock_txt = FONT.render('LOCKED', True, (200, 40, 40))
SCREEN.blit(lock_txt, (btn_rect.centerx - lock_txt.get_width()//2, btn_rect.centery - 10))
# mouse clicks on unlocked buttons start levels
if pygame.mouse.get_pressed()[0]:
for i in range(1, 9):
btn_surf, btn_rect = level_buttons[i]
@ -370,7 +343,6 @@ while True:
except Exception: pass
break
# Playing any level (1..8)
elif level > 0:
if current_level_bg:
SCREEN.blit(current_level_bg, (0, 0))
@ -380,7 +352,6 @@ while True:
SCREEN.blit(door_image, door_rect)
if not paused:
# reverted to per-frame calls (no dt)
goblin.handle_input(keys)
goblin.apply_gravity()
goblin.update_animation()
@ -392,7 +363,6 @@ while True:
goblin.draw(SCREEN)
knight.draw(SCREEN)
# ...existing HUD and level-complete logic...
pygame.display.update()
#CLOCK.tick(FPS)
CLOCK.tick(FPS)