-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation_test.py
83 lines (55 loc) · 1.71 KB
/
animation_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 time
from tiles_skeleton import SupermarketMap, MARKET
import os
import numpy as np
import cv2
import random
dir = os.path.dirname(os.path.realpath(__file__))
tiles = cv2.imread(f"{dir}/tiles.png")
TILE_SIZE = 32
class Customer:
def __init__(self, supermarket, avatar, row=5, col=5):
"""
supermarket: A SuperMarketMap object
avatar : a numpy array containing a 32x32 tile image
row: the starting row
col: the starting column
"""
self.supermarket = supermarket
self.avatar = avatar
self.row = row
self.col = col
def draw(self, frame):
y = self.row * TILE_SIZE
x = self.col * TILE_SIZE
one = y + self.avatar.shape[0]
two = x + self.avatar.shape[1]
frame[y:one, x:two] = self.avatar
return frame
def move(self, direction):
new_row = self.row
new_col = self.col
if direction == 'up':
new_row -= 1
if self.supermarket.contents[new_row][new_col] == '.':
self.col = new_col
self.row = new_row
# Do tests here
supermarket = SupermarketMap(MARKET, tiles)
get_avatar_id = str(random.randint(1,12))
print('get_avatar_id', get_avatar_id)
customer = Customer(supermarket, supermarket.get_tile(get_avatar_id), 8, 10)
background = np.zeros((500, 700, 3), np.uint8)
while True:
frame = background.copy()
frame = supermarket.draw(frame)
frame = customer.draw(frame)
# https://www.ascii-code.com/
key = cv2.waitKey(1)
if key == 113: # 'q' key
break
customer.move('up')
cv2.imshow("frame", frame)
time.sleep(1)
cv2.destroyAllWindows()
supermarket.write_image("supermarket.png")