2024-03-24 14:55:49 +01:00
|
|
|
import pygame
|
|
|
|
|
|
|
|
class Enclosure:
|
2024-04-28 22:40:13 +02:00
|
|
|
def __init__(self, x1, y1, x2, y2, gate1, gate2, type, imageH, imageV, imageGate):
|
2024-03-24 14:55:49 +01:00
|
|
|
self.x1 = x1 - 1
|
|
|
|
self.y1 = y1 - 1
|
2024-04-28 22:40:13 +02:00
|
|
|
# (x1,y1) - wierzchołek przekątnej
|
2024-03-24 14:55:49 +01:00
|
|
|
self.x2 = x2 - 1
|
|
|
|
self.y2 = y2 - 1
|
2024-04-28 22:40:13 +02:00
|
|
|
# (x2,y2) - 2 wierzchołek przekątnej
|
|
|
|
self.gate1 = gate1
|
|
|
|
self.gate2 = gate2
|
2024-03-24 17:33:58 +01:00
|
|
|
self.type = type
|
2024-03-24 14:55:49 +01:00
|
|
|
self.imageH = imageH
|
|
|
|
self.imageV = imageV
|
2024-03-24 17:33:58 +01:00
|
|
|
self.imageGate = imageGate
|
2024-03-24 14:55:49 +01:00
|
|
|
|
2024-03-24 17:33:58 +01:00
|
|
|
def gatebuild(self, screen, grid_size):
|
|
|
|
self.imageGate = pygame.transform.scale(self.imageGate, (grid_size, grid_size))
|
2024-04-28 22:40:13 +02:00
|
|
|
gate_x1, gate_y1 = self.gate1
|
|
|
|
gate_x2, gate_y2 = self.gate2
|
|
|
|
gate_x1 -= 1
|
|
|
|
gate_y1 -= 1
|
|
|
|
gate_x2 -= 1
|
|
|
|
gate_y2 -= 1
|
|
|
|
rect1 = pygame.Rect(gate_x1 * grid_size, gate_y1 * grid_size, grid_size, grid_size)
|
|
|
|
rect2 = pygame.Rect(gate_x2 * grid_size, gate_y2 * grid_size, grid_size, grid_size)
|
|
|
|
screen.blit(self.imageGate, (gate_x1 * grid_size, gate_y1 * grid_size))
|
|
|
|
screen.blit(self.imageGate, (gate_x2 * grid_size, gate_y2 * grid_size))
|
2024-03-24 17:33:58 +01:00
|
|
|
|
2024-04-27 19:50:18 +02:00
|
|
|
def draw(self, screen, grid_size):
|
2024-03-24 14:55:49 +01:00
|
|
|
self.imageH = pygame.transform.scale(self.imageH, (grid_size, grid_size))
|
|
|
|
self.imageV = pygame.transform.scale(self.imageV, (grid_size, grid_size))
|
2024-04-28 22:40:13 +02:00
|
|
|
gate_x1, gate_y1 = self.gate1
|
|
|
|
gate_x2, gate_y2 = self.gate2
|
|
|
|
gate_x1 -= 1
|
|
|
|
gate_y1 -= 1
|
|
|
|
gate_x2 -= 1
|
|
|
|
gate_y2 -= 1
|
2024-03-24 14:55:49 +01:00
|
|
|
if self.x1 < self.x2:
|
2024-04-28 22:40:13 +02:00
|
|
|
for i in range(self.x1, self.x2 + 1):
|
|
|
|
if (i, self.y1) != (gate_x1, gate_y1) and (i, self.y1) != (gate_x2, gate_y2):
|
2024-04-27 11:45:04 +02:00
|
|
|
screen.blit(self.imageH, (i * grid_size, self.y1 * grid_size))
|
2024-04-28 22:40:13 +02:00
|
|
|
if (i, self.y2) != (gate_x1, gate_y1) and (i, self.y2) != (gate_x2, gate_y2):
|
2024-04-27 11:45:04 +02:00
|
|
|
screen.blit(self.imageH, (i * grid_size, self.y2 * grid_size))
|
2024-04-28 22:40:13 +02:00
|
|
|
for j in range(self.y1, self.y2 + 1):
|
|
|
|
if (self.x1, j) != (gate_x1, gate_y1) and (self.x1, j) != (gate_x2, gate_y2):
|
2024-04-27 11:45:04 +02:00
|
|
|
screen.blit(self.imageV, (self.x1 * grid_size, j * grid_size))
|
2024-04-28 22:40:13 +02:00
|
|
|
if (self.x2, j) != (gate_x1, gate_y1) and (self.x2, j) != (gate_x2, gate_y2):
|
2024-04-27 19:50:18 +02:00
|
|
|
screen.blit(self.imageV, (self.x2 * grid_size, j * grid_size))
|
|
|
|
|
|
|
|
def create_enclosures():
|
|
|
|
fenceH = pygame.image.load('images/fenceHor.png')
|
|
|
|
fenceV = pygame.image.load('images/fenceVer.png')
|
|
|
|
gate = pygame.image.load('images/gate.png')
|
2024-04-28 22:40:13 +02:00
|
|
|
|
|
|
|
en1 = Enclosure(0, 5, 9, 11, (9, 6), (4, 11), "hot", fenceH, fenceV, gate) # Lewa klatka
|
|
|
|
en2 = Enclosure(13, 0, 29, 3, (16, 3), (27, 3), 'medium', fenceH, fenceV, gate) # Górna klatka
|
|
|
|
en3 = Enclosure(11, 5, 16, 11, (12, 5), (16, 8), 'cold', fenceH, fenceV, gate) # Środkowa klatka
|
|
|
|
en4 = Enclosure(19, 5, 31, 11, (23, 5), (25, 11), 'hot', fenceH, fenceV, gate) # Prawa klatka
|
|
|
|
en5 = Enclosure(4, 13, 28, 16, (12, 13), (20, 13), 'cold', fenceH, fenceV, gate) # Dolna klatka
|
2024-04-27 19:50:18 +02:00
|
|
|
|
|
|
|
Enclosures = [en1, en2, en3, en4, en5]
|
|
|
|
|
2024-04-28 22:40:13 +02:00
|
|
|
return Enclosures
|
2024-05-08 11:54:49 +02:00
|
|
|
|
|
|
|
def draw_enclosures(Enclosures, const):
|
|
|
|
for enclosure in Enclosures:
|
|
|
|
enclosure.draw(const.screen, const.GRID_SIZE)
|
|
|
|
|
|
|
|
def draw_gates(Enclosures, const):
|
|
|
|
for enclosure in Enclosures:
|
|
|
|
enclosure.gatebuild(const.screen, const.GRID_SIZE)
|