2020-05-03 16:59:29 +02:00
|
|
|
import pygame
|
2020-05-18 22:05:58 +02:00
|
|
|
import random
|
2020-05-03 16:59:29 +02:00
|
|
|
class game_ui():
|
|
|
|
|
|
|
|
def __init__(self,traktor,field):
|
|
|
|
self.traktor = traktor
|
|
|
|
self.field = field
|
|
|
|
self.window_name = "SI_Projekt"
|
|
|
|
self.szer = 850
|
|
|
|
self.wys = 1000
|
|
|
|
self.col =(0,255,0)
|
|
|
|
self.POLE_SZER = 700
|
|
|
|
self.POLE_WYS = 700
|
|
|
|
self.POLE_COL = (128, 128, 0)
|
|
|
|
self.POLE_POZ = (75, 75)
|
|
|
|
self.text_rect = [self.POLE_POZ[0], self.POLE_WYS + self.POLE_POZ[1] + 100]
|
2020-06-04 18:56:18 +02:00
|
|
|
self.pogoda_rect = [self.POLE_POZ[0], self.POLE_WYS + self.POLE_POZ[1] + 125]
|
|
|
|
self.text_weather = "Pogoda: "+self.field.get_pogoda_name()
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
# Init pola gry
|
|
|
|
self.okno = pygame.display.set_mode((self.szer, self.wys), 0, 32)
|
|
|
|
|
|
|
|
# Tytuł okna
|
|
|
|
pygame.display.set_caption(self.window_name)
|
|
|
|
|
|
|
|
# Tworzenie powierzchni pola
|
|
|
|
self.pole_surf = pygame.Surface([self.POLE_SZER, self.POLE_WYS])
|
|
|
|
self.pole_surf.fill(self.POLE_COL)
|
|
|
|
self.pole_surf_rect = self.pole_surf.get_rect()
|
|
|
|
self.pole_surf_rect.x = self.POLE_POZ[0]
|
|
|
|
self.pole_surf_rect.y = self.POLE_POZ[1]
|
|
|
|
self.pole1_surf = pygame.Surface([self.POLE_SZER + 150, self.POLE_WYS + 150])
|
|
|
|
self.pole1_surf.fill((0, 0, 0))
|
|
|
|
self.pole1_surf_rect = self.pole_surf.get_rect()
|
|
|
|
self.pole1_surf_rect.x = self.POLE_POZ[0] - 75
|
|
|
|
self.pole1_surf_rect.y = self.POLE_POZ[1] - 75
|
|
|
|
self.traktor_img = ["traktor_d.png", "traktor_l.png", "traktor_u.png", "traktor_r.png"]
|
|
|
|
self.field_images = []
|
2020-05-18 22:05:58 +02:00
|
|
|
# self.field_images_path = []
|
|
|
|
# self.random = random.randint(0,99)
|
|
|
|
for i in ['gleba_pix','gleba_chwasty_pix','sadzonka_suchi_pix','sadzonka_chwasty_pix','gleba_mokra_pix','gleba_mokra_chwasty','sadzonka_mokra_pix','sadzonka_mokra_chwasty_pix','gotowy_burak_pix']:
|
|
|
|
# self.field_images_path.append("images/"+i+"/"+i+str(self.random)+".png")
|
|
|
|
self.field_images.append(pygame.image.load("images/"+i+".png"))
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
# Zezwalamy na przechwytywanie klawiszy
|
|
|
|
pygame.event.pump()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
# kolor okna
|
|
|
|
self.okno.fill(self.col)
|
|
|
|
# wstawienie pola
|
|
|
|
self.okno.blit(self.pole1_surf, self.pole1_surf_rect)
|
|
|
|
self.okno.blit(self.pole_surf, self.pole_surf_rect)
|
|
|
|
self.text_value = "Ile ruchów: " + str(self.traktor.get_moves()) + " Tryb: " + self.traktor.get_mode_name()
|
2020-06-04 18:56:18 +02:00
|
|
|
|
2020-05-03 16:59:29 +02:00
|
|
|
self.font = pygame.font.Font('freesansbold.ttf', 24)
|
|
|
|
self.text = self.font.render(self.text_value, True, (0, 0, 0), self.col)
|
2020-06-04 18:56:18 +02:00
|
|
|
self.text_pogoda = self.font.render(self.text_weather, True,(0, 0, 0), self.col)
|
2020-05-03 16:59:29 +02:00
|
|
|
self.okno.blit(self.text, self.text_rect)
|
2020-06-04 18:56:18 +02:00
|
|
|
self.okno.blit(self.text_pogoda, self.pogoda_rect)
|
2020-05-03 16:59:29 +02:00
|
|
|
for i in range(0, 10):
|
|
|
|
for j in range(0, 10):
|
|
|
|
self.pole_surf.blit(self.field_images[self.field.get_value([i,j])], (i*70, j*70))
|
|
|
|
self.traktor_actual_img = pygame.image.load('images/' + self.traktor_img[self.traktor.get_turn()])
|
|
|
|
self.okno.blit(self.traktor_actual_img,self.traktor.get_poz_on_screen())
|
|
|
|
# aktualizacja okna i wyświetlenie
|
|
|
|
pygame.display.update()
|