Game Written by GPT-3.5 Designed by: Wilson
import kandinsky as kd from ion import keydown, KEY_DOWN, KEY_UP, KEY_LEFT, KEY_RIGHT, KEY_BACKSPACE, KEY_EXE import random import time import math # press [EXE] to grab hostage..cute yellow thing.. WIDTH = 320 HEIGHT = 220 PLAYER_CHAR = '@' PLAYER_COLOR = (255, 255, 255) PLAYER_EYE_COLOR = (0, 0, 0) PLAYER_OUTLINE_COLOR = (0, 0, 255) # Blue outline color MONSTER_CHAR = 'M' MONSTER_COLOR = (255, 0, 0) EYE_COLOR = (0, 0, 0) KEY_CHAR = 'K' KEY_FOREGROUND_COLOR = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) # Random foreground color KEY_BACKGROUND_COLOR = (255, 255, 0) # Yellow background color DOOR_CHAR = 'D' DOOR_COLOR = (128, 128, 128) # Gray door color player_x = WIDTH // 2 player_y = HEIGHT // 2 player_energy = 100 # Initial energy value player_has_eyes = True player_speed = 5 # Initial player speed has_key = False # Player doesn't have the key initially door_locked = True # The door is locked initially key_x = random.randint(30, WIDTH - 30) key_y = random.randint(30, HEIGHT - 30) monsters = [ { 'x': random.randint(0, WIDTH - 10), 'y': random.randint(0, HEIGHT - 10), 'speed': random.uniform(0.5, 2.0), 'direction_x': random.choice([-1, 0, 1]), 'direction_y': random.choice([-1, 0, 1]), 'chase_probability': 0.1 }, { 'x': random.randint(0, WIDTH - 10), 'y': random.randint(0, HEIGHT - 10), 'speed': random.uniform(0.5, 2.0), 'direction_x': random.choice([-1, 0, 1]), 'direction_y': random.choice([-1, 0, 1]), 'chase_probability': 0.05 }, { 'x': random.randint(0, WIDTH - 10), 'y': random.randint(0, HEIGHT - 10), 'speed': random.uniform(0.5, 2.0), 'direction_x': random.choice([-1, 0, 1]), 'direction_y': random.choice([-1, 0, 1]), 'chase_probability': 0.2 } ] def calculate_angle(monster): dx = player_x - monster['x'] dy = player_y - monster['y'] return math.atan2(dy, dx) def move_toward_player(monster): angle = calculate_angle(monster) monster_speed_x = monster['speed'] * math.cos(angle) monster_speed_y = monster['speed'] * math.sin(angle) return monster_speed_x, monster_speed_y def draw_player(): # Draw a blue outline for the player player_width = 10 player_height = 10 player_outline_width = player_width + 4 # Increase the width for the outline player_outline_height = player_height + 4 # Increase the height for the outline player_outline_x = player_x - 2 # Adjust the position for the outline player_outline_y = player_y - 2 # Adjust the position for the outline kd.fill_rect(player_outline_x, player_outline_y, player_outline_width, player_outline_height, PLAYER_OUTLINE_COLOR) kd.fill_rect(player_x, player_y, player_width, player_height, PLAYER_COLOR) if player_has_eyes: eye_x1, eye_y1 = player_x + 2, player_y + 2 eye_x2, eye_y2 = player_x + 7, player_y + 2 kd.fill_rect(eye_x1, eye_y1, 2, 2, PLAYER_EYE_COLOR) kd.fill_rect(eye_x2, eye_y2, 2, 2, PLAYER_EYE_COLOR) def draw_monster(monster): x = int(monster['x']) y = int(monster['y']) kd.fill_rect(x, y, 10, 10, MONSTER_COLOR) eye_x1, eye_y1 = x + 2, y + 2 eye_x2, eye_y2 = x + 7, y + 2 kd.fill_rect(eye_x1, eye_y1, 2, 2, EYE_COLOR) kd.fill_rect(eye_x2, eye_y2, 2, 2, EYE_COLOR) def draw_key(): if not has_key: # Draw the key with a key-like appearance key_width = 10 key_height = 10 key_teeth_width = 2 key_teeth_height = 5 key_foreground_x = key_x key_foreground_y = key_y key_background_x = key_x - 2 key_background_y = key_y - 2 # Draw the key background (yellow) kd.fill_rect(key_background_x, key_background_y, key_width + 4, key_height + 4, KEY_BACKGROUND_COLOR) # Draw the key teeth (random foreground color) for i in range(3): kd.fill_rect(key_foreground_x, key_foreground_y, key_teeth_width, key_teeth_height, KEY_FOREGROUND_COLOR) key_foreground_x += key_teeth_width + 1 def draw_door(): if door_locked: kd.fill_rect(250, 150, 20, 40, DOOR_COLOR) else: kd.fill_rect(250, 150, 20, 40, (0, 255, 0)) # Green color when door is unlocked while True: kd.fill_rect(0, 0, WIDTH, HEIGHT, (0, 0, 0)) if keydown(KEY_DOWN): player_y += player_speed elif keydown(KEY_UP): player_y -= player_speed elif keydown(KEY_LEFT): player_x -= player_speed elif keydown(KEY_RIGHT): player_x += player_speed elif keydown(KEY_BACKSPACE): # Increase speed when Backspace is pressed player_speed = 10 # Increase player speed else: player_speed = 5 # Reset player speed player_x = max(0, min(player_x, WIDTH - 10)) player_y = max(0, min(player_y, HEIGHT - 10)) player_energy -= 0.01 # Slowly lose energy for monster in monsters: if random.random() < monster['chase_probability']: monster_speed_x, monster_speed_y = move_toward_player(monster) else: if random.random() < 0.02: monster['speed'] = random.uniform(0.5, 2.0) monster['direction_x'] = random.choice([-1, 0, 1]) monster['direction_y'] = random.choice([-1, 0, 1]) monster['x'] += monster['speed'] * monster['direction_x'] monster['y'] += monster['speed'] * monster['direction_y'] monster['x'] = max(0, min(monster['x'], WIDTH - 10)) monster['y'] = max(0, min(monster['y'], HEIGHT - 10)) if ( player_x < monster['x'] + 10 and player_x + 10 > monster['x'] and player_y < monster['y'] + 10 and player_y + 10 > monster['y'] ): player_energy -= 10 # Lose energy if hit by a monster draw_monster(monster) draw_player() draw_key() draw_door() kd.draw_string(str(int(player_energy)), 10, 10, (0, 0, 0)) # Change font color to black if ( player_x < key_x + 10 and player_x + 10 > key_x and player_y < key_y + 10 and player_y + 10 > key_y and not has_key and keydown(KEY_EXE) # Use EXE key to pick up the key ): has_key = True # Pick up the key when player touches it if ( player_x < 270 and player_x + 10 > 250 and player_y < 190 and player_y + 10 > 150 and has_key and door_locked ): door_locked = False # Unlock the door when player touches it with the key if ( player_x < 270 and player_x + 10 > 250 and player_y < 190 and player_y + 10 > 150 and not door_locked ): break # Exit the game when the door is unlocked time.sleep(0.03)