""" ------------------------------------------------- Project: Dungeon Run Standard: 91896 (2.7) School: Tauranga Boys' College Author: Thomas Brighouse Date: March 2025 Python: ------------------------------------------------- """ import pygame from pygame.locals import * from time import sleep import time import sys import random # ALL CLASSES, These are to help layout the world and input things like loading sprites or tiles for the game. #World Class, This is for the level tiles and loading in the images. class World(): def __init__(self, data): self.tile_list = [] #Loads the tile tiles_img = pygame.image.load("Images/Level Assets/Level Tiles/tile.png") #Loads up the tiles so map making is easy. row_count = 0 for row in data: col_count = 0 for tile in row: if tile == 1: img = pygame.transform.scale(stone_img, (TILE_SIZE, TILE_SIZE)) img_rect = img.get_rect() img_rect.x = col_count * TILE_SIZE img_rect.y = row_count * TILE_SIZE tile = (img, img_rect) self.tile_list.append(tile) if tile == 2: spike = SpikeUp(col_count * TILE_SIZE, row_count * TILE_SIZE) spike_group.add(spike) if tile == 3: img = pygame.transform.scale(diamonds_img, (TILE_SIZE, TILE_SIZE)) img_rect = img.get_rect() img_rect.x = col_count * TILE_SIZE img_rect.y = row_count * TILE_SIZE tile = (img, img_rect) self.tile_list.append(tile) if tile == 4: img = pygame.transform.scale(emeralds_img, (TILE_SIZE, TILE_SIZE)) img_rect = img.get_rect() img_rect.x = col_count * TILE_SIZE img_rect.y = row_count * TILE_SIZE tile = (img, img_rect) self.tile_list.append(tile) if tile == 5: img = pygame.transform.scale(golds_img, (TILE_SIZE, TILE_SIZE)) img_rect = img.get_rect() img_rect.x = col_count * TILE_SIZE img_rect.y = row_count * TILE_SIZE tile = (img, img_rect) self.tile_list.append(tile) if tile == 6: spike = SpikeDown(col_count * TILE_SIZE, row_count * TILE_SIZE) spike_group.add(spike) if tile == 7: img = pygame.transform.scale(SlimeCube_img, (TILE_SIZE, TILE_SIZE)) img_rect = img.get_rect() img_rect.x = col_count * TILE_SIZE img_rect.y = row_count * TILE_SIZE tile = (img, img_rect) self.tile_list.append(tile) if tile == 8: exit = Exit(col_count * TILE_SIZE, row_count * TILE_SIZE - (TILE_SIZE // 2)) exit_group.add(exit) if tile == 9: spoon = Spoon(col_count * TILE_SIZE + (TILE_SIZE // 2), row_count * TILE_SIZE + (TILE_SIZE // 2)) spoon_group.add(spoon) if tile == 10: img = pygame.transform.scale(ShooterLeft_img, (TILE_SIZE, TILE_SIZE)) img_rect = img.get_rect() img_rect.x = col_count * TILE_SIZE img_rect.y = row_count * TILE_SIZE tile = (img, img_rect) self.tile_list.append(tile) if tile == 11: img = pygame.transform.scale(ShooterRight_img, (TILE_SIZE, TILE_SIZE)) img_rect = img.get_rect() img_rect.x = col_count * TILE_SIZE img_rect.y = row_count * TILE_SIZE tile = (img, img_rect) self.tile_list.append(tile) if tile == 12: img = pygame.transform.scale(ShooterDown_img, (TILE_SIZE, TILE_SIZE)) img_rect = img.get_rect() img_rect.x = col_count * TILE_SIZE img_rect.y = row_count * TILE_SIZE tile = (img, img_rect) self.tile_list.append(tile) if tile == 13: img = pygame.transform.scale(ShooterUp_img, (TILE_SIZE, TILE_SIZE)) img_rect = img.get_rect() img_rect.x = col_count * TILE_SIZE img_rect.y = row_count * TILE_SIZE tile = (img, img_rect) self.tile_list.append(tile) if tile == 14: blob = Enemy(col_count * TILE_SIZE, row_count * TILE_SIZE + 2) blob_group.add(blob) col_count += 1 row_count += 1 def draw(self): for tile in self.tile_list: screen.blit(tile[0], tile[1]) pygame.draw.rect(screen, (255, 255, 255), tile[1], 2) #Enemy Class, this is for the enemy badguys. class Enemy(pygame.sprite.Sprite): def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load("Images/Characters/Enemies/Golem.png") self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.move_direction = 1 self.move_counter = 0 def update(self): self.rect.x += self.move_direction self.move_counter += 1 if abs(self.move_counter) > 50: self.move_direction *= -1 self.move_counter *= -1 #Class for objects that are bad class SpikeUp(pygame.sprite.Sprite): def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) img = pygame.image.load("Images/Level Assets/Level Tiles/2.png") self.image = pygame.transform.scale(img, (TILE_SIZE, TILE_SIZE)) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y class SpikeDown(pygame.sprite.Sprite): def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) img = pygame.image.load("Images/Level Assets/Level Tiles/6.png") self.image = pygame.transform.scale(img, (TILE_SIZE, TILE_SIZE)) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y class Orb(pygame.sprite.Sprite): def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) img = pygame.image.load("Images/Level Assets/Level Tiles/orb.png") self.image = pygame.transform.scale(img, (TILE_SIZE // 2, TILE_SIZE // 2)) self.rect = self.image.get_rect() self.rect.center = (x, y) class Exit(pygame.sprite.Sprite): def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) img = pygame.image.load("Images/Level Assets/Level Tiles/8.png") self.image = pygame.transform.scale(img, (TILE_SIZE, int(TILE_SIZE * 1.5))) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y class Button(): def __init__(self, x, y, image): self.image = image self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.clicked = False def draw(self): action = False #get mouse position pos = pygame.mouse.get_pos() #check mouseover and clicked conditions if self.rect.collidepoint(pos): if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False: action = True self.clicked = True if pygame.mouse.get_pressed()[0] == 0: self.clicked = False #draw button screen.blit(self.image, self.rect) return action #Player Class, This is for player sprites class Player(): def __init__(self, x, y): self.reset(x, y) def update(self, game_over): dx = 0 dy = 0 walk_cooldown = 5 attack_cooldown = 5 ki_cooldown = 5 #Checks if game over if game_over == 0: #Player movement using keybinds key = pygame.key.get_pressed() if key[pygame.K_w] and self.jumped == False and self.in_air == False: self.vel_y = -15 self.jumped = True self.jump += 1 if key[pygame.K_w] == False: self.jumped = False self.jump = 0 if key[pygame.K_a]: dx -= 5 self.counter += 1 self.direction = -1 if key[pygame.K_d]: dx += 5 self.counter += 1 self.direction = 1 if key[pygame.K_SPACE] and not self.attacking: self.attacking = True self.attack_index = 0 self.attack_timer = 0 if key[pygame.K_e] and not self.attacking: self.ki = True self.attack_index = 0 self.attack_timer = 0 if key[pygame.K_a] == False and key[pygame.K_d] == False and key[pygame.K_w] == False and self.attacking == False and self.ki == False: self.counter = 0 self.jump = 0 self.index = 0 if self.direction == 1: self.image = self.images_idle_right[self.index] if self.direction == -1: self.image = self.images_idle_left[self.index] #Handle animation if self.counter > walk_cooldown: self.counter = 0 self.index += 1 if self.index >= len(self.images_right): self.index = 0 if self.direction == 1: self.image = self.images_right[self.index] if self.direction == -1: self.image = self.images_left[self.index] if self.jumped == True: self.jump += 1 if self.jump >= len(self.images_up_right): self.jump = 0 if self.direction == 1: self.image = self.images_up_right[self.jump] if self.direction == -1: self.image = self.images_up_left[self.jump] if self.attacking: hits = pygame.sprite.spritecollide(self, blob_group, False) for blob in hits: blob.kill() self.attack_timer += 1 if self.attack_timer >= attack_cooldown: self.attack_timer = 0 self.attack_index += 1 if self.attack_index >= len(self.img_atk_right): self.attack_index = 0 self.attacking = False # Done with attack else: if self.direction == 1: self.image = self.img_atk_right[self.attack_index] else: self.image = self.img_atk_left[self.attack_index] if self.ki: self.ki_timer += 1 if self.ki_timer >= ki_cooldown: self.ki_timer = 0 self.ki_index += 1 if self.ki_index >= len(self.img_ki_atk_right): self.ki_index = 0 self.ki = False # Done with attack else: if self.direction == 1: self.image = self.img_ki_atk_right[self.ki_index] else: self.image = self.img_ki_atk_left[self.ki_index] #adds the gravity self.vel_y += 1 if self.vel_y > 10: self.vel_y = 10 dy += self.vel_y #check for collision self.in_air = True for tile in world.tile_list: #check for collision in x dircetion if tile[1].colliderect(self.rect.x + dx, self.rect.y, self.width, self.height): dx = 0 #check for collision in direction if tile[1].colliderect(self.rect.x, self.rect.y + dy, self.width, self.height): #check if below the ground i.e. jumping if self.vel_y < 0: dy = tile[1].bottom - self.rect.top self.vel_y = 0 #check if below the ground i.e. falling elif self.vel_y >= 0: dy = tile[1].top - self.rect.bottom self.vel_y = 0 self.in_air = False #check for collision with enemies if pygame.sprite.spritecollide(self, blob_group, False): self.health -= 1 self.index = 0 knockback = 55 if self.direction > 0: self.rect.x -= knockback self.image = self.img_hurt_right[self.index] self.index = 0 else: self.rect.x += knockback self.image = self.img_hurt_left[self.index] self.index = 0 if self.health < 1: game_over = -1 #check for collision with dripstone if pygame.sprite.spritecollide(self, spike_group, False): game_over = -1 #check for collision with Door if pygame.sprite.spritecollide(self, exit_group, False): game_over = 1 #update player coords self.rect.x += dx self.rect.y += dy if self.rect.bottom > screen_height: self.rect.bottom = screen_height dy = 0 elif game_over == -1: self.image = self.dead_image if self.rect.y > 75: self.rect.y -= 5 #draw player onto the screen if self.direction == -1: screen.blit(self.image, (self.rect.x - (self.image.get_width() - self.width), self.rect.y)) else: screen.blit(self.image, self.rect) pygame.draw.rect(screen, (255, 255, 255), self.rect, 2) return game_over def reset(self, x, y): self.images_idle_right = [] self.images_idle_left = [] self.images_right = [] self.images_left = [] self.images_up_right = [] self.images_up_left = [] self.img_idle_right = [] self.img_idle_left = [] self.img_atk_right = [] self.img_atk_left = [] self.img_ki_atk_right = [] self.img_ki_atk_left = [] self.img_hurt_right = [] self.img_hurt_left = [] self.dead_image = [] self.index = 0 self.counter = 0 self.health = 3 self.jump = 0 #Idle Sprite images_idle_right = pygame.image.load('Images/Characters/Player/glad_idle.png') images_idle_right = pygame.transform.scale(images_idle_right, (40, 80)) images_idle_left = pygame.transform.flip(images_idle_right, True, False) self.images_idle_right.append(images_idle_right) self.images_idle_left.append(images_idle_left) #Walking Sprites for num in range(1, 10): img_right = pygame.image.load(f'Images/Characters/Player/glad_walk{num}.png') img_right = pygame.transform.scale(img_right, (40, 80)) img_left = pygame.transform.flip(img_right, True, False) self.images_right.append(img_right) self.images_left.append(img_left) #Jumping Sprites for num in range(1, 3): img_up_right = pygame.image.load(f'Images/Characters/Player/glad_jump{num}.png') img_up_right = pygame.transform.scale(img_up_right, (40, 80)) img_up_left = pygame.transform.flip(img_up_right, True, False) self.images_up_right.append(img_up_right) self.images_up_left.append(img_up_left) #Attacking Sprites for num in range(1, 5): img_atk_right = pygame.image.load(f'Images/Characters/Player/glad_attack{num}.png') img_atk_right = pygame.transform.scale(img_atk_right, (125, 80)) img_atk_left = pygame.transform.flip(img_atk_right, True, False) self.img_atk_right.append(img_atk_right) self.img_atk_left.append(img_atk_left) #Ki Attack Sprites for num in range(1, 7): img_ki_atk_right = pygame.image.load(f'Images/Characters/Player/KKB{num}.png') img_ki_atk_right = pygame.transform.scale(img_ki_atk_right, (80, 80)) img_ki_atk_left = pygame.transform.flip(img_ki_atk_right, True, False) self.img_ki_atk_right.append(img_ki_atk_right) self.img_ki_atk_left.append(img_ki_atk_left) #Death sprite self.dead_image = pygame.image.load("Images/Characters/Player/ghost.png") #Hurt sprite images_hurt_right = pygame.image.load('Images/Characters/Player/glad_hurt.png') images_hurt_right = pygame.transform.scale(images_hurt_right, (40, 80)) images_hurt_left = pygame.transform.flip(images_hurt_right, True, False) self.img_hurt_right.append(images_hurt_right) self.img_hurt_left.append(images_hurt_left) self.image = self.images_idle_right[self.index] self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.width = self.image.get_width() self.height = self.image.get_height() self.vel_y = 0 self.jumped = False self.direction = 1 self.in_air = True self.attacking = False self.attack_index = 0 self.attack_timer = 0 self.ki = False self.ki_index = 0 self.ki_timer = 0 #All DEFINE Varbles commands #Define Reset level def reset_level(level): player.reset(100, screen_height - 130) blob_group.empty() spike_group.empty() exit_group.empty() world_data = globals()[f"lvl{level}"] background_data = globals()[f"level{level}_bg"] screen.blit(background_data, (0,0)) new_world = World(world_data) return new_world #All Varibles #General Window run = True screen_width = 1200 screen_height = 800 clock = pygame.time.Clock() fps = 60 main_menu = True level = 1 max_levels = 3 score = 0 #Grid Table TILE_SIZE = 50 game_over = 0 #Abilities #Images #UI main_menu_bg = pygame.image.load("Images/Screens/Title/title_page.png") #Level Background level1_bg = pygame.image.load("Images/Level Assets/Background/bg.png") level2_bg = pygame.image.load("Images/Level Assets/Background/bg.png") level3_bg = pygame.image.load("Images/Level Assets/Background/bg.png") #The Buttons restart_img = pygame.image.load("Images/Screens/Game Over/Restart_Button.png") start_img = pygame.image.load("Images/Screens/Title/Title Button.png") leave_img = pygame.image.load("Images/Screens/Title/Title Button Leave.png") #Level Data blob_group = pygame.sprite.Group() spike_group = pygame.sprite.Group() spoon_group = pygame.sprite.Group() exit_group = pygame.sprite.Group() #load in level data and create world lvl1 = [ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [1, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 1, 3, 3, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 1, 1, 3, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 1, 3, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6, 1], [1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 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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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ] world_data = globals()[f"lvl{level}"] background_data = globals()[f"level{level}_bg"] world = World(world_data) restart_button = Button(screen_width // 2 - 50, screen_height // 2 + 100, restart_img) start_button = Button(screen_width // 2 - 350, screen_height // 2 - 250, start_img) exit_button = Button(screen_width // 2 + 150, screen_height // 2, leave_img) #Player Data player = Player(100, screen_height - 130) # General setup pygame.init clock = pygame.time.Clock() screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("I am steve") # This is the main code that runs it all while True: clock.tick(fps) if main_menu == True: screen.blit(main_menu_bg, (0,0)) if exit_button.draw(): pygame.quit() sys.exit() if start_button.draw(): main_menu = False else: screen.blit(background_data, (0,0)) world.draw() if game_over == 0: blob_group.update() #update score #check if a coin has been collected if pygame.sprite.spritecollide(player, spoon_group, True): score += 1 print(score) blob_group.draw(screen) spike_group.draw(screen) spoon_group.draw(screen) exit_group.draw(screen) game_over = player.update(game_over) #if player has died if game_over == -1: if restart_button.draw(): player.reset(100, screen_height - 130) world = reset_level(level) game_over = 0 score = 0 #if player has completed the level if game_over == 1: #reset game and go to next levl level += 1 if level <= max_levels: #reset level world_data = [] world = reset_level(level) game_over = 0 else: if restart_button.draw(): level = 1 screen.blit(background_data, (0,0)) #reset level world_data = [] world = reset_level(level) game_over = 0 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() pygame.display.update()