-
Notifications
You must be signed in to change notification settings - Fork 18
/
game.py
130 lines (105 loc) · 3.33 KB
/
game.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import pygame
import time
import random
from settings import Settings
canvas = pygame.display.set_mode((Settings.width, Settings.height))
done = False
class Foot(pygame.sprite.Sprite):
def __init__(self, canvas, side):
super().__init__()
# self.positive_image = pygame.image.load(f'images/{positive_name}')
# self.negative_image = pygame.image.load(f'images/{negative_name}')
self.canvas = canvas
# self.state = 1
# self.step = 'heel'
# self.side = side
# orientation = 0
# self.location = (10, 10)
# moves = ['flat', 'heel']
#
# feet = {'flat': {}, 'heel': {}}
# for foot in ['l', 'r']:
# for move in moves:
# feet[move][foot] = Foot(f'{move}-white-{foot}.png', f'{move}-black-{foot}.png')
image = pygame.image.load(f'images/flat-white-{side}.png')
self.image = pygame.transform.scale(image, (45, 100))
self.rect = self.image.get_rect()
self.rect.move_ip(300, 300)
def move(self, x, y):
self.rect.move_ip(x, y)
# def set_orientation(self):
def draw(self):
canvas.blit(self.image, self.rect)
# if self.state:
# canvas.blit(self.positive_image)
# else:
# canvas.blit(self.negative_image)
# dance = [
# 'p',
# 'l up 2',
# 'p',
# 'r up 2',
# 'r right 1.5',
# 'p'
# ]
with open('dance.txt') as input_file:
dance = input_file.readlines()
left_foot = Foot(canvas, 'l')
right_foot = Foot(canvas, 'r')
right_foot.move(50, 0)
all_feet = [left_foot, right_foot]
def draw_feet():
for foot in all_feet:
foot.draw()
def draw(canvas):
canvas.fill((0, 0, 0))
draw_feet()
pygame.display.flip()
while True:
for line in dance * 2:
if line.startswith('p'):
draw(canvas)
time.sleep(0.666)
else:
assert line[0] in ['l', 'r']
parts = line.split()
foot = {'l': left_foot, 'r': right_foot}[parts[0]]
distance = {'up': (0, -1), 'left': (-1, 0), 'right': (1, 0), 'down': (0, 1)}[parts[1]]
m = Settings.multiplier * float(parts[2])
distance = (int(distance[0] * m), int(distance[1] * m))
foot.move(*distance)
random.shuffle(dance)
# while not done:
# for event in pygame.event.get():
# if event.type == pygame.QUIT:
# done = True
#
#
#
# # elif event.type == MY_EVENT:
# # game_counter.increase()
# #
# # elif event.type == pygame.MOUSEBUTTONDOWN:
# # event_log.add(f'Mouse button down')
# #
# # elif event.type == pygame.MOUSEBUTTONUP:
# # event_log.add('Mouse button up')
# #
# # elif event.type == pygame.KEYDOWN:
# # event_log.add('Key down')
# #
# # elif event.type == pygame.KEYUP:
# # event_log.add('Key up')
# #
# # if event.key == pygame.K_LEFT:
# # event_log.add(' Left arrow')
# # elif event.key == pygame.K_RIGHT:
# # event_log.add(' Right arrow')
# # else:
# # event_log.add(f' {event.key}')
# # canvas.fill((0, 0, 0))
# # game_counter.draw()
# # show_status(canvas)
# # event_log.draw()
# draw()
# pygame.display.flip()