From 5f20bf55529668f58212bff033882036ecc4bc1a Mon Sep 17 00:00:00 2001 From: Giovani Date: Thu, 3 Jun 2021 15:11:37 -0400 Subject: [PATCH] feat: add logic that allows piece to move --- config.yaml | 2 +- entity/Piece.py | 10 ++++++++-- main.py | 12 +++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/config.yaml b/config.yaml index 5e58eac..c09bfd7 100644 --- a/config.yaml +++ b/config.yaml @@ -8,7 +8,7 @@ engine: fps: 60 tile-size: 20 -# https://coolors.co/6495ed-ee6352-59cd90-fac05e-f79d84 +# https://coolors.co/6495ed-ee6352-59cd90-fac05e-dfd9e2 # TODO change config color names, should be generic color: cornflower-blue: "#6495ED" diff --git a/entity/Piece.py b/entity/Piece.py index f7abd2f..a95adac 100644 --- a/entity/Piece.py +++ b/entity/Piece.py @@ -35,9 +35,15 @@ class Piece: for sub_points in self.points: pygame.draw.polygon(surface, base_color, sub_points, 0) pygame.draw.polygon(surface, border_color, sub_points, max(tile_size // 6, 1)) - + + def move(self, vector): + for sub_points in self.points: + for point in sub_points: + point[0] += vector[0] + point[1] += vector[1] + # rotate the piece clockwise - def rotate(): + def rotate(self): pass # shape attributes diff --git a/main.py b/main.py index 261d212..4e323fc 100644 --- a/main.py +++ b/main.py @@ -3,15 +3,17 @@ import pygame from entity.Piece import Piece from util.ConfigurationManager import ConfigurationManager -def draw(screen): +def draw(screen, obj): # draw window bg bg_color = pygame.Color(ConfigurationManager.configuration["color"]["cornflower-blue"]) screen.fill(bg_color) fire_opal = ConfigurationManager.configuration["color"]["fire-opal"] - i_piece = Piece(Piece.I_SHAPE, (100, 100), fire_opal) - i_piece.draw(screen) + if not "i_piece" in obj: + obj["i_piece"] = Piece(Piece.I_SHAPE, (100, 100), fire_opal) + obj["i_piece"].move((1, 1)) + obj["i_piece"].draw(screen) # update display pygame.display.update() @@ -33,16 +35,16 @@ def main(): pygame.display.set_caption(win_title) pygame.display.set_icon(loaded_icon) + obj = { } is_running = True while is_running: clock.tick(fps) for event in pygame.event.get(): - if event.type == pygame.QUIT: is_running = False - draw(screen) + draw(screen, obj) pygame.quit()