0% found this document useful (0 votes)
66 views1 page

Red Dragon Follows Mouse Cursor in Pygame

This document is a Python script using Pygame to create a window where a red dragon follows the mouse cursor. The dragon is represented as a circle that moves towards the cursor's position at a defined speed. The program runs in a loop until the window is closed, updating the display at 60 frames per second.

Uploaded by

organixer0
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views1 page

Red Dragon Follows Mouse Cursor in Pygame

This document is a Python script using Pygame to create a window where a red dragon follows the mouse cursor. The dragon is represented as a circle that moves towards the cursor's position at a defined speed. The program runs in a loop until the window is closed, updating the display at 60 frames per second.

Uploaded by

organixer0
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import pygame

import sys

[Link]()

# Screen
WIDTH, HEIGHT = 800, 600
screen = [Link].set_mode((WIDTH, HEIGHT))
[Link].set_caption("Red Dragon Follows Cursor")

# Dragon properties
dragon_pos = [Link].Vector2(WIDTH//2, HEIGHT//2)
dragon_speed = 5
dragon_color = (255, 0, 0) # Red
dragon_radius = 25

clock = [Link]()

while True:
for event in [Link]():
if [Link] == [Link]:
[Link]()
[Link]()

[Link]((0, 0, 0)) # Background black

# Get mouse position


mouse_pos = [Link].get_pos()
mouse_vec = [Link].Vector2(mouse_pos)

# Move dragon towards cursor


direction = (mouse_vec - dragon_pos)
if [Link]() != 0:
direction = [Link]()
dragon_pos += direction * dragon_speed

# Draw dragon
[Link](screen, dragon_color, (int(dragon_pos.x),
int(dragon_pos.y)), dragon_radius)

[Link]()
[Link](60)

You might also like