Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please make my rotating elipse appear somewhere other than the cdenter of the screen and move when the dragon gets it . code is provided

please make my rotating elipse appear somewhere other than the cdenter of the screen and move when the dragon gets it. code is provided below. this is in pygames. import pygame
import random
pygame.init()
# Create a display surface
WINDOW_WIDTH =600
WINDOW_HEIGHT =300
display_surface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
# Set FPS and clock
FPS =10
clock = pygame.time.Clock()
# Set the game values
VELOCITY =5
# Load images
dragon_image = pygame.image.load("dragon_right.png")
dragon_rect = dragon_image.get_rect(topleft=(25,25))
coin_images =[
pygame.image.load("coin.png"),
pygame.image.load("coin_blue.png"),
pygame.image.load("coin_green.png")
]
coin_values ={
"coin.png": 10,
"coin_blue.png": 20,
"coin_green.png": 30
}
coin_image = random.choice(coin_images)
coin_rect = coin_image.get_rect(center=(WINDOW_WIDTH //2, WINDOW_HEIGHT //2))
background_image = pygame.image.load("star_background.png")
def draw_rotating_ellipse(surface, color, rect, angle):
ellipse_rect = pygame.Rect(0,0, rect.width, rect.height)
ellipse_rect.center = rect.center
rotated_ellipse = pygame.Surface(rect.size, pygame.SRCALPHA)
pygame.draw.ellipse(rotated_ellipse, color, rotated_ellipse.get_rect())
rotated_ellipse = pygame.transform.rotate(rotated_ellipse, angle)
surface.blit(rotated_ellipse, ellipse_rect)
# The main game loop
running = True
angle =0
while running:
# Process events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Get keys
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and dragon_rect.left >0:
dragon_rect.x -= VELOCITY
if keys[pygame.K_RIGHT] and dragon_rect.right < WINDOW_WIDTH:
dragon_rect.x += VELOCITY
if keys[pygame.K_UP] and dragon_rect.top >0:
dragon_rect.y -= VELOCITY
if keys[pygame.K_DOWN] and dragon_rect.bottom < WINDOW_HEIGHT:
dragon_rect.y += VELOCITY
# Check for collision
if dragon_rect.colliderect(coin_rect):
print(f'HIT! Collected {coin_values[coin_image]} points')
coin_rect.x = random.randint(0, WINDOW_WIDTH - coin_image.get_width())
coin_rect.y = random.randint(0, WINDOW_HEIGHT - coin_image.get_height())
coin_image = random.choice(coin_images)
# Fill display surface with star background
display_surface.blit(background_image, (0,0))
# Draw boundaries
pygame.draw.rect(display_surface, (0,255,0), dragon_rect, 1)
pygame.draw.rect(display_surface, (255,255,0), coin_rect, 1)
# Blit assets
display_surface.blit(dragon_image, dragon_rect)
draw_rotating_ellipse(display_surface, (255,0,0), coin_rect, angle)
display_surface.blit(coin_image, coin_rect)
# Update display
pygame.display.update()
# Tick the clock
clock.tick(FPS)
# Update rotation angle
angle +=1
pygame.quit()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

Students also viewed these Databases questions

Question

=+2. What is the education level of your target public?

Answered: 1 week ago