import pygame import sys pygame.init() # === Screen Setup === SCREEN_WIDTH = 800 SCREEN_HEIGHT = 540 TILE_SIZE = 40 BOTTOM_MARGIN = 100 screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT + BOTTOM_MARGIN)) pygame.display.set_caption('----------------------------------------- ⌐╖╖═─ Lifeblood ⌐╖╖═─ ---------------------------------------') # === Colors === WHITE = (255, 255, 255) BLACK = (0, 0, 0) BG_COLOR = WHITE BOTTOM_COLOR = BLACK GRID_COLOR = (200, 200, 200) # === Clock === clock = pygame.time.Clock() # === Level Data (0 = empty, 1 = block) === level_data = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], ] # === Font === font = pygame.font.SysFont('Arial', 48) # === Base Drawing Functions === def draw_base(): screen.fill(BG_COLOR) pygame.draw.rect(screen, BOTTOM_COLOR, (0, SCREEN_HEIGHT, SCREEN_WIDTH, BOTTOM_MARGIN)) def draw_grid(): for x in range(0, SCREEN_WIDTH, TILE_SIZE): pygame.draw.line(screen, GRID_COLOR, (x, 0), (x, SCREEN_HEIGHT), 1) for y in range(0, SCREEN_HEIGHT, TILE_SIZE): pygame.draw.line(screen, GRID_COLOR, (0, y), (SCREEN_WIDTH, y), 1) def draw_level(data): for row_idx, row in enumerate(data): for col_idx, tile in enumerate(row): if tile == 1: x = col_idx * TILE_SIZE y = SCREEN_HEIGHT - (len(data) - row_idx) * TILE_SIZE pygame.draw.rect(screen, BLACK, (x, y, TILE_SIZE, TILE_SIZE)) def get_tile_rects(level_data): rects = [] for row_idx, row in enumerate(level_data): for col_idx, tile in enumerate(row): if tile == 1: x = col_idx * TILE_SIZE y = SCREEN_HEIGHT - (len(level_data) - row_idx) * TILE_SIZE rects.append(pygame.Rect(x, y, TILE_SIZE, TILE_SIZE)) return rects # === Button Class === class Button: def __init__(self, text, x, y, w, h): self.text = text self.rect = pygame.Rect(x, y, w, h) self.color = (0, 0, 0) self.hover_color = (50, 50, 50) self.alpha = 0 self.surf = pygame.Surface((w, h), pygame.SRCALPHA) def draw(self, surface): mouse_pos = pygame.mouse.get_pos() is_hovered = self.rect.collidepoint(mouse_pos) color = self.hover_color if is_hovered else self.color self.surf.fill((255, 255, 255, 0)) pygame.draw.rect(self.surf, (*color, self.alpha), self.surf.get_rect(), border_radius=10) text_surf = font.render(self.text, True, (255, 255, 255)) text_surf.set_alpha(self.alpha) text_rect = text_surf.get_rect(center=self.rect.center) surface.blit(self.surf, self.rect.topleft) surface.blit(text_surf, text_rect) def fade_in(self, step=5): if self.alpha < 255: self.alpha += step if self.alpha > 255: self.alpha = 255 def is_clicked(self, event): return event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and self.rect.collidepoint(event.pos) # === Intro Animation === def intro_animation(): global sprite_x, sprite_y, sprite_width, sprite_height, sprite_speed running = True finished = False fade_out_counter = 0 while not finished: draw_base() draw_grid() if running: fade = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT + BOTTOM_MARGIN), pygame.SRCALPHA) fade.fill((255, 255, 255, 10)) trail_surf.blit(fade, (0, 0)) blur_square = pygame.Surface((sprite_width, sprite_height), pygame.SRCALPHA) blur_square.fill((0, 0, 0, 80)) trail_surf.blit(blur_square, (sprite_x, sprite_y)) sprite_x += sprite_speed if sprite_x > SCREEN_WIDTH: running = False else: fade = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT + BOTTOM_MARGIN), pygame.SRCALPHA) fade.fill((255, 255, 255, 15)) trail_surf.blit(fade, (0, 0)) fade_out_counter += 1 if fade_out_counter > 60: finished = True screen.blit(trail_surf, (0, 0)) pygame.draw.rect(screen, BOTTOM_COLOR, (0, SCREEN_HEIGHT, SCREEN_WIDTH, BOTTOM_MARGIN)) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() pygame.display.update() clock.tick(60) # === Fade in BEGIN Button === def fade_in_begin_button(): global player_active fading = True while fading: draw_base() draw_grid() white_overlay = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT + BOTTOM_MARGIN), pygame.SRCALPHA) white_overlay.fill((255, 255, 255, 8)) screen.blit(trail_surf, (0, 0)) screen.blit(white_overlay, (0, 0)) begin_button.fade_in() begin_button.draw(screen) pygame.draw.rect(screen, BOTTOM_COLOR, (0, SCREEN_HEIGHT, SCREEN_WIDTH, BOTTOM_MARGIN)) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if begin_button.is_clicked(event): fading = False player_active = True pygame.display.update() clock.tick(60) # === Setup Variables === trail_surf = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT + BOTTOM_MARGIN), pygame.SRCALPHA) trail_surf.fill((255, 255, 255, 0)) sprite_width = 40 sprite_height = 40 sprite_x = 0 sprite_y = SCREEN_HEIGHT // 2 sprite_speed = 4 begin_button = Button("BEGIN", SCREEN_WIDTH // 2 - 100, SCREEN_HEIGHT // 2 - 40, 200, 80) player_size = 40 player_x = SCREEN_WIDTH // 2 - player_size // 2 player_y = 100 player_speed = 5 player_vel_y = 0 gravity = 0.5 jump_strength = -10 player_active = False can_jump = False # === Run Intro and Button === intro_animation() fade_in_begin_button() # === Main Loop === run = True while run: draw_base() draw_grid() draw_level(level_data) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False keys = pygame.key.get_pressed() if player_active: player_rect = pygame.Rect(player_x, player_y, player_size, player_size) # Horizontal Movement dx = 0 if keys[pygame.K_LEFT]: dx = -player_speed if keys[pygame.K_RIGHT]: dx = player_speed player_rect.x += dx for tile_rect in get_tile_rects(level_data): if player_rect.colliderect(tile_rect): if dx > 0: player_rect.right = tile_rect.left elif dx < 0: player_rect.left = tile_rect.right # Vertical Movement player_vel_y += gravity player_rect.y += player_vel_y can_jump = False for tile_rect in get_tile_rects(level_data): if player_rect.colliderect(tile_rect): if player_vel_y > 0: player_rect.bottom = tile_rect.top player_vel_y = 0 can_jump = True elif player_vel_y < 0: player_rect.top = tile_rect.bottom player_vel_y = 0 # Wall limits if player_rect.left < 0: player_rect.left = 0 if player_rect.right > SCREEN_WIDTH: player_rect.right = SCREEN_WIDTH if keys[pygame.K_SPACE] and can_jump: player_vel_y = jump_strength player_x = player_rect.x player_y = player_rect.y pygame.draw.rect(screen, BLACK, player_rect) pygame.display.update() clock.tick(60) pygame.quit()