poruszanie sie fix
dodanie poruszania sie tylko po okreslonych polach
This commit is contained in:
parent
8a79b45b91
commit
1ed782d5de
14
board
14
board
@ -41,16 +41,16 @@ def draw(square_num, objectArr):
|
||||
radius = 10
|
||||
pygame.draw.circle(screen, agent_color, (a + circleX, b + circleY), radius)
|
||||
|
||||
def kb_listen(objectArray):
|
||||
def kb_listen(objectArray, gridLength):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_LEFT:
|
||||
if event.key == pygame.K_LEFT and objectArray[0].xPos > 0:
|
||||
objectArray[0].xPos = objectArray[0].xPos - 1
|
||||
if event.key == pygame.K_RIGHT:
|
||||
if event.key == pygame.K_RIGHT and objectArray[0].xPos < gridLength - 1:
|
||||
objectArray[0].xPos = objectArray[0].xPos + 1
|
||||
if event.key == pygame.K_UP:
|
||||
if event.key == pygame.K_UP and objectArray[0].yPos > 1:
|
||||
objectArray[0].yPos = objectArray[0].yPos - 1
|
||||
if event.key == pygame.K_DOWN:
|
||||
if event.key == pygame.K_DOWN and objectArray[0].yPos < gridLength:
|
||||
objectArray[0].yPos = objectArray[0].yPos + 1
|
||||
if event.type == pygame.QUIT:
|
||||
sys.exit()
|
||||
@ -70,6 +70,6 @@ if __name__ == '__main__':
|
||||
while 1:
|
||||
c = (255, 255, 255) #tymczasowy kolor tła - do usunięcia, jak już będzie zdjęcie
|
||||
screen.fill(c)
|
||||
draw(10, objectArray)
|
||||
kb_listen(objectArray)
|
||||
draw(15, objectArray)
|
||||
kb_listen(objectArray, 15)
|
||||
pygame.display.update() #by krata pojawiła się w okienku - update powierzchni
|
Loading…
Reference in New Issue
Block a user