mousePos = pygame.mouse.___________
get_pos()
What method is used to detect collision between two single sprites?
pygame.sprite.collide_rect()
#You may assume all variables are defined
while True:
allSprites.draw()
screen.fill(WHITE)
pygame.display.flip()
The drawing is being covered up by the background.
Name one primary reason we use Sprites in Pygame.
To make collision easier.
To utilize grouping.
What is one benefit of having groups?
It allows us to do a variety of things to MULTIPLE objects at ONCE.
class Cool_Sprite(_____________):
def __init__(self):
#rest of code to initialize sprite here
pygame.sprite.Sprite
What data type does pygame.sprite.spritecollide() return?
A LIST of sprite objects.
#Assuming all variables are defined
allSprites = pygame.sprite.Group()
allSprites.append(player)
allSprites.add(player)
What sprite attribute represents its hitbox?
rect
Which is the only collision method we have learned that works with groups?
for event in pygame.event.get():
if event.type == pygame.______________:
print("You released the mouse button!")
MOUSEBUTTONUP
What does the third argument in pygame.sprite.spritecollide() indicate?
Whether or not the object in the group will be killed when the collision occurs.
collisions = pygame.sprite.spritecollide(player, coins)
Missing third argument
child classes
What method should be used instead of screen.blit when drawing Sprites in a group?
.draw()
#This is used in the constructor of a Sprite
self.rect = self.image.________
get_rect()
Write an if statement that detects collision between a sprite called player and a group called coins, and removes the coin when run into.
if len(pygame.sprite.spritecollide(player, coins, True) > 0:
or similar
#Fill in the blank
class Player(pygame.sprite.Sprite):
def __init__(self, __________<--):
super().__init__()
self.image = playerImg
self.rect = pygame.image.get_rect()
self.rect.x = myX
self.rect.y = myY
Missing myX and myY as parameters
What are two different methods you can use to effectively remove a sprite from a group?
.kill() and .remove()
Why is important to put all movement in a method called update()?
treats = pygame.sprite.Group()
treat = Treat()
Modify this code, using a for loop, so that it adds 10 Treat objects to the group called treats.
for i in range(10):
treats.add(Treat())
or similar
Write an if statement that would detect collision between a sprite called player and a point called mousePos.
if player.rect.collidepoint(mousePos) == True:
(or similar)
#you may assume playerImg is defined
def __init__(self, myX, myY):
__________ <--what is missing here?
self.image = playerImg
self.rect = self.image.get_rect()
self.rect = pygame.image.get_rect()
self.rect.x = myX
self.rect.y = myY
Missing super().__init__()
Suppose you wanted your sprite to look like a solid-colored rectangle. As opposed to loading in an image, you can set self.image to what kind of object in the constructor?
Surface
What happens when you try to detect collision between a sprite and a group that that sprite is a member of?
It is always going to detect a collision.