Added move coounter

This commit is contained in:
Magdalena Wilczyńska 2019-05-12 10:24:43 +02:00
parent 05eaa8f396
commit ae270bc833
2 changed files with 19 additions and 0 deletions

View File

@ -8,6 +8,8 @@ from config import GRID_WIDTH, GRID_HEIGHT
class GC(Cell):
moves_made = 0
def __init__(self, x, y, max_rubbish, yellow=0, green=0, blue=0):
Cell.__init__(self, x, y, max_rubbish, yellow, green, blue)
@ -23,6 +25,7 @@ class GC(Cell):
def move(self, direction, environment):
self.x, self.y = self.movement(environment)[0][direction]
self.update_rect(self.x, self.y)
self.moves_made = self.moves_made + 1
print(self.check_moves(direction, environment))
@ -42,3 +45,6 @@ class GC(Cell):
item.return_trash(self)
self.update_image()
def get_moves_made(self):
return self.moves_made

13
main.py
View File

@ -5,12 +5,16 @@ import sys
from random import randint
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y
from PIL import Image,ImageDraw
from DataModels.Grass import Grass
from DataModels.House import House
from DataModels.Dump import Dump
from DataModels.Road import Road
from DataModels.GC import GC
pygame.init()
pygame_sprites = pygame.sprite.Group()
FPS_CLOCK = pygame.time.Clock()
@ -93,5 +97,14 @@ while True:
pygame_sprites.update()
pygame_sprites.draw(GAME_WINDOW)
#draw GC moves
bg_rect = pygame.Surface((105,30), pygame.SRCALPHA) # per-pixel alpha
bg_rect.fill((0,0,0,160)) # notice the alpha value in the color
GAME_WINDOW.blit(bg_rect, (0, WINDOW_HEIGHT-30))
font = pygame.font.SysFont("monospace", 15)
gc_moves = font.render("Moves: " + str(gc.get_moves_made()), 1, (255,255,255))
GAME_WINDOW.blit(gc_moves, (10, WINDOW_HEIGHT - 25))
pygame.display.flip()
FPS_CLOCK.tick(FPS)