Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help me build a pygame that does the following. 6 0 : Apply to your gravity and wind project.Number of joysticks: 1 Joystick 0
please help me build a pygame that does the following. : Apply to your gravity and wind project.Number of joysticks:
Joystick
Joystick name: Nintendo Switch Pro Controller
GUID:
Number of axes:
Axis value:
Axis value:
Axis value:
Axis value:
Axis value:
Axis value:
Number of buttons:
Button value:
Button value:
Button value:
Button value:
Button value:
Button value:
Button value:
Button value:
Button value:
Button value:
Button value:
Button value:
Button value:
Button value:
Button value:
Button value:
Number of hats:
: gravity toggled onoff you pick
: left wind applied momentarily Axis
: right wind applied momentarily Axis
: Force up Axis maps to your gravity amount
: ball returns to the center of the screen A Button
: LT Y quits game import pygame
import random
# Initialize Pygame
pygame.init
WIDTH, HEIGHT
screen pygame.display.setmodeWIDTH HEIGHT
clock pygame.time.Clock
# Load the click sound
clicksound pygame.mixer.Soundcollisionmp
# Create ball class and implement addforce to it
class Ball:
def initself x y radius, mass, color:
self.location x y
self.vector
self.acceleration
self.radius radius
self.mass mass
self.color color
def addForceself force:
fx fy force
self.acceleration fx self.mass
self.acceleration fy self.mass
# Update the ball class
def updateself:
self.vector self.acceleration
self.vector self.acceleration
self.location self.vector
self.location self.vector
self.acceleration # Reset acceleration
# Add boundary collision detection
if self.location or self.location WIDTH:
self.vectorself.vector
if self.location or self.location HEIGHT:
self.vectorself.vector
# Draws the balls on my screen
def drawself screen:
pygame.draw.circlescreen self.color, self.location, self.radius
balls
for i in range:
radius random.randrange
x random.randrangeradius WIDTH radius
y random.randrangeradius HEIGHT radius
mass radius
color randomrandrange random.randrange random.randrange
ball Ballx y radius, mass, color
balls.appendball
def onclickpos:
# Play the click sound
clicksound.play
# Apply force towards the clicked position
for ball in balls:
dx pos ball.location
dy pos ball.location
ball.addForcedx dy
# Values for star background
stars
for i in range:
x random.randrange WIDTH
y random.randrange HEIGHT
stars.appendx y
# Draws stars on background
def drawstarsscreen stars:
for star in stars:
pygame.draw.rectscreen pygame.Rectstar star
# Game loop with on click call
running True
while running:
for event in pygame.event.get:
if event.type pygame.QUIT:
running False
if event.type pygame.MOUSEBUTTONDOWN:
onclickpygamemouse.getpos
screen.filld
drawstarsscreen stars
for ball in balls:
ball.update
ball.drawscreen
pygame.display.flip
clock.tickthe output should look just like the photo provided
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