feat: add logic that allows piece to move

This commit is contained in:
2021-06-03 15:11:37 -04:00
parent 9b48f3b347
commit 5f20bf5552
3 changed files with 16 additions and 8 deletions

View File

@@ -8,7 +8,7 @@ engine:
fps: 60 fps: 60
tile-size: 20 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 # TODO change config color names, should be generic
color: color:
cornflower-blue: "#6495ED" cornflower-blue: "#6495ED"

View File

@@ -35,9 +35,15 @@ class Piece:
for sub_points in self.points: for sub_points in self.points:
pygame.draw.polygon(surface, base_color, sub_points, 0) pygame.draw.polygon(surface, base_color, sub_points, 0)
pygame.draw.polygon(surface, border_color, sub_points, max(tile_size // 6, 1)) 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 # rotate the piece clockwise
def rotate(): def rotate(self):
pass pass
# shape attributes # shape attributes

12
main.py
View File

@@ -3,15 +3,17 @@ import pygame
from entity.Piece import Piece from entity.Piece import Piece
from util.ConfigurationManager import ConfigurationManager from util.ConfigurationManager import ConfigurationManager
def draw(screen): def draw(screen, obj):
# draw window bg # draw window bg
bg_color = pygame.Color(ConfigurationManager.configuration["color"]["cornflower-blue"]) bg_color = pygame.Color(ConfigurationManager.configuration["color"]["cornflower-blue"])
screen.fill(bg_color) screen.fill(bg_color)
fire_opal = ConfigurationManager.configuration["color"]["fire-opal"] fire_opal = ConfigurationManager.configuration["color"]["fire-opal"]
i_piece = Piece(Piece.I_SHAPE, (100, 100), fire_opal) if not "i_piece" in obj:
i_piece.draw(screen) obj["i_piece"] = Piece(Piece.I_SHAPE, (100, 100), fire_opal)
obj["i_piece"].move((1, 1))
obj["i_piece"].draw(screen)
# update display # update display
pygame.display.update() pygame.display.update()
@@ -33,16 +35,16 @@ def main():
pygame.display.set_caption(win_title) pygame.display.set_caption(win_title)
pygame.display.set_icon(loaded_icon) pygame.display.set_icon(loaded_icon)
obj = { }
is_running = True is_running = True
while is_running: while is_running:
clock.tick(fps) clock.tick(fps)
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
is_running = False is_running = False
draw(screen) draw(screen, obj)
pygame.quit() pygame.quit()