#!/usr/bin/python3

import random

import pygame
from pygame.sprite import Sprite

class Settings:
    def __init__(self):
        self.screen_width = 600
        self.screen_height = 370
        self.screen_color = (0, 0, 0)
        #self.screen_color = (250, 250, 250)

        self.image = pygame.image.load('backgrounds/roof_top2.png')
        self.rect = self.image.get_rect()

        self.water_mark_image = pygame.image.load('backgrounds/watermark.png')
        self.water_mark_rect = self.water_mark_image.get_rect()
        self.andex_image = pygame.image.load('backgrounds/andex.png')
        self.andex_rect = self.andex_image.get_rect()

        self.water_mark_rect.y = 330
        self.water_mark_rect.x = 370
        self.andex_rect.center = (300, 175)

    def make_it_rain(self, game):
        money_rain_chance = random.randrange(20)
        if money_rain_chance == 3:
            for mon in range(22):
                self.money = Money(game)
                self.money.rect.x = self.money.rect.width * mon +  + 3
                random_number = random.randrange(13)
                if random_number == 3:
                    game.moneys.add(self.money)



class Money(Sprite):
    def __init__(self, game):
        super().__init__()

        self.screen = game.screen
        self.stack = []
        self.stack.append(pygame.image.load('backgrounds/money.png'))
        self.stack.append(pygame.image.load('backgrounds/money2.png'))
        self.image = pygame.image.load('backgrounds/money.png')
        self.rect = self.image.get_rect()

        self.rect.y = -21

    def update(self, game):
        downwards = random.randrange(3)
        self.rect.y += downwards
        for mon in game.moneys.copy():
            if mon.rect.top >= 370:
                game.moneys.remove(mon)
            else:
                money_swing = random.randrange(2)
                money_pos = random.randint(0, 1)
                money_swing *= random.randint(-1, 1)
                mon.rect.x += money_swing
                mon.image = mon.stack[money_pos]
