Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need each coin to display a different value when hit by the dragon and I need to add a rotating elipse to this pygame.
I need each coin to display a different value when hit by the dragon and I need to add a rotating elipse to this pygame. The code is provided below. import pygame, random
pygame.init
# create a display surface
WINDOWWIDTH
WINDOWHEIGHT
displaysurface pygame.display.setmodeWINDOWWIDTH,WINDOWHEIGHT
# set FPS and clock
FPS
clock pygame.time.Clock
# set the games values
VELOCITY
# load images
dragonimage pygame.image.loaddragonright.png
dragonrect dragonimage.getrect
dragonrect.topleft
# load multiple coin images
coinimages pygameimage.loadcoinpng pygame.image.loadcoinpng pygame.image.loadcoinpng
coinimage random.choicecoinimages
coinrect coinimage.getrect
coinrect.center WINDOWWIDTHWINDOWHEIGHT
# load star background
backgroundimage pygame.image.loadstarbackground.png
# the main game loop
running True
while running:
# process each update
# listen for quit request
for event in pygame.event.get:
if event.type pygame.QUIT:
running False
# get keys to see who is pressed down
keys pygame.key.getpressed
if keyspygameKLEFT and dragonrect.left :
dragonrect.x VELOCITY
if keyspygameKRIGHT and dragonrect.right WINDOWWIDTH:
dragonrect.x VELOCITY
if keyspygameKUP and dragonrect.top :
dragonrect.y VELOCITY
if keyspygameKDOWN and dragonrect.bottom WINDOWHEIGHT:
dragonrect.y VELOCITY
# check for collison of the two objects
if dragonrect.colliderectcoinrect:
printHIT
coinrect.x random.randint WINDOWWIDTH coinimage.getwidth
coinrect.y random.randint WINDOWHEIGHT coinimage.getheight
coinimage random.choicecoinimages # select a new random coin image
# fill display surface with star background
displaysurface.blitbackgroundimage,
# draw boundaries
pygame.draw.rectdisplaysurface, dragonrect,
pygame.draw.rectdisplaysurface, coinrect,
# blit assets
displaysurface.blitdragonimage,dragonrect
displaysurface.blitcoinimage, coinrect
#update display
pygame.display.update
# tick the clock
clock.tickFPS
pygame.quit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started