11.3℃ M Python Shape Moving You must enhance the code provided as follows: 1.The shape also can be moved up and down 2.T

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

11.3℃ M Python Shape Moving You must enhance the code provided as follows: 1.The shape also can be moved up and down 2.T

Post by answerhappygod »

11 3 M Python Shape Moving You Must Enhance The Code Provided As Follows 1 The Shape Also Can Be Moved Up And Down 2 T 1
11 3 M Python Shape Moving You Must Enhance The Code Provided As Follows 1 The Shape Also Can Be Moved Up And Down 2 T 1 (406.64 KiB) Viewed 28 times
#This is the basic structure!
# Acknowledgement to the original authors of the code on which
this
# example is based.
import pygame
pygame.init()
SCREEN_HEIGHT = 400
SCREEN_WIDTH = 400
screen = pygame.display.set_mode((SCREEN_WIDTH,
SCREEN_HEIGHT))
done = False
is_blue = True
x = 30
y = 30
time = pygame.time
while not done:
clock.tick(60)
for event in pygame.event.get():

if
event.type == pygame.QUIT:

done = True
if
event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:

is_blue = not is_blue

pressed = pygame.key.get_pressed()
if pressed[pygame.K_LEFT]: x -= 3
if pressed[pygame.K_RIGHT]: x += 3
print(f"x is {x} y is {y} timer is
{time.get_ticks()}")
screen.fill((0, 0, 0))
if is_blue: color = (0, 128, 255)
else: color = (255, 100, 0)
rect = pygame.Rect(x, y, 60,
60)
pygame.draw.rect(screen, color,
rect)
pygame.display.flip()
11.3℃ M Python Shape Moving You must enhance the code provided as follows: 1.The shape also can be moved up and down 2.The shape does not move out of the window area. i You will nee to install python3 and pygame on your machine this task. See below taken from: https://www.pygame.org/wiki/GettingStarted Pygame Installation Pygame requires Python; if you don't already have it, you can download it from python.org. Use python 3.7.7 or greater, because it is much friendlier to newbies, and additionally runs faster. The best way to install pygame is with the pip tool (which is what python uses to install packages). Note, this comes with python in recent versions. We use the --user flag to tell it to install into the home directory, rather than globally. python3 -m pip install -U pygame --user To see if it works, run one of the included examples: python3 -m pygame.examples.aliens If it works, you are ready to go! If not there are more detailed, VOL 2
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply