feat: add ability to move piece with arrow keys
This commit is contained in:
29
main.py
29
main.py
@@ -3,17 +3,14 @@ import pygame
|
||||
from entity.Piece import Piece
|
||||
from util.ConfigurationManager import ConfigurationManager
|
||||
|
||||
def draw(screen, obj):
|
||||
def draw(screen, objects):
|
||||
# draw window bg
|
||||
bg_color = pygame.Color(ConfigurationManager.configuration["color"]["cornflower-blue"])
|
||||
bg_color = pygame.Color(ConfigurationManager.configuration["window"]["bg-color"])
|
||||
screen.fill(bg_color)
|
||||
|
||||
fire_opal = ConfigurationManager.configuration["color"]["fire-opal"]
|
||||
|
||||
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)
|
||||
# draw all game objects
|
||||
for object in objects:
|
||||
object.draw(screen)
|
||||
|
||||
# update display
|
||||
pygame.display.update()
|
||||
@@ -35,7 +32,9 @@ def main():
|
||||
pygame.display.set_caption(win_title)
|
||||
pygame.display.set_icon(loaded_icon)
|
||||
|
||||
obj = { }
|
||||
base_one_color = ConfigurationManager.configuration["color"]["base-1"]
|
||||
i_piece = Piece(Piece.I_SHAPE, (100, 100), base_one_color)
|
||||
|
||||
is_running = True
|
||||
while is_running:
|
||||
clock.tick(fps)
|
||||
@@ -43,8 +42,18 @@ def main():
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
is_running = False
|
||||
|
||||
keys = pygame.key.get_pressed()
|
||||
if keys[pygame.K_LEFT]:
|
||||
i_piece.move((-5, 0))
|
||||
if keys[pygame.K_RIGHT]:
|
||||
i_piece.move((5, 0))
|
||||
if keys[pygame.K_UP]:
|
||||
i_piece.move((0, -5))
|
||||
if keys[pygame.K_DOWN]:
|
||||
i_piece.move((0, 5))
|
||||
|
||||
draw(screen, obj)
|
||||
draw(screen, [i_piece])
|
||||
|
||||
pygame.quit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user