Zaktualizuj 'main.py'
This commit is contained in:
parent
8d43f8abf6
commit
a40fb0a8e3
@ -1,79 +1,79 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
from agenci import *
|
from agent import *
|
||||||
from stale import *
|
from stale import *
|
||||||
import stale
|
import stale
|
||||||
|
|
||||||
OKNO = pygame.display.set_mode((SZEROKOSC_OKNA, WYSOKOSC_OKNA))
|
OKNO = pygame.display.set_mode((SZEROKOSC_OKNA, WYSOKOSC_OKNA))
|
||||||
pygame.display.set_caption("Okno1")
|
pygame.display.set_caption("Okno1")
|
||||||
Agenci1 = []
|
Agenci1 = []
|
||||||
|
|
||||||
def kratka(surface):
|
def kratka(surface):
|
||||||
for i in range(stale.NUMBER_OF_BLOCKS_WIDE):
|
for i in range(stale.NUMBER_OF_BLOCKS_WIDE):
|
||||||
new_height=round(i*BLOCK_HEIGHT)
|
new_height=round(i*BLOCK_HEIGHT)
|
||||||
new_width =round(i*BLOCK_HEIGHT)
|
new_width =round(i*BLOCK_HEIGHT)
|
||||||
pygame.draw.line(surface, BLACK,(0,new_height),(SZEROKOSC_OKNA,new_height),2)
|
pygame.draw.line(surface, BLACK,(0,new_height),(SZEROKOSC_OKNA,new_height),2)
|
||||||
pygame.draw.line(surface,BLACK,(new_width,0),(new_width,WYSOKOSC_OKNA),2)
|
pygame.draw.line(surface,BLACK,(new_width,0),(new_width,WYSOKOSC_OKNA),2)
|
||||||
|
|
||||||
def wyswietl_okno():
|
def wyswietl_okno():
|
||||||
OKNO.fill(JASNOSZARY1)
|
OKNO.fill(JASNOSZARY1)
|
||||||
for a in Agenci1:
|
for a in Agenci1:
|
||||||
OKNO.blit(a.tekstura, (a.hitbox.x, a.hitbox.y))
|
OKNO.blit(a.tekstura, (a.hitbox.x, a.hitbox.y))
|
||||||
if a.droga == 0:
|
if a.droga == 0:
|
||||||
a.obierzNowyKierunek()
|
a.obierzNowyKierunek()
|
||||||
a.okreslDlugoscDrogi()
|
a.okreslDlugoscDrogi()
|
||||||
a.ruszSie(Agenci1)
|
a.ruszSie(Agenci1)
|
||||||
kratka(OKNO)
|
kratka(OKNO)
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
|
|
||||||
def dodaj_agenta1():
|
def dodaj_agenta1():
|
||||||
los = None
|
los = None
|
||||||
if len(Agenci1) in range(0, 1):
|
if len(Agenci1) in range(0, 1):
|
||||||
los = random.randint(1, 15)
|
los = random.randint(1, 15)
|
||||||
if los != None:
|
if los != None:
|
||||||
pom = None
|
pom = None
|
||||||
if los in (1, 2) or len(Agenci1) == 0:
|
if los in (1, 2) or len(Agenci1) == 0:
|
||||||
pom = 'wozek.png'
|
pom = 'wozek.png'
|
||||||
elif los in (3, 4):
|
elif los in (3, 4):
|
||||||
pom = 'wozek_ze_skrzynka.png'
|
pom = 'wozek_ze_skrzynka.png'
|
||||||
elif los == 5 and len(Agenci1) > 6:
|
elif los == 5 and len(Agenci1) > 6:
|
||||||
pom = 'traktor_ikona.png'
|
pom = 'traktor_ikona.png'
|
||||||
if pom != None:
|
if pom != None:
|
||||||
x, y = random.randint(0, SZEROKOSC_OKNA - BOK_AGENTA1), random.randint(0, WYSOKOSC_OKNA - BOK_AGENTA1)
|
x, y = random.randint(0, SZEROKOSC_OKNA - BOK_AGENTA1), random.randint(0, WYSOKOSC_OKNA - BOK_AGENTA1)
|
||||||
hitbox = pygame.Rect(x, y, BOK_AGENTA1, BOK_AGENTA1)
|
hitbox = pygame.Rect(x, y, BOK_AGENTA1, BOK_AGENTA1)
|
||||||
warunek = True
|
warunek = True
|
||||||
for a in Agenci1:
|
for a in Agenci1:
|
||||||
if a.hitbox.colliderect(hitbox):
|
if a.hitbox.colliderect(hitbox):
|
||||||
warunek = False
|
warunek = False
|
||||||
break
|
break
|
||||||
if warunek:
|
if warunek:
|
||||||
ikona = pygame.transform.scale(pygame.image.load(os.path.join('Ikony', pom)),
|
ikona = pygame.transform.scale(pygame.image.load(os.path.join('Ikony', pom)),
|
||||||
(BOK_AGENTA1, BOK_AGENTA1))
|
(BOK_AGENTA1, BOK_AGENTA1))
|
||||||
Agenci1.append(Agent1(hitbox, ikona, KIERUNEK.GORA, 0))
|
Agenci1.append(Agent1(hitbox, ikona, KIERUNEK.GORA, 0))
|
||||||
|
|
||||||
def dodaj_agenta2():
|
def dodaj_agenta2():
|
||||||
los = None
|
los = None
|
||||||
if len(Agenci1) in range(0, 1):
|
if len(Agenci1) in range(0, 1):
|
||||||
los = random.randint(1, 15)
|
los = random.randint(1, 15)
|
||||||
pom = 'wozek.png'
|
pom = 'wozek.png'
|
||||||
if pom != None:
|
if pom != None:
|
||||||
x, y = random.randint(0, SZEROKOSC_OKNA - BOK_AGENTA1), random.randint(0, WYSOKOSC_OKNA - BOK_AGENTA1)
|
x, y = random.randint(0, SZEROKOSC_OKNA - BOK_AGENTA1), random.randint(0, WYSOKOSC_OKNA - BOK_AGENTA1)
|
||||||
hitbox = pygame.Rect(x, y, BOK_AGENTA1, BOK_AGENTA1)
|
hitbox = pygame.Rect(x, y, BOK_AGENTA1, BOK_AGENTA1)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
klatkaz = pygame.time.Clock()
|
klatkaz = pygame.time.Clock()
|
||||||
warunek_dzialania = True
|
warunek_dzialania = True
|
||||||
while warunek_dzialania:
|
while warunek_dzialania:
|
||||||
klatkaz.tick(FPS)
|
klatkaz.tick(FPS)
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
warunek_dzialania = False
|
warunek_dzialania = False
|
||||||
break
|
break
|
||||||
wyswietl_okno()
|
wyswietl_okno()
|
||||||
dodaj_agenta1()
|
dodaj_agenta1()
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
Loading…
Reference in New Issue
Block a user