2022-03-09 12:27:02 +01:00
|
|
|
import random
|
|
|
|
|
2022-03-10 19:41:05 +01:00
|
|
|
import pygame
|
2022-03-21 19:41:34 +01:00
|
|
|
from enumy import *
|
2022-03-10 19:41:05 +01:00
|
|
|
|
2022-03-09 12:27:02 +01:00
|
|
|
from stale import *
|
|
|
|
|
|
|
|
|
|
|
|
class Agent1:
|
2022-03-10 19:41:05 +01:00
|
|
|
bok = BOK_AGENTA1
|
|
|
|
bok_w_polach = BOK_AGENTA1_W_POLACH
|
2022-03-21 19:41:34 +01:00
|
|
|
Agenci = []
|
2022-03-10 19:41:05 +01:00
|
|
|
|
|
|
|
def __init__(self, pole_lewe_gorne, tekstura, kierunek, droga):
|
|
|
|
self.pole_lewe_gorne = pole_lewe_gorne
|
|
|
|
self.hitbox = pygame.Rect(self.pole_lewe_gorne.x_lewego_boku, self.pole_lewe_gorne.y_gory, self.bok, self.bok)
|
2022-03-09 12:27:02 +01:00
|
|
|
self.tekstura = tekstura
|
|
|
|
self.kierunek = kierunek
|
|
|
|
self.droga = droga
|
2022-03-21 19:41:34 +01:00
|
|
|
Agent1.Agenci.append(self)
|
2022-03-09 12:27:02 +01:00
|
|
|
|
|
|
|
def obierzNowyKierunek(self):
|
|
|
|
self.kierunek = KIERUNEK(random.randint(0, 3))
|
2022-03-09 16:08:26 +01:00
|
|
|
|
|
|
|
def okreslDlugoscDrogi(self):
|
2022-03-09 12:27:02 +01:00
|
|
|
losowa_droga = None
|
|
|
|
if self.kierunek == KIERUNEK.GORA:
|
|
|
|
losowa_droga = random.randint(0, self.hitbox.y)
|
|
|
|
elif self.kierunek == KIERUNEK.DOL:
|
|
|
|
losowa_droga = random.randint(0, WYSOKOSC_OKNA - self.hitbox.y)
|
|
|
|
elif self.kierunek == KIERUNEK.LEWO:
|
|
|
|
losowa_droga = random.randint(0, self.hitbox.x)
|
|
|
|
elif self.kierunek == KIERUNEK.PRAWO:
|
|
|
|
losowa_droga = random.randint(0, SZEROKOSC_OKNA - self.hitbox.x)
|
|
|
|
self.droga = losowa_droga - losowa_droga % KROK_AGENTA1
|
|
|
|
|
2022-03-09 16:08:26 +01:00
|
|
|
def idzWGore(self):
|
|
|
|
if self.hitbox.y - KROK_AGENTA1 > 0:
|
|
|
|
self.hitbox.y -= KROK_AGENTA1
|
|
|
|
self.droga -= KROK_AGENTA1
|
|
|
|
else:
|
|
|
|
self.droga = 0
|
|
|
|
|
|
|
|
def idzWDol(self):
|
|
|
|
if self.hitbox.y + KROK_AGENTA1 < WYSOKOSC_OKNA - self.hitbox.height:
|
|
|
|
self.hitbox.y += KROK_AGENTA1
|
|
|
|
self.droga -= KROK_AGENTA1
|
|
|
|
else:
|
|
|
|
self.droga = 0
|
|
|
|
|
|
|
|
def idzWLewo(self):
|
|
|
|
if self.hitbox.x - KROK_AGENTA1 > 0:
|
|
|
|
self.hitbox.x -= KROK_AGENTA1
|
|
|
|
self.droga -= KROK_AGENTA1
|
|
|
|
else:
|
|
|
|
self.droga = 0
|
|
|
|
|
|
|
|
def idzWPrawo(self):
|
|
|
|
if self.hitbox.x + KROK_AGENTA1 < SZEROKOSC_OKNA - self.hitbox.width:
|
|
|
|
self.hitbox.x += KROK_AGENTA1
|
|
|
|
self.droga -= KROK_AGENTA1
|
|
|
|
else:
|
|
|
|
self.droga = 0
|
|
|
|
|
2022-03-21 19:41:34 +01:00
|
|
|
def czyWszedlesWInnegoAgenta(self):
|
|
|
|
for a in self.Agenci:
|
2022-03-09 16:08:26 +01:00
|
|
|
if a.hitbox.colliderect(self.hitbox) and a != self:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2022-03-21 19:41:34 +01:00
|
|
|
def ruszSie(self):
|
2022-03-09 16:08:26 +01:00
|
|
|
if self.kierunek == KIERUNEK.GORA:
|
|
|
|
self.idzWGore()
|
|
|
|
elif self.kierunek == KIERUNEK.DOL:
|
|
|
|
self.idzWDol()
|
|
|
|
elif self.kierunek == KIERUNEK.LEWO:
|
|
|
|
self.idzWLewo()
|
|
|
|
elif self.kierunek == KIERUNEK.PRAWO:
|
|
|
|
self.idzWPrawo()
|
2022-03-21 19:41:34 +01:00
|
|
|
if self.czyWszedlesWInnegoAgenta():
|
2022-03-09 16:08:26 +01:00
|
|
|
self.cofnijSie()
|
|
|
|
self.zawroc()
|
|
|
|
self.okreslDlugoscDrogi()
|
|
|
|
# self.ruszSie(Agenci)
|
|
|
|
|
|
|
|
def cofnijSie(self):
|
|
|
|
if self.kierunek == KIERUNEK.GORA:
|
|
|
|
self.idzWDol()
|
|
|
|
elif self.kierunek == KIERUNEK.DOL:
|
|
|
|
self.idzWGore()
|
|
|
|
elif self.kierunek == KIERUNEK.LEWO:
|
|
|
|
self.idzWPrawo()
|
|
|
|
elif self.kierunek == KIERUNEK.PRAWO:
|
|
|
|
self.idzWLewo()
|
|
|
|
|
|
|
|
def zawroc(self):
|
2022-03-09 12:27:02 +01:00
|
|
|
if self.kierunek == KIERUNEK.GORA:
|
2022-03-09 16:08:26 +01:00
|
|
|
self.kierunek = KIERUNEK.DOL
|
2022-03-09 12:27:02 +01:00
|
|
|
elif self.kierunek == KIERUNEK.DOL:
|
2022-03-09 16:08:26 +01:00
|
|
|
self.kierunek = KIERUNEK.GORA
|
2022-03-09 12:27:02 +01:00
|
|
|
elif self.kierunek == KIERUNEK.LEWO:
|
2022-03-09 16:08:26 +01:00
|
|
|
self.kierunek = KIERUNEK.PRAWO
|
2022-03-09 12:27:02 +01:00
|
|
|
elif self.kierunek == KIERUNEK.PRAWO:
|
2022-03-09 16:08:26 +01:00
|
|
|
self.kierunek = KIERUNEK.LEWO
|
2022-03-10 19:41:05 +01:00
|
|
|
|
|
|
|
def zaznacz_zajmowane_pola_na_kracie(self, Krata):
|
|
|
|
for wiersz in range(self.pole_lewe_gorne.wiersz, self.pole_lewe_gorne.wiersz + self.bok_w_polach):
|
|
|
|
for kolumna in range(self.pole_lewe_gorne.kolumna, self.pole_lewe_gorne.kolumna + self.bok_w_polach):
|
2022-03-21 19:41:34 +01:00
|
|
|
Krata.krata[wiersz][kolumna] = POLE.AGENT
|