Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need the rotating elipse to be its own picture not connected to one of the coins and I need it to output different point

I need the rotating elipse to be its own picture not connected to one of the coins and I need it to output different point values for the coins and the elipse. Pygame code provided below. 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("coin1.png"),
pygame.image.load("coin2.png"),
pygame.image.load("coin3.png")
]
coin_values ={
"coin1.png": 10,
"coin2.png": 20,
"coin3.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

Step: 3

blur-text-image

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

Which form of proof do you find least persuasive? Why?

Answered: 1 week ago