GradePack

    • Home
    • Blog
Skip to content
bg
bg
bg
bg

GradePack

For the next 7 questions, refer to the following code: # 1 -…

For the next 7 questions, refer to the following code: # 1 – Import packagesimport pygame, sys, random# 2 – Define constantsWINDOW_WIDTH = 640WINDOW_HEIGHT = 480FRAMES_PER_SECOND = 30C1 = (0, 0, 0)C2 = (255, 255, 255)C3 = (255, 0, 0)N_PIXELS_TO_MOVE = 5# 3 – Initialize the worldpygame.init()window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))clock = pygame.time.Clock()# 4 – Load assets: image(s), sound(s),  etc.ballImage = pygame.image.load(‘images/ball.png’)bounceSound = pygame.mixer.Sound(‘sounds/boing.wav’) # 5 – Initialize variablesballX = 50ballY = 350ballSide = 100ballRect = pygame.Rect(50, 350, 100, 100)maxBallX = WINDOW_WIDTH – ballSidemaxBallY = WINDOW_HEIGHT – ballSidecircleX = 100circleY = 50circleRadius = 30circleRect = pygame.Rect(70, 20, 60, 60)# 6 – Loop foreverwhile True:   # 7 – Check for and handle events    for event in pygame.event.get():        if event.type == pygame.QUIT:                       pygame.quit()              sys.exit()        if event.type == pygame.MOUSEBUTTONDOWN:            if ballRect.collidepoint(event.pos):                ballX = random.randrange(WINDOW_WIDTH – ballSide)                ballY = random.randrange(WINDOW_HEIGHT – ballSide)                ballRect = pygame.Rect(ballX, ballY, ballSide, ballSide)            if circleRect.collidepoint(event.pos):                circleX = random.randrange(circleRadius, WINDOW_WIDTH – circleRadius)                circleY = random.randrange(circleRadius, WINDOW_HEIGHT – circleRadius)   # 8 – Do any “per frame” actions   keyPressedTuple = pygame.key.get_pressed()           if keyPressedTuple[pygame.K_LEFT]:          if ballX == 0:            bounceSound.play()         elif ballX < N_PIXELS_TO_MOVE:            ballX = 0        else:            ballX = ballX - N_PIXELS_TO_MOVE    if keyPressedTuple[pygame.K_RIGHT]:          if ballX == maxBallX:            bounceSound.play()         elif ballX > maxBallX – N_PIXELS_TO_MOVE:            ballX = maxBallX        else:            ballX = ballX + N_PIXELS_TO_MOVE    if keyPressedTuple[pygame.K_UP]:          if ballY == 0:            bounceSound.play()         elif ballY < N_PIXELS_TO_MOVE:            ballY = 0        else:            ballY = ballY - N_PIXELS_TO_MOVE    if keyPressedTuple[pygame.K_DOWN]:          if ballY == maxBallY:            bounceSound.play()         elif ballY > maxBallY – N_PIXELS_TO_MOVE:            ballY = maxBallY        else:            ballY = ballY + N_PIXELS_TO_MOVE                ballRect = pygame.Rect(ballX, ballY, ballSide, ballSide)       # 9 – Clear the window    window.fill(C2)        # 10 – Draw all window elements    window.blit(ballImage, (ballX, ballY))       circleRect = pygame.draw.circle(window, C3, (circleX, circleY), circleRadius, 0)     # 11 – Update the window    pygame.display.update()    # 12 – Slow things down a bit   clock.tick(FRAMES_PER_SECOND)  

Read Details

What happens if the user presses and holds both the up arrow…

What happens if the user presses and holds both the up arrow and the right arrow keys (on the keyboard) at the same time?

Read Details

True or false? When the ball and the smaller circle overlap…

True or false? When the ball and the smaller circle overlap on the window, the ball appears to be over the circle, covering part of the circle (or the entire circle).

Read Details

The program displays the image of a ball and a smaller circl…

The program displays the image of a ball and a smaller circle. What color is the circle? 

Read Details

Let be the vector space of all polynomials of degree at mos…

Let be the vector space of all polynomials of degree at most 3 with real coefficients, and let be a subset of  Which of the following is/are true? A.   is isomorphic to B.  If Span S = , then S is a basis for C.  If Span S = , then S is linearly independence. 

Read Details

For the following MATLAB program, what is the output result…

For the following MATLAB program, what is the output result for det(A)?      n = 5;   A = zeros(n);   for i = 1:n      for j = i:n         A(i,j) = i+j-3;      end   end   det(A)  

Read Details

Newton’s second law states that force equals mass times [BLA…

Newton’s second law states that force equals mass times [BLANK-1].

Read Details

Analyze the importance of emergency preparedness in mitigati…

Analyze the importance of emergency preparedness in mitigating the impact of various emergencies.

Read Details

Which part of the brachial plexus gives rise to the median n…

Which part of the brachial plexus gives rise to the median nerve?

Read Details

What does Newton’s first law of motion imply about objects i…

What does Newton’s first law of motion imply about objects in motion?

Read Details

Posts pagination

Newer posts 1 … 36,204 36,205 36,206 36,207 36,208 … 84,525 Older posts

GradePack

  • Privacy Policy
  • Terms of Service
Top