-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresents.py
33 lines (25 loc) · 1.08 KB
/
presents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pygame
from pygame.sprite import Sprite
from settings import Settings
import random
class Present(Sprite):
"""Represents many presents continuously generating."""
def __init__(self, sc_game):
"""Initialise the present(s) and set its/their starting position(s)"""
super().__init__()
self.screen = sc_game.screen
self.settings = Settings()
#Load the image and set it's rect attribute.
self.image = self.settings.present_image
self.image = pygame.transform.scale(self.image, (self.settings.present_width, self.settings.present_height))
self.rect = self.image.get_rect()
#Start each new present at a random point at the top of the screen.
self.start_x = random.randint(30, 570)
self.rect.x = self.start_x
self.rect.y = self.rect.height
#Store each present's horizontal position.
self.y = float(self.rect.y)
def update(self):
"""Move the presents down"""
self.y += self.settings.present_speed
self.rect.y = self.y