-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcloud.py
More file actions
28 lines (24 loc) · 889 Bytes
/
cloud.py
File metadata and controls
28 lines (24 loc) · 889 Bytes
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
import pygame
import random
from pygame.locals import RLEACCEL
from screen import Screen
# Define the cloud object extending pygame.sprite.Sprite
# Use an image for a better looking sprite
class Cloud(pygame.sprite.Sprite):
def __init__(self):
super(Cloud, self).__init__()
self.surf = pygame.image.load("icons/cloud.png").convert()
self.surf.set_colorkey((0, 0, 0), RLEACCEL)
# The starting position is randomly generated
self.rect = self.surf.get_rect(
center=(
random.randint(Screen.height + 20, Screen.width + 100),
random.randint(0, Screen.height),
)
)
# Move the cloud based on a constant speed
# Remove it when it passes the left edge of the screen.py
def update(self):
self.rect.move_ip(-5, 0)
if self.rect.right < 0:
self.kill()