You are on page 1of 2

from wizardlib import *

######## DEFINE FUNCTIONS BELOW ###################

def win_game():
clear()
win_text = add_text("You win!", 64)
position_element(win_text, "center", 100)

def lose_game():
clear()
lose_text = add_text("You Lose!", 64)
position_element(lose_text, "center", 100)

def hit_wall():
global health
position_element(knight, start_x, start_y)
health = health - 10
update_text(health_text, f"Health: {health}")
if health <= 0:
lose_game()

def check_key(key):
if key == "w" or key == "k_up":
move_up(knight, 5)
elif key == "a" or key == "k_left":
move_left(knight, 5)
elif key == "s" or key == "k_down":
move_down(knight, 5)
elif key == "d" or key == "right":
move_right(knight, 5)
def add_wall(x, y, make_vertical):
wall = add_image("wall.png", 105)
position_element(wall, x, y)
if make_vertical:
rotate_element(wall, 90)
check_collision(knight, wall, hit_wall)
def add_ghost(x, y, animate_vertical):
ghost = add_image("ghost.png", 50)
position_element(ghost, x, y)
check_collision(ghost, knight, lose_game)
if animate_vertical:
animate_up(ghost, 100, 1.5, True)
else:
animate_left(ghost, 100, 1.5, True)

################ STARTER CODE ######################

add_background("background.png")

title_text = add_text("Castle Quest", 64)


position_element(title_text, "center", 0)
castle = add_image("castle.png", 400)
position_element(castle, "right", 200)

mountains = add_image("mountains.png", 500)


position_element(mountains, -100, 600)

health = 100
health_text = add_text(f"Health: {health}", 42)
position_element(health_text, 100, 100)

knight = add_image("knight.png", 50)


start_x = 200
start_y = 600
position_element(knight, start_x, start_y)

####################################################

keydown(check_key)
add_wall(100, 400, True)
add_wall(100, 500, True)
add_wall(350, 450, False)
add_wall(450, 450, False)
add_wall(300, 500, True)
add_wall(100, 300, True)
add_wall(150, 250, False)
add_wall(250, 250, False)
add_wall(350, 250, False)
add_wall(100, 600, True)
add_wall(100, 700, True)
add_wall(300, 600, True)
add_wall(300, 700, True)
add_wall(450, 250, False)
add_wall(550, 250, False)
add_wall(650, 250, False)
add_wall(750, 250, False)
add_wall(800, 250, False)
add_wall(450, 450, False)
add_wall(550, 450, False)
add_wall(650, 450, False)
add_wall(750, 450, False)
add_wall(800, 450, False)

add_ghost(500, 300, True)


add_ghost(200, 450, False)
add_ghost(650, 300, True)
add_ghost(350, 300, True)

check_collision(castle, knight, win_game)

You might also like