Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Question: How can i incoperate user directional modifications to my code below please, that is, have the user move the images from their keyboard themselves .

import pygame

pygame.init()

screenSize = width,height = 240,180
display = pygame.display.set_mode(screenSize)

starImage = pygame.image.load("star.gif")

starBox = starImage.get_rect()

# add a second star
starImage2 = pygame.image.load("star.gif")

starBox2 = starImage2.get_rect()

keepPlaying = True

speed = [10,5]

speed2 = [5,10]

while keepPlaying:

       for event in pygame.event.get():

               if event.type == pygame.QUIT:

                          keepPlaying = False

# redraw the background

                     black = 0,0,0 display.fill(black)

# draw the stars on the screen

starBox = starBox.move(speed)

starBox2 = starBox2.move(speed2)

# update their speed, changing direction if needed

if starBox.left < 0 or starBox.right > width:

speed[0] = - speed[0]
if starBox.top < 0 or starBox.bottom > height:

speed[1] = - speed[1]
if starBox2.left < 0 or starBox2.right > width:

speed2[0] = - speed2[0]
if starBox2.top < 0 or starBox2.bottom > height:

speed2[1] = - speed2[1

collide = True
if starBox.left > starBox2.right:

collide = False
elif starBox.right < starBox2.left:

collide = False
elif starBox.top > starBox2.bottom:

collide = False
elif starBox.bottom < starBox2.top:

collide = False

else:

print ("Boom!")

# update the display

display.blit(starImage, starBox)

display.blit(starImage2, starBox2)

pygame.display.flip()

pygame.time.delay(100)

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education