formatted file to pep8 and changed readme

This commit is contained in:
Michał Starski 2019-03-21 01:25:19 +01:00
parent 59f9eaae36
commit c537d6c581
10 changed files with 183 additions and 158 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ VENV
env
**/__pycache__
linux_env
.vscode

View File

@ -2,6 +2,7 @@
## Lekki notateczki
```yaml
Modele:
Smieciarka:
- Zbiera smieci
@ -20,7 +21,6 @@ Modele:
- Ma swoj typ
- { { LICZNIK ? } }
Mapa:
Blok:
- Dom
@ -30,15 +30,16 @@ Mapa:
Opis:
- Kwadrat o boku X na ktorym ukladamy obiekty
- Obiektow innych niz droga moze byc x-1
```
Smieciarz ma sie nauczyc jezdzic po mapie i prawidolowo wywozic rozne typy smieci
=================
## Uruchamianie
Aby uruchomić grę należy podać do skryptu argument __home-count__, który ustala liczbę domków do wyrenderowania na mapie:
Aby uruchomić grę należy podać do skryptu argument **home-count**, który ustala liczbę domków do wyrenderowania na mapie:
```shell
game.py --home-count=<amount>
$ game.py --home-count=<amount>
```

View File

@ -1,6 +1,8 @@
import sys, getopt
import sys
import getopt
from sprites.cell import CELL_SIZE
def set_home_amount():
arguments = sys.argv[1:]
try:
@ -17,6 +19,7 @@ def set_home_amount():
print(err)
sys.exit(2)
home_amount = set_home_amount()
PLAY_WIDTH = home_amount*CELL_SIZE

View File

@ -1,5 +1,6 @@
from pygame import *
import sys, random
import sys
import random
from config import PLAY_WIDTH, PLAY_HEIGHT, home_amount
from sprites.house import House
from pygame.locals import *
@ -47,7 +48,6 @@ while(1):
if e.key == K_LEFT:
gc.move('left', obstacles_coords)
all_sprites.update()
all_sprites.draw(GAMEWINDOW)

View File

@ -5,6 +5,7 @@ from pygame.locals import *
CELL_SIZE = 64
class Cell(pygame.sprite.Sprite):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self)
@ -13,4 +14,5 @@ class Cell(pygame.sprite.Sprite):
self.update()
def update(self):
self.rect = pygame.Rect(self.x*CELL_SIZE,self.y*CELL_SIZE, CELL_SIZE, CELL_SIZE)
self.rect = pygame.Rect(
self.x*CELL_SIZE, self.y*CELL_SIZE, CELL_SIZE, CELL_SIZE)

View File

@ -1,6 +1,7 @@
import pygame
from sprites.cell import Cell
class Garbage_collector(Cell):
def __init__(self, x, y):
Cell.__init__(self, x, y)
@ -20,5 +21,3 @@ class Garbage_collector(Cell):
self.y = value
self.update()

View File

@ -2,6 +2,7 @@ import pygame
import sys
from sprites.cell import Cell
class Grass(Cell):
def __init__(self, x, y):
Cell.__init__(self, x, y)

View File

@ -1,16 +1,19 @@
import pygame
import sys, random
import sys
import random
from sprites.cell import Cell
PLASTIC = 0 # blue
GLASS = 1 # green
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.rubbish = [random.randint(0, max_plastic), random.randint(0, max_glass), random.randint(0, max_metal)] #plastic, glass, metal
self.rubbish = [random.randint(0, max_plastic), random.randint(
0, max_glass), random.randint(0, max_metal)] # plastic, glass, metal
self.max_plastic = max_plastic
self.max_glass = max_glass
@ -29,4 +32,5 @@ class House(Cell):
self.image = pygame.image.load("images/house_metal.png")
def check_rubbish_status(self):
print( "plastic: " + str(self.rubbish[PLASTIC]) + " glass: " + str(self.rubbish[GLASS]) + " metal: " + str(self.rubbish[METAL]) )
print("plastic: " + str(self.rubbish[PLASTIC]) + " glass: " + str(
self.rubbish[GLASS]) + " metal: " + str(self.rubbish[METAL]))

View File

@ -2,6 +2,7 @@ import pygame
import sys
from sprites.cell import Cell
class Landfill(Cell):
def __init__(self, x, y, type):
Cell.__init__(self, x, y)

View File

@ -1,4 +1,6 @@
import sys, getopt, random
import sys
import getopt
import random
from config import PLAY_WIDTH, PLAY_HEIGHT, home_amount
from sprites.cell import CELL_SIZE
from sprites.grass import Grass
@ -6,6 +8,7 @@ from sprites.house import House
from sprites.landfill import Landfill
from sprites.garbage_collector import Garbage_collector
def generate_rand_coordinates(max_x, max_y):
return (random.randint(0, max_x), random.randint(0, (max_y)))
@ -14,7 +17,8 @@ def generate_rand_coordinates(max_x, max_y):
def generate_grass(all_sprites):
grass = []
for k in range(0, (PLAY_WIDTH//CELL_SIZE)*(PLAY_HEIGHT//CELL_SIZE)):
x,y = (int(k%(PLAY_WIDTH//CELL_SIZE)), int(k/(PLAY_WIDTH//CELL_SIZE)))
x, y = (int(k % (PLAY_WIDTH//CELL_SIZE)),
int(k/(PLAY_WIDTH//CELL_SIZE)))
grass.append(Grass(x, y))
for item in grass:
@ -22,11 +26,14 @@ def generate_grass( all_sprites ):
##################################################################################
##GENERATE HOUSES#################################################################
def generate_houses(all_sprites, obstacles_coords):
houses = []
home_counter = home_amount
while(home_counter != 0):
x,y = generate_rand_coordinates((PLAY_WIDTH//CELL_SIZE)-1,(PLAY_HEIGHT//CELL_SIZE)-1)
x, y = generate_rand_coordinates(
(PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1)
if((x, y) not in obstacles_coords):
houses.append(House(x, y, 10, 10, 10))
obstacles_coords.append((x, y))
@ -37,11 +44,14 @@ def generate_houses( all_sprites, obstacles_coords ):
##################################################################################
##GENERATE LANDFILLS##############################################################
def generate_landfills(all_sprites, obstacles_coords):
landfills = []
landfill_counter = 3
while(landfill_counter != 0):
x,y = generate_rand_coordinates((PLAY_WIDTH//CELL_SIZE)-1,(PLAY_HEIGHT//CELL_SIZE)-1)
x, y = generate_rand_coordinates(
(PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1)
if((x, y) not in obstacles_coords):
landfills.append(Landfill(x, y, landfill_counter-1))
obstacles_coords.append((x, y))
@ -52,9 +62,12 @@ def generate_landfills( all_sprites, obstacles_coords ):
##################################################################################
##GENERATE GARBAGE COLLECTOR######################################################
def generate_garbage_collector(all_sprites, obstacles_coords):
while(True):
x,y = generate_rand_coordinates((PLAY_WIDTH//CELL_SIZE)-1,(PLAY_HEIGHT//CELL_SIZE)-1)
x, y = generate_rand_coordinates(
(PLAY_WIDTH//CELL_SIZE)-1, (PLAY_HEIGHT//CELL_SIZE)-1)
if((x, y) not in obstacles_coords):
gc = Garbage_collector(x, y)
break