59 lines
2.6 KiB
Python
59 lines
2.6 KiB
Python
import pygame
|
|
|
|
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]
|
|
|
|
# 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 = []
|
|
for i in ['gleba_pix.png','gleba_chwasty_pix.png','sadzonka_suchi_pix.png','sadzonka_chwasty_pix.png','gleba_mokra_pix.png','gleba_mokra_chwasty.png','sadzonka_mokra_pix.png','sadzonka_mokra_chwasty_pix.png','gotowy_burak_pix.png']:
|
|
self.field_images.append(pygame.image.load('images/'+i))
|
|
|
|
# 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()
|
|
self.font = pygame.font.Font('freesansbold.ttf', 24)
|
|
self.text = self.font.render(self.text_value, True, (0, 0, 0), self.col)
|
|
self.okno.blit(self.text, self.text_rect)
|
|
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() |