Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I ' m creating an animation using pygame in python. I ' m using to learn Python, program arcade games. I can't figure out how

I'm creating an animation using pygame in python. I'm using to learn Python, program arcade games. I can't figure out how to animate my image, I've created my image and it just needs to be animated. Ive pasted the code below. Basically, my idea is for the snow to be like a blizzard from the left to the right and the whole animal to be moving across the screen from right to left slowly. Moving the legs individually would be way too hard and above my level, but moving the whole animal although it seems unrealistic is at my level and easy to do.Yet I still cant seem to figure it out and the blizzard should be travelling from left to right so it looks like the deer is moving against the blizzard. The deer shouldnt be going at a fast pace either since its moving through a blizzard. Also, try to add a shooting star in the background if you can. Please make sure not to use any advanced coding, i've also pasted a sample of animation code at my level.
Sample code --at my level for animation
import pygame
import random
# Initialize the game engine
pygame.init()
BLACK =[0,0,0]
WHITE =[255,255,255]
# Set the height and width of the screen
SIZE =[400,400]
screen =pygame.display.set_mode(SIZE)
pygame.display.set_caption("Snow Animation")
# Create an empty array
snow_list =[]
# Loop 50times and add a snow flake in a random x,y position
for i in range(50):
x =random.randrange(0,400)
y =random.randrange(0,400)
snow_list.append([x,y])
clock =pygame.time.Clock()
# Loop until the user clicks the close button.
done =False
while not done:
for event in pygame.event.get():
if event.type ==pygame.QUIT:
done =True
# Set the screen background
screen.fill(BLACK)
# Process each snow flake in the list
for i in range(len(snow_list)):
# Draw the snow flake
pygame.draw.circle(screen,WHITE, snow_list[i],2)
snow_list[i][1]+=1
if snow_list[i][1]>400:
# Reset it just above the top
y =random.randrange(-50,-10)
snow_list[i][1]=y
# Give it a new x position
x =random.randrange(0,400)
snow_list[i][0]=x
pygame.display.flip()
clock.tick(20)
pygame.quit()
My code, aka my image I drew in pygame
import pygame
import random
import math
# Define some colors
BLACK =(0,0,0)
WHITE =(255,255,255)
GREEN =(0,255,0)
RED =(255,0,0)
BLUE =(0,0,255)
YELLOW =(222,176,0)
BROWN =(128,90,70)
DARK_BROWN =(106,57,37)
PINK =(255,192,203)
DARK_YELLOW =(252,234,121)
DARK_WHITE =(183,182,177)
LIGHT_BLACK =(62,65,71)
FACE_BLACK =(61,59,65,)
PI =3.14159265359
ellipse_positions =[(random.randint(0,700),random.randint(0,600))for _in range(130)]# used to generate random positions for the snow
pygame.init()
size =(700,500)
screen =pygame.display.set_mode(size)
pygame.display.set_caption("DeeRERE")
done =False
clock =pygame.time.Clock()
#main loop
while not done:
# ---Main event loop
for event in pygame.event.get():
if event.type ==pygame.QUIT:
done =True
screen.fill(BLUE)
pygame.draw.rect(screen,WHITE,[0,360,900,905],0)
# Snow
for pos in ellipse_positions:
pygame.draw.ellipse(screen,WHITE,[*pos,10,10],0)
pygame.draw.ellipse(screen,BROWN,[255,490,20,25],0)# Hooves
pygame.draw.ellipse(screen,BROWN,[500,490,20,25],0)
#Legs
pygame.draw.rect(screen,LIGHT_BLACK, [255,400,20,180],0)
pygame.draw.rect(screen,LIGHT_BLACK, [500,400,20,180],0)
pygame.draw.rect(screen,LIGHT_BLACK, [455,400,20,180],0)
pygame.draw.rect(screen,LIGHT_BLACK, [300,400,20,180],0)
#Body
pygame.draw.ellipse(screen,DARK_WHITE, [245,345,300,100],0)
#Neck
pygame.draw.rect(screen,DARK_WHITE, [265,320,20,100],0)
#Head
pygame.draw.ellipse(screen,DARK_WHITE, [220,270,75,65],0)
pygame.draw.ellipse(screen,DARK_WHITE, [195,300,50,30],0)
#Eyes
pygame.draw.ellipse(screen,BLACK,[230,280,10,15],0)
pygame.draw.ellipse(screen,BLACK,[255,280,10,15],0)
#nose
pygame.draw.ellipse(screen,PINK,[200,305,15,10],0)
#mouth
pygame.draw.line(screen,BLACK,[200,320],[220,320],2)
# Antlers
pygame.draw.line(screen,BROWN,[275,245],[275,275],5)
pygame.draw.line(screen,BROWN,[274,245],[300,245],5)
pygame.draw.line(screen,BROWN,[300,245],[300,220],5)
pygame.draw.line(screen,BROWN,[300,245],[275,245],5)
pygame.draw.line(screen,BROWN,[275,245],[260,245],5) pygame.draw.line(screen,BROWN,[260,246],[260,220],5) pygame.display.flip()# Update screen
clock.tick(

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

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

What are the role of supervisors ?

Answered: 1 week ago