diff --git a/game.py b/game.py index bd1d960..cbd005f 100644 --- a/game.py +++ b/game.py @@ -1,16 +1,60 @@ from pygame import * +import sys, random from sprites.grass import Grass +from sprites.house import House +from pygame.locals import * + +all_sprites = sprite.Group() cells = [] FPS = 5 cell_size = 64 +fps_clock = time.Clock() -PLAY_WIDTH = 640 -PLAY_HEIGHT = 640 +#Tu będzie zmienna do wybrania przez użytkownika na start/ do zmiany w trakcie "gry" +home_amount = 9 + +#Obszar przeznaczony na płyki +PLAY_WIDTH = (home_amount+1)*64 +PLAY_HEIGHT = PLAY_WIDTH + +#Całe okno gry (z przyszłym hud'em) WINDOW_WIDTH = PLAY_WIDTH + 100 WINDOW_HEIGHT = PLAY_HEIGHT + 100 +GAMEWINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32) +WHITE = (255, 255, 255) +display.set_caption('Śmieciarz WMI') - -for x in range(WINDOW_HEIGHT//64): +#Dodawanie pól typu Grass +for x in range(PLAY_HEIGHT//64): cells.append([]) - for y in range(WINDOW_HEIGHT//64): - cells[x].append(grass(x,y)) + for y in range(PLAY_HEIGHT//64): + grass = Grass(x,y) + cells[x].append(grass) + + +#Losowanie domków i dodawanie je do mapy +for x in range(home_amount): + #Sprawdzenie, czy istnieje już domek na danej pozycji, jeżeli tak to losuj ponownie + x = random.randint(0, (PLAY_WIDTH//64)-1) + y = random.randint(0, (PLAY_WIDTH//64)-1) + print(x,y) + house = House(x,y) + cells[x][y] = house + +#Dodawanie wszystkich spritow do grupy spritow +for x in range(len(cells)): + for y in range(len(cells[x])): + all_sprites.add(cells[x][y]) + +#Sama gierka +while(1): + for e in event.get(): + if e.type == QUIT: + quit() + sys.exit() + + all_sprites.update() + all_sprites.draw(GAMEWINDOW) + + display.flip() + fps_clock.tick(FPS) diff --git a/images/tile.png b/images/grass.png old mode 100644 new mode 100755 similarity index 100% rename from images/tile.png rename to images/grass.png diff --git a/images/house_empty.png b/images/house.png similarity index 100% rename from images/house_empty.png rename to images/house.png diff --git a/sprites/__pycache__/cell.cpython-36.pyc b/sprites/__pycache__/cell.cpython-36.pyc new file mode 100644 index 0000000..e47bd02 Binary files /dev/null and b/sprites/__pycache__/cell.cpython-36.pyc differ diff --git a/sprites/__pycache__/grass.cpython-36.pyc b/sprites/__pycache__/grass.cpython-36.pyc new file mode 100644 index 0000000..648142c Binary files /dev/null and b/sprites/__pycache__/grass.cpython-36.pyc differ diff --git a/sprites/__pycache__/house.cpython-36.pyc b/sprites/__pycache__/house.cpython-36.pyc new file mode 100644 index 0000000..0f044c2 Binary files /dev/null and b/sprites/__pycache__/house.cpython-36.pyc differ diff --git a/sprites/cell.py b/sprites/cell.py index 7eb962e..babf778 100644 --- a/sprites/cell.py +++ b/sprites/cell.py @@ -1,9 +1,10 @@ -from pygame import * +# -*- coding: utf-8 -*- +import pygame import sys from pygame.locals import * -class Cell(pygame.sprite.Sprites): +class Cell(pygame.sprite.Sprite): def __init__(self,x,y): - sprite.Sprite.__init__(self) + pygame.sprite.Sprite.__init__(self) self.x = x self.y = y self.rect = pygame.Rect(x*64,y*64, 64,64) diff --git a/sprites/grass.py b/sprites/grass.py index e75e6ed..5eda041 100644 --- a/sprites/grass.py +++ b/sprites/grass.py @@ -1,8 +1,8 @@ -from pygame import * +import pygame import sys -from cell import Cell +from sprites.cell import Cell class Grass(Cell): - def __init__(x,y): + def __init__(self,x,y): Cell.__init__(self,x,y) - self.image = pygame.image.load("/images/grass.png") + self.image = pygame.image.load("images/grass.png") diff --git a/sprites/house.py b/sprites/house.py new file mode 100644 index 0000000..3ec092b --- /dev/null +++ b/sprites/house.py @@ -0,0 +1,8 @@ +import pygame +import sys +from sprites.cell import Cell + +class House(Cell): + def __init__(self,x,y): + Cell.__init__(self,x,y) + self.image = pygame.image.load("images/house.png")