-
Notifications
You must be signed in to change notification settings - Fork 0
/
path-test.py
83 lines (68 loc) · 3.24 KB
/
path-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import pygame, sys
import eventparser as ep
import env.overworld as overworld
import pyconsole
from colors import *
from pygame.locals import *
from actions import *
def main():
pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
CLOCK = pygame.time.Clock()
pygame.display.set_caption("PATH TEST")
environment = overworld.Overworld('tests/maps/test.tmx', debug=True)
console = pyconsole.Console(DISPLAYSURF, (0,0,400,100))
actions = []
while True:
mouse_pos = list(pygame.mouse.get_pos())
environment.debug_update(DISPLAYSURF, actions, mouse_pos)
console.process_input()
console.draw()
pygame.display.flip()
actions = ep.parse_keymap(pygame.key.get_pressed())
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
#toggle grid settings
if event.key == K_1:
environment.grid.toggle_grid()
elif event.key == K_2:
environment.grid.toggle_lines()
elif event.key == K_3:
environment.grid.toggle_cells()
#temporary -- set goal for pathfinding
elif event.key == K_k:
current_cell = environment.grid.get_cell_at_grid_index(environment.goal)
goal = list(environment.goal)
goal[0] -= 1
environment.goal = tuple(goal)
environment.grid.set_cell_value(current_cell, current_cell.last_value)
environment.grid.set_cell_value(environment.grid.get_cell_at_grid_index(goal), 2)
elif event.key == K_j:
current_cell = environment.grid.get_cell_at_grid_index(environment.goal)
goal = list(environment.goal)
goal[0] += 1
environment.goal = tuple(goal)
environment.grid.set_cell_value(current_cell, current_cell.last_value)
environment.grid.set_cell_value(environment.grid.get_cell_at_grid_index(goal), 2)
elif event.key == K_h:
current_cell = environment.grid.get_cell_at_grid_index(environment.goal)
goal = list(environment.goal)
goal[1] -= 1
environment.goal = tuple(goal)
environment.grid.set_cell_value(current_cell, current_cell.last_value)
environment.grid.set_cell_value(environment.grid.get_cell_at_grid_index(goal), 2)
elif event.key == K_l:
current_cell = environment.grid.get_cell_at_grid_index(environment.goal)
goal = list(environment.goal)
goal[1] += 1
environment.goal = tuple(goal)
environment.grid.set_cell_value(current_cell, current_cell.last_value)
environment.grid.set_cell_value(environment.grid.get_cell_at_grid_index(goal), 2)
elif event.key == K_SPACE:
environment.handler.move_to(environment.goal)
CLOCK.tick(30)
if __name__ == "__main__":
main()