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
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"

View File

@@ -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

12
main.py
View File

@@ -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()