-
Notifications
You must be signed in to change notification settings - Fork 0
/
dancing_stick_figure.py
60 lines (45 loc) · 1.5 KB
/
dancing_stick_figure.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
import pygame
from pygame.locals import *
print("""
DIRECTIONS:
PRESS LEFT ARROW AND RIGHT ARROW TO DANCE
""")
pygame.init()
screen = pygame.display.set_mode((400, 400), 0, 32)
pygame.display.set_caption('dancing stick figure')
left_arm_y2 = 175
right_arm_y2 = 175
def toggleLeftArm():
global left_arm_y2
# Move the left arm down if it is currently up, and up if it is currently down.
if (left_arm_y2 == 125):
left_arm_y2 = 175
else:
left_arm_y2 = 125
def toggleRightArm():
global right_arm_y2
# Move the right arm down if it is currently up, and up if it is currently down.
if (right_arm_y2 == 125):
right_arm_y2 = 175
else:
right_arm_y2 = 125
while True:
screen.fill((173, 216, 230))
# face and body
pygame.draw.circle(screen, (0, 0, 0), (200, 135), 25)
pygame.draw.line(screen, (0, 0, 0), (200, 160), (200, 240))
# upper arms
pygame.draw.line(screen, (0, 0, 0), (200, 185), (150, left_arm_y2))
pygame.draw.line(screen, (0, 0, 0), (200, 185), (250, right_arm_y2))
# legs
pygame.draw.line(screen, (0, 0, 0), (200, 240), (230, 300))
pygame.draw.line(screen, (0, 0, 0), (200, 240), (170, 300))
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
if event.type == KEYDOWN:
if event.key == K_LEFT:
toggleLeftArm()
elif event.key == K_RIGHT:
toggleRightArm()
pygame.display.update()