Un jeu créé entièrement par ChatGPT OpenAI
import math import kandinsky import turtle import time import ion # Set up the game window # Set up the player player_size = 16 player_hitbox_size = 14 player_x = 104 player_y = 190 player_dx = 0 player_dy = 0 player_speed = 2 # Set up the player bullet player_bullet_size = 4 player_bullet_x = None player_bullet_y = None player_bullet_dx = None player_bullet_dy = None player_bullet_speed = 5 # Set up the boss boss_size = 64 boss_hitbox_size = 60 boss_x = 79 boss_y = 10 boss_dx = 1 boss_dy = 1 boss_speed = 1 # Set up the boss bullet boss_bullet_size = 8 boss_bullet_x = None boss_bullet_y = None boss_bullet_dx = None boss_bullet_dy = None boss_bullet_speed = 2 # Set up the boss health boss_health = 100 # Define a function to draw a rectangle def draw_rect(x, y, width, height, color): kandinsky.fill_rect(x, y, width, height, color) kandinsky.draw_rect(x, y, width, height, color) # Define a function to draw the player def draw_player(): draw_rect(player_x, player_y, player_size, player_size, (255, 255, 0)) draw_rect(player_x + (player_size - player_hitbox_size) // 2, player_y + (player_size - player_hitbox_size) // 2, player_hitbox_size, player_hitbox_size, (0, 0, 0)) # Define a function to draw the player bullet def draw_player_bullet(): if player_bullet_x is not None: draw_rect(player_bullet_x, player_bullet_y, player_bullet_size, player_bullet_size, (255, 255, 255)) # Define a function to draw the boss def draw_boss(): draw_rect(boss_x, boss_y, boss_size, boss_size, (255, 0, 0)) draw_rect(boss_x + (boss_size - boss_hitbox_size) // 2, boss_y + (boss_size - boss_hitbox_size) // 2, boss_hitbox_size, boss_hitbox_size, (0, 0, 0)) # Define a function to draw the boss bullet def draw_boss_bullet(): if boss_bullet_x is not None: draw_rect(boss_bullet_x, boss_bullet_y, boss_bullet_size, boss_bullet_size, (0, 0, 255)) # Define a function to check for hitbox collision def hitbox_collision(x1, y1, size1, x2, y2, size2): return x1 + size1 > x2 and x2 + size2 > x1 and y1 + size1 > y2 and y2 + size2 > y1 # Define a function to move the player def move_player(): global player_x, player_y, player_dx, player_dy # Set the player's velocity based on input player_dx = 0 if ion.keyboard.is_pressed("LEFT"): player_dx = -player_speed if ion.keyboard.is_pressed("RIGHT"): player_dx = player_speed # Move the player player_x += player_dx player_y += player_dy # Keep the player within the game window if player_x < 0: player_x = 0 if player_x > 208: player_x = 208 if player_y < 0: player_y = 0 if player_y > 208: player_y = 208 # Define a function to move the player bullet def move_player_bullet(): global player_bullet_x, player_bullet_y, player_bullet_dx, player_bullet_dy # Move the player bullet if player_bullet_x is not None: player_bullet_x += player_bullet_dx player_bullet_y += player_bullet_dy # Check if the player bullet is out of bounds if player_bullet_x < 0 or player_bullet_x > 208 or player_bullet_y < 0 or player_bullet_y > 208: player_bullet_x = None player_bullet_y = None player_bullet_dx = None player_bullet_dy = None # Check if the player bullet hits the boss if hitbox_collision(player_bullet_x, player_bullet_y, player_bullet_size, boss_x, boss_y, boss_hitbox_size): global boss_health boss_health -= 10 player_bullet_x = None player_bullet_y = None player_bullet_dx = None player_bullet_dy = None # Define a function to move the boss def move_boss(): global boss_x, boss_y, boss_dx, boss_dy # Move the boss boss_x += boss_dx boss_y += boss_dy # Reverse direction if the boss hits a wall if boss_x < 0 or boss_x > 158: boss_dx = -boss_dx if boss_y < 0 or boss_y > 118: boss_dy = -boss_dy # Define a function to move the boss bullet def move_boss_bullet(): global boss_bullet_x, boss_bullet_y, boss_bullet_dx, boss_bullet_dy # Move the boss bullet if boss_bullet_x is not None: boss_bullet_x += boss_bullet_dx boss_bullet_y += boss_bullet_dy # Check if the boss bullet is out of bounds if boss_bullet_x < 0 or boss_bullet_x > 208 or boss_bullet_y < 0 or boss_bullet_y > 208: boss_bullet_x = None boss_bullet_y = None boss_bullet_dx = None boss_bullet_dy = None # Check if the boss bullet hits the player if hitbox_collision(boss_bullet_x, boss_bullet_y, boss_bullet_size, player_x, player_y, player_hitbox_size): global player_health player_health -= 10 boss_bullet_x = None boss_bullet_y = None boss_bullet_dx = None boss_bullet_dy = None # Define a function to check for collisions between hitboxes def hitbox_collision(x1, y1, size1, x2, y2, size2): distance = math.sqrt((x1-x2)**2 + (y1-y2)**2) if distance < size1/2 + size2/2: return True else: return False