Male_zoo_Projekt_SI/enclosure.py

73 lines
3.2 KiB
Python
Raw Normal View History

import pygame
class Enclosure:
def __init__(self, x1, y1, x2, y2, gate1, gate2, type, imageH, imageV, imageGate):
self.x1 = x1 - 1
self.y1 = y1 - 1
# (x1,y1) - wierzchołek przekątnej
self.x2 = x2 - 1
self.y2 = y2 - 1
# (x2,y2) - 2 wierzchołek przekątnej
self.gate1 = gate1
self.gate2 = gate2
self.type = type
self.imageH = imageH
self.imageV = imageV
self.imageGate = imageGate
def gatebuild(self, screen, grid_size):
self.imageGate = pygame.transform.scale(self.imageGate, (grid_size, grid_size))
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-04-27 19:50:18 +02:00
def draw(self, screen, grid_size):
self.imageH = pygame.transform.scale(self.imageH, (grid_size, grid_size))
self.imageV = pygame.transform.scale(self.imageV, (grid_size, grid_size))
gate_x1, gate_y1 = self.gate1
gate_x2, gate_y2 = self.gate2
gate_x1 -= 1
gate_y1 -= 1
gate_x2 -= 1
gate_y2 -= 1
if self.x1 < self.x2:
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))
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))
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))
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')
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]
return Enclosures
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)