Enabled multiple images for house
This commit is contained in:
parent
c537d6c581
commit
f18f6dcbb2
10
enums/house_image.py
Normal file
10
enums/house_image.py
Normal file
@ -0,0 +1,10 @@
|
||||
from enum import Enum
|
||||
class House_image(Enum):
|
||||
house = "images/house.png"
|
||||
plastic = "images/house_plastic.png"
|
||||
metal = "images/house_metal.png"
|
||||
glass = "images/house_glass.png"
|
||||
plastic_glass = "images/house_plastic_glass.png"
|
||||
plastic_metal = "images/house_plastic_metal.png"
|
||||
glass_metal = "images/house_glass_metal.png"
|
||||
full = "images/house_full.png"
|
1
game.py
1
game.py
@ -11,6 +11,7 @@ FPS = 60
|
||||
|
||||
all_sprites = sprite.Group()
|
||||
fps_clock = time.Clock()
|
||||
|
||||
######################################
|
||||
|
||||
##INITIALIZE DYNAMIC VARIABLES########
|
||||
|
@ -1,7 +1,9 @@
|
||||
import pygame
|
||||
import sys
|
||||
import random
|
||||
from enum import Enum
|
||||
from sprites.cell import Cell
|
||||
from enums.house_image import House_image
|
||||
|
||||
PLASTIC = 0 # blue
|
||||
GLASS = 1 # green
|
||||
@ -11,7 +13,7 @@ METAL = 2 # yellow
|
||||
class House(Cell):
|
||||
def __init__(self, x, y, max_plastic, max_glass, max_metal):
|
||||
Cell.__init__(self, x, y)
|
||||
self.image = pygame.image.load("images/house.png")
|
||||
self.image = pygame.image.load(House_image.house.value)
|
||||
self.rubbish = [random.randint(0, max_plastic), random.randint(
|
||||
0, max_glass), random.randint(0, max_metal)] # plastic, glass, metal
|
||||
|
||||
@ -20,16 +22,28 @@ class House(Cell):
|
||||
self.max_metal = max_metal
|
||||
|
||||
def generate_rubbish(self):
|
||||
if(random.randint(0, 5) == 1): # 1/5 szansa na wyrzucenie śmiecia w klatce
|
||||
if(random.randint(0, 50) == 1): # 1/5 szansa na wyrzucenie śmiecia w klatce
|
||||
thrash_type = random.randint(0, 2)
|
||||
self.rubbish[thrash_type] = self.rubbish[thrash_type] + 1
|
||||
|
||||
#mozna ladniej?
|
||||
if(self.rubbish[PLASTIC] > self.max_plastic):
|
||||
self.image = pygame.image.load("images/house_plastic.png")
|
||||
if(self.rubbish[GLASS] > self.max_glass):
|
||||
self.image = pygame.image.load("images/house_glass.png")
|
||||
if(self.rubbish[METAL] > self.max_metal):
|
||||
self.image = pygame.image.load("images/house_metal.png")
|
||||
if(self.rubbish[GLASS] > self.max_glass):
|
||||
if(self.rubbish[METAL] > self.max_metal):
|
||||
self.image = pygame.image.load(House_image.full.value) #plastik, szklo, metal
|
||||
else:
|
||||
self.image = pygame.image.load(House_image.plastic_glass.value) #plastik, szklo
|
||||
elif(self.rubbish[METAL] > self.max_metal):
|
||||
self.image = pygame.image.load(House_image.plastic_metal.value) #plastik, metal
|
||||
else:
|
||||
self.image = pygame.image.load(House_image.plastic.value) #plastik
|
||||
elif(self.rubbish[GLASS] > self.max_glass):
|
||||
if(self.rubbish[METAL] > self.max_metal):
|
||||
self.image = pygame.image.load(House_image.glass_metal.value) #szklo, metal
|
||||
else:
|
||||
self.image = pygame.image.load(House_image.glass.value) #szklo
|
||||
elif(self.rubbish[METAL] > self.max_metal):
|
||||
self.image = pygame.image.load(House_image.metal.value) #metal
|
||||
|
||||
def check_rubbish_status(self):
|
||||
print("plastic: " + str(self.rubbish[PLASTIC]) + " glass: " + str(
|
||||
|
Loading…
Reference in New Issue
Block a user