Big update

This commit is contained in:
Adnovac 2019-03-19 11:47:23 +01:00
parent 3f216cab67
commit 577de170f0
9 changed files with 66 additions and 13 deletions

56
game.py
View File

@ -1,16 +1,60 @@
from pygame import * from pygame import *
import sys, random
from sprites.grass import Grass from sprites.grass import Grass
from sprites.house import House
from pygame.locals import *
all_sprites = sprite.Group()
cells = [] cells = []
FPS = 5 FPS = 5
cell_size = 64 cell_size = 64
fps_clock = time.Clock()
PLAY_WIDTH = 640 #Tu będzie zmienna do wybrania przez użytkownika na start/ do zmiany w trakcie "gry"
PLAY_HEIGHT = 640 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_WIDTH = PLAY_WIDTH + 100
WINDOW_HEIGHT = PLAY_HEIGHT + 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')
#Dodawanie pól typu Grass
for x in range(WINDOW_HEIGHT//64): for x in range(PLAY_HEIGHT//64):
cells.append([]) cells.append([])
for y in range(WINDOW_HEIGHT//64): for y in range(PLAY_HEIGHT//64):
cells[x].append(grass(x,y)) 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)

0
images/tile.png → images/grass.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,9 +1,10 @@
from pygame import * # -*- coding: utf-8 -*-
import pygame
import sys import sys
from pygame.locals import * from pygame.locals import *
class Cell(pygame.sprite.Sprites): class Cell(pygame.sprite.Sprite):
def __init__(self,x,y): def __init__(self,x,y):
sprite.Sprite.__init__(self) pygame.sprite.Sprite.__init__(self)
self.x = x self.x = x
self.y = y self.y = y
self.rect = pygame.Rect(x*64,y*64, 64,64) self.rect = pygame.Rect(x*64,y*64, 64,64)

View File

@ -1,8 +1,8 @@
from pygame import * import pygame
import sys import sys
from cell import Cell from sprites.cell import Cell
class Grass(Cell): class Grass(Cell):
def __init__(x,y): def __init__(self,x,y):
Cell.__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")

8
sprites/house.py Normal file
View File

@ -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")