File: cloud.py

package info (click to toggle)
funnyboat 1.5-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 4,368 kB
  • sloc: python: 2,153; makefile: 5; sh: 3
file content (55 lines) | stat: -rw-r--r-- 1,465 bytes parent folder | download | duplicates (5)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pygame
import math
import random

from locals import *

import util

def init():
    Cloud.images = []
    Cloud.images.append(util.load_image("cloud1"))
    Cloud.images.append(util.load_image("cloud2"))
    Cloud.images.append(util.load_image("cloud3"))
    Cloud.images.append(util.load_image("cloud4"))

def update():
    if Cloud.t % 150 == 0:
        Cloud.global_clouds.append(Cloud())
        Cloud.cloud_sprites.add(Cloud.global_clouds[-1])
    for cloud in Cloud.global_clouds:
        cloud.update()
        if cloud.rect.right < 0:
            Cloud.global_clouds.remove(cloud)
            Cloud.cloud_sprites.remove(cloud)

    Cloud.t += 1

def draw(screen):
    Cloud.cloud_sprites.draw(screen)

class Cloud (pygame.sprite.Sprite):
    images = None
    global_clouds = []
    cloud_sprites = pygame.sprite.Group()
    t = 0
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)

        if not Cloud.images:
            cloud.init()

        screen = pygame.display.get_surface()
        self.area = screen.get_rect()
        self.cloudtype = int(random.random() * len(Cloud.images))

        self.image = Cloud.images[self.cloudtype]

        self.rect = pygame.Rect(SCREEN_WIDTH, random.random()*70, self.image.get_width(), self.image.get_height())
        self.life = 0

        self.dx, self.dy = -1, 0

    def update(self):
        self.rect.top = self.rect.top + self.dy
        self.rect.left = self.rect.left + self.dx