diff --git a/images/play_button.png b/images/play_button.png index ea9f4b2..92431af 100644 Binary files a/images/play_button.png and b/images/play_button.png differ diff --git a/main.py b/main.py index 3be9813..6d148c3 100644 --- a/main.py +++ b/main.py @@ -15,7 +15,7 @@ GROUND_Y = HEIGHT - 60 FPS = 60 -BACKGROUND = pygame.image.load("images/back.png") +BACKGROUND = pygame.image.load("images/back_main.jpg") BACKGROUND = pygame.transform.scale(BACKGROUND, (WIDTH, HEIGHT)) BACK_MAIN = pygame.image.load("images/back_main.jpg") BACK_MAIN = pygame.transform.scale(BACK_MAIN, (WIDTH, HEIGHT)) @@ -195,30 +195,36 @@ knight = Player( ) door_image = pygame.image.load("images/door.png") -door_image = pygame.transform.scale(door_image, (int(door_image.get_width() * 3), int(door_image.get_height() * 3))) +door_image = pygame.transform.scale(door_image,(int(door_image.get_width() * 3), int(door_image.get_height() * 3))) -door_rect = door_image.get_rect(center=(WIDTH//2, GROUND_Y - door_image.get_height()//2)) +DOOR_POSITIONS = { + 1: (100, GROUND_Y - 645), + 2: (1800, GROUND_Y-565), + 3: (1550,GROUND_Y-525), + 4: (50, GROUND_Y - 725), + 5: (900, GROUND_Y - 685), + 6: (200,GROUND_Y-625), + 7: (1700, GROUND_Y - 745), + 8: (1300, GROUND_Y - 875) + } +door_rect = door_image.get_rect(center=(WIDTH//2, GROUND_Y)) def place_door_for_level(lvl): - """Разместить дверь на одной из платформ уровня (предпочтительно над землёй, ближе к центру).""" global door_rect - plats = build_platform_rects(lvl) - if not plats: - door_rect = door_image.get_rect(center=(WIDTH//2, GROUND_Y - door_image.get_height()//2)) - return - candidates = [p for p in plats if p.top < GROUND_Y - 10] - if not candidates: - candidates = plats - - candidates.sort(key=lambda p: abs(p.centerx - WIDTH//2)) - chosen = candidates[0] - - door_rect = door_image.get_rect(midbottom=(chosen.centerx, chosen.top)) - + if lvl in DOOR_POSITIONS: + x, y = DOOR_POSITIONS[lvl] + door_rect = door_image.get_rect(midbottom=(x, y)) + else: + door_rect = door_image.get_rect(center=(WIDTH // 2, GROUND_Y - door_image.get_height() // 2)) door_rect.clamp_ip(pygame.Rect(0, 0, WIDTH, HEIGHT)) -button_play = pygame.image.load("images/play_button.png") -button_rect = button_play.get_rect(center=(500, 400)) +button_play = pygame.image.load("images/play_button.png").convert_alpha() +button_play.set_colorkey((0,0,0)) +button_play = pygame.transform.scale( + button_play, + (int(button_play.get_width() * 2.5), int(button_play.get_height() * 2.5)) +) +button_rect = button_play.get_rect(center=(WIDTH // 2, HEIGHT // 2)) buttonlvl1 = pygame.image.load("images/button_lvl/F1.png") buttonlvl2 = pygame.image.load("images/button_lvl/F2.png") @@ -322,143 +328,132 @@ PLATFORM_IMAGES = { LEVEL_BLOCKS = { 1: [ - ("dirt_big", (80, GROUND_Y)), - ("grass_smol",(220, GROUND_Y - 120)), - ("dirt_smol", (360, GROUND_Y - 200)), - ("sand_smol", (500, GROUND_Y - 260)), - ("ice_smol", (640, GROUND_Y - 320)), - ("grass_big", (780, GROUND_Y - 80)), - ("sand_big", (920, GROUND_Y)), - ("dirt_smol", (1060, GROUND_Y - 240)), - ("grass_smol",(1200, GROUND_Y - 140)), - ("ice_big", (1340, GROUND_Y)), - ("dirt_big", (1480, GROUND_Y - 60)), - ("sand_smol", (1620, GROUND_Y - 200)), - ("grass_smol",(1760, GROUND_Y - 280)), - ("ice_smol", (1000, GROUND_Y - 420)), - ("dirt_smol", (400, GROUND_Y - 360)), + ("dirt_big", (100, GROUND_Y-120)), + ("grass_smol",(400, GROUND_Y-180)), + ("grass_big", (700, GROUND_Y - 240)), + ("sand_smol", (1000, GROUND_Y - 300)), + ("ice_smol", (1300, GROUND_Y - 360)), + ("grass_big", (1600, GROUND_Y - 220)), + ("sand_big", (1800, GROUND_Y - 340)), + ("dirt_smol", (1600, GROUND_Y - 460)), + ("grass_smol",(1800, GROUND_Y - 580)), + ("ice_big", (1600, GROUND_Y- 700)), + ("dirt_big", (1200, GROUND_Y - 700)), + ("sand_smol", (900, GROUND_Y - 700)), + ("grass_smol",(600, GROUND_Y - 700)), + ("ice_smol", (250, GROUND_Y - 520)), + ("dirt_smol", (100, GROUND_Y - 620)), ], 2: [ - ("sand_big", (120, GROUND_Y)), - ("dirt_smol", (260, GROUND_Y - 160)), - ("grass_smol",(400, GROUND_Y - 120)), - ("ice_smol", (540, GROUND_Y - 300)), - ("dirt_big", (680, GROUND_Y - 40)), - ("sand_smol", (820, GROUND_Y - 220)), - ("grass_big", (960, GROUND_Y)), - ("ice_big", (1100, GROUND_Y - 20)), - ("dirt_smol", (1240, GROUND_Y - 260)), - ("sand_smol", (1380, GROUND_Y - 320)), - ("grass_smol",(1520, GROUND_Y - 180)), - ("dirt_big", (1660, GROUND_Y - 80)), - ("ice_smol", (1800, GROUND_Y - 360)), - ("grass_smol",(900, GROUND_Y - 420)), - ("dirt_smol", (520, GROUND_Y - 360)), + ("dirt_big",(100,GROUND_Y-100)), + ("grass_smol",(400,GROUND_Y-240)), + ("grass_smol",(600,GROUND_Y-380)), + ("sand_smol",(400,GROUND_Y-520)), + ("grass_big",(100,GROUND_Y-660)), + ("sand_smol",(400,GROUND_Y-720)), + ("sand_big",(600,GROUND_Y-720)), + ("sand_smol",(480,GROUND_Y-720)), + ("sand_big",(1000,GROUND_Y-420)), + ("dirt_smol",(1300,GROUND_Y-220)), + ("grass_smol",(1500,GROUND_Y-360)), + ("sand_smol",(1800,GROUND_Y-420)), + ("ice_smol",(1800,GROUND_Y-540)), ], 3: [ - ("grass_big", (100, GROUND_Y)), - ("sand_smol", (260, GROUND_Y - 200)), - ("dirt_smol", (420, GROUND_Y - 140)), - ("ice_smol", (580, GROUND_Y - 320)), - ("grass_smol",(740, GROUND_Y - 240)), - ("dirt_big", (900, GROUND_Y - 60)), - ("sand_big", (1060, GROUND_Y)), - ("ice_big", (1220, GROUND_Y - 40)), - ("grass_smol",(1380, GROUND_Y - 300)), - ("dirt_smol", (1540, GROUND_Y - 220)), - ("sand_smol", (1700, GROUND_Y - 160)), - ("grass_smol",(860, GROUND_Y - 420)), - ("ice_smol", (480, GROUND_Y - 420)), - ("dirt_big", (1320, GROUND_Y - 120)), - ("grass_smol",(200, GROUND_Y - 320)), - ], + ("ice_big",(400,GROUND_Y-120)), + ("ice_smol",(100,GROUND_Y-240)), + ("ice_smol",(400,GROUND_Y-360)), + ("ice_smol",(100,GROUND_Y-480)), + ("grass_big",(400,GROUND_Y-600)), + ("sand_big",(100,GROUND_Y-720)), + ("ice_big",(400,GROUND_Y-800)), + ("grass_smol",(700,GROUND_Y-800)), + ("ice_smol",(900,GROUND_Y-800)), + ("grass_smol",(1100,GROUND_Y-800)), + ("sand_big",(1400,GROUND_Y-800)), + ("dirt_smol",(1600,GROUND_Y-800)), + ("grass_smol",(1520,GROUND_Y-800)), + ("sand_smol",(1550,GROUND_Y-500)), + ], + 4: [ - ("ice_big", (140, GROUND_Y)), - ("ice_smol", (300, GROUND_Y - 140)), - ("grass_smol",(460, GROUND_Y - 220)), - ("sand_smol", (620, GROUND_Y - 180)), - ("dirt_smol", (780, GROUND_Y - 360)), - ("grass_big", (940, GROUND_Y - 80)), - ("sand_big", (1100, GROUND_Y)), - ("dirt_big", (1260, GROUND_Y - 40)), - ("ice_smol", (1420, GROUND_Y - 300)), - ("grass_smol",(1580, GROUND_Y - 240)), - ("dirt_smol", (1740, GROUND_Y - 320)), - ("ice_big", (820, GROUND_Y - 420)), - ("sand_smol", (980, GROUND_Y - 260)), - ("grass_smol",(540, GROUND_Y - 360)), - ("dirt_big", (200, GROUND_Y - 80)), + ("dirt_big", (400, GROUND_Y - 120)), + ("grass_smol", (700, GROUND_Y - 240)), + ("grass_smol", (1000, GROUND_Y - 360)), + ("sand_big", (1300, GROUND_Y - 480)), + ("sand_big", (1600, GROUND_Y - 600)), + ("ice_smol", (1300, GROUND_Y - 700)), + ("ice_smol", (1000, GROUND_Y - 780)), + ("dirt_big", (700, GROUND_Y - 840)), + ("dirt_big", (400, GROUND_Y - 840)), + ("grass_smol", (100, GROUND_Y - 900)), + ("grass_smol", (50, GROUND_Y - 700)), ], + 5: [ - ("dirt_big", (60, GROUND_Y)), - ("grass_big", (240, GROUND_Y - 80)), - ("sand_smol", (420, GROUND_Y - 220)), - ("ice_smol", (600, GROUND_Y - 320)), - ("grass_smol",(780, GROUND_Y - 260)), - ("dirt_smol", (960, GROUND_Y - 280)), - ("sand_big", (1140, GROUND_Y)), - ("ice_big", (1320, GROUND_Y - 40)), - ("grass_smol",(1500, GROUND_Y - 200)), - ("dirt_smol", (1680, GROUND_Y - 360)), - ("sand_smol", (900, GROUND_Y - 420)), - ("grass_big", (540, GROUND_Y - 140)), - ("dirt_big", (1260, GROUND_Y - 120)), - ("ice_smol", (300, GROUND_Y - 300)), - ("grass_smol",(1740, GROUND_Y - 240)), + ("grass_big", (150, GROUND_Y - 120)), + ("sand_smol", (450, GROUND_Y - 240)), + ("sand_smol", (750, GROUND_Y - 360)), + ("ice_big", (1050, GROUND_Y - 360)), + ("ice_big", (1350, GROUND_Y - 360)), + ("dirt_smol", (1650, GROUND_Y - 360)), + ("dirt_smol", (1650, GROUND_Y - 500)), + ("dirt_smol", (1650, GROUND_Y - 640)), + ("grass_big", (1400, GROUND_Y - 720)), + ("sand_smol", (1100, GROUND_Y - 720)), + ("sand_smol", (900, GROUND_Y - 660)), + ], - 6: [ - ("sand_big", (140, GROUND_Y)), - ("dirt_smol", (320, GROUND_Y - 160)), - ("dirt_smol", (500, GROUND_Y - 160)), - ("grass_smol",(680, GROUND_Y - 320)), - ("ice_smol", (860, GROUND_Y - 300)), - ("sand_smol", (1040, GROUND_Y - 300)), - ("grass_big", (1220, GROUND_Y - 80)), - ("dirt_big", (1400, GROUND_Y)), - ("ice_big", (1580, GROUND_Y - 40)), - ("grass_smol",(1760, GROUND_Y - 240)), - ("dirt_smol", (940, GROUND_Y - 420)), - ("sand_smol", (260, GROUND_Y - 260)), - ("grass_smol",(460, GROUND_Y - 220)), - ("dirt_big", (1100, GROUND_Y - 120)), - ("ice_smol", (660, GROUND_Y - 360)), + + + 6: [ + ("grass_big",(200,GROUND_Y-120)), + ("sand_big",(500,GROUND_Y-240)), + ("ice_big",(800,GROUND_Y-360)), + ("dirt_big",(1100,GROUND_Y-480)), + ("grass_big",(1400,GROUND_Y-600)), + ("sand_big",(1700,GROUND_Y-720)), + ("ice_smol",(1400,GROUND_Y-840)), + ("grass_smol",(1100,GROUND_Y-900)), + ("sand_smol",(800,GROUND_Y-840)), + ("ice_smol",(500,GROUND_Y-720)), + ("grass_big",(200,GROUND_Y-600)), ], + 7: [ - ("grass_big", (80, GROUND_Y)), - ("ice_smol", (260, GROUND_Y - 180)), - ("ice_smol", (440, GROUND_Y - 180)), - ("sand_smol", (620, GROUND_Y - 260)), - ("dirt_smol", (800, GROUND_Y - 350)), - ("grass_smol",(980, GROUND_Y - 420)), - ("sand_big", (1160, GROUND_Y)), - ("dirt_big", (1340, GROUND_Y - 60)), - ("ice_big", (1520, GROUND_Y - 20)), - ("grass_smol",(1700, GROUND_Y - 300)), - ("dirt_smol", (560, GROUND_Y - 320)), - ("sand_smol", (920, GROUND_Y - 220)), - ("grass_big", (1240, GROUND_Y - 100)), - ("ice_smol", (420, GROUND_Y - 420)), - ("dirt_smol", (140, GROUND_Y - 240)), + ("ice_big", (150, GROUND_Y - 120)), + ("ice_big", (150, GROUND_Y - 260)), + ("dirt_smol", (150, GROUND_Y - 400)), + ("dirt_smol", (150, GROUND_Y - 540)), + ("ice_smol", (150, GROUND_Y - 680)), + ("grass_big", (600, GROUND_Y - 200)), + ("sand_smol", (700, GROUND_Y - 340)), + ("sand_smol", (700, GROUND_Y - 480)), + ("ice_smol", (700, GROUND_Y - 620)), + ("ice_big", (950, GROUND_Y - 620)), + ("dirt_smol", (1150, GROUND_Y - 720)), + ("grass_smol", (1450, GROUND_Y - 720)), + ("sand_big", (1750, GROUND_Y - 720)), + ("sand_big", (1700, GROUND_Y - 600)), ], + + 8: [ - ("ice_big", (100, GROUND_Y)), - ("dirt_big", (300, GROUND_Y)), - ("grass_smol",(500, GROUND_Y - 200)), - ("sand_smol", (700, GROUND_Y - 320)), - ("ice_smol", (900, GROUND_Y - 400)), - ("dirt_smol", (1100, GROUND_Y - 360)), - ("grass_smol",(1300, GROUND_Y - 300)), - ("sand_big", (1500, GROUND_Y)), - ("dirt_big", (1700, GROUND_Y - 40)), - ("ice_big", (600, GROUND_Y - 420)), - ("grass_big", (800, GROUND_Y - 120)), - ("dirt_smol", (1000, GROUND_Y - 220)), - ("sand_smol", (1200, GROUND_Y - 260)), - ("ice_smol", (1400, GROUND_Y - 320)), - ("grass_smol",(1600, GROUND_Y - 180)), + ("dirt_big", (700, GROUND_Y - 120)), + ("sand_big", (1000, GROUND_Y - 240)), + ("sand_big", (1300, GROUND_Y - 240)), + ("ice_smol", (1600, GROUND_Y - 370)), + ("ice_big", (1300, GROUND_Y - 500)), + ("ice_big", (1000, GROUND_Y - 500)), + ("dirt_smol", (700, GROUND_Y - 620)), + ("grass_big", (400, GROUND_Y - 740)), + ("sand_smol", (700, GROUND_Y - 850)), + ("ice_big", (1000, GROUND_Y - 850)), + ("ice_big", (1300, GROUND_Y - 850)), ], } + current_level_bg = None def restart_level(): @@ -466,7 +461,6 @@ def restart_level(): knight.reset() def build_platform_rects(lvl): - """Построить список rect'ов платформ текущего уровня.""" rects = [] for name, pos in LEVEL_BLOCKS.get(lvl, []): img = PLATFORM_IMAGES.get(name) @@ -475,7 +469,6 @@ def build_platform_rects(lvl): return rects def resolve_platform_collision(player, platform_rects): - """Простая обработка коллизий игрока с платформами (приземление и удар головой).""" cur_rect = player.surface.get_rect(midbottom=(int(player.x), int(player.y))) prev_rect = player.surface.get_rect(midbottom=(int(player.x), int(player.prev_y)))