-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimations.py
161 lines (130 loc) · 5.41 KB
/
animations.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import enum
from enum import auto
import os
import pygame
import random
import animation
import locations
_surfaces = {}
class Surfaces(enum.Enum):
VIM = auto()
ATOM = auto()
EMACS = auto()
INTELLIJ = auto()
NANO = auto()
VSCODE = auto()
RANDOM = auto()
BUG_RED_1 = auto()
BUG_RED_2 = auto()
BUG_GREEN_1 = auto()
BUG_GREEN_2 = auto()
BUG_YELLOW_1 = auto()
BUG_YELLOW_2 = auto()
BUG_GRAY_1 = auto()
BUG_GRAY_2 = auto()
TRY_EXCEPT = auto()
CATCH_EXCEPTION = auto()
FLOATINGPOINTERROR = auto()
INDEXERROR = auto()
KEYERROR = auto()
MEMORYERROR = auto()
NOTIMPLEMENTEDERROR = auto()
OVERFLOWERROR = auto()
RECURSIONERROR = auto()
RUNTIMEERROR = auto()
TYPEERROR = auto()
FIBONACCI = auto()
FOR_I_IN_RANGE = auto()
FOR_ITEM_IN_ITEMS = auto()
IMPORT_PYGAME = auto()
PRINT_HELLO_WORLD = auto()
REVERSE = auto()
SQR_LAMBDA = auto()
STR_JOIN = auto()
XY_POINT = auto()
COFFEE = auto()
COFFEE_BROKEN = auto()
EXPLOSION = auto()
EFFECT = auto()
def get_filename(self):
if self == Surfaces.VIM: fn = 'vim.png'
elif self == Surfaces.ATOM: fn = 'atom.png'
elif self == Surfaces.EMACS: fn = 'emacs.png'
elif self == Surfaces.INTELLIJ: fn = 'intellij.png'
elif self == Surfaces.NANO: fn = 'nano.png'
elif self == Surfaces.VSCODE: fn = 'vscode.png'
elif self == Surfaces.RANDOM: fn = 'random-editor.png'
elif self == Surfaces.BUG_RED_1: fn = 'bug-red-1.png'
elif self == Surfaces.BUG_RED_2: fn = 'bug-red-2.png'
elif self == Surfaces.BUG_GREEN_1: fn = 'bug-green-1.png'
elif self == Surfaces.BUG_GREEN_2: fn = 'bug-green-2.png'
elif self == Surfaces.BUG_YELLOW_1: fn = 'bug-yellow-1.png'
elif self == Surfaces.BUG_YELLOW_2: fn = 'bug-yellow-2.png'
elif self == Surfaces.BUG_GRAY_1: fn = 'bug-gray-1.png'
elif self == Surfaces.BUG_GRAY_2: fn = 'bug-gray-2.png'
elif self == Surfaces.TRY_EXCEPT: fn = 'try-except.png'
elif self == Surfaces.CATCH_EXCEPTION: fn = 'catch-exception.png'
elif self == Surfaces.FLOATINGPOINTERROR: fn = 'floatingpointerror.png'
elif self == Surfaces.INDEXERROR: fn = 'indexerror.png'
elif self == Surfaces.KEYERROR: fn = 'keyerror.png'
elif self == Surfaces.MEMORYERROR: fn = 'memoryerror.png'
elif self == Surfaces.NOTIMPLEMENTEDERROR: fn = 'notimplementederror.png'
elif self == Surfaces.OVERFLOWERROR: fn = 'overflowerror.png'
elif self == Surfaces.RECURSIONERROR: fn = 'recursionerror.png'
elif self == Surfaces.RUNTIMEERROR: fn = 'runtimeerror.png'
elif self == Surfaces.TYPEERROR: fn = 'typeerror.png'
elif self == Surfaces.FIBONACCI: fn = 'fibonacci.png'
elif self == Surfaces.FOR_I_IN_RANGE: fn = 'for-i-in-range.png'
elif self == Surfaces.FOR_ITEM_IN_ITEMS: fn = 'for-item-in-items.png'
elif self == Surfaces.IMPORT_PYGAME: fn = 'import-pygame.png'
elif self == Surfaces.PRINT_HELLO_WORLD: fn = 'print-hello-world.png'
elif self == Surfaces.REVERSE: fn = 'reverse.png'
elif self == Surfaces.SQR_LAMBDA: fn = 'sqr-lambda.png'
elif self == Surfaces.STR_JOIN: fn = 'str-join.png'
elif self == Surfaces.XY_POINT: fn = 'xy-point.png'
elif self == Surfaces.COFFEE: fn = 'coffee.png'
elif self == Surfaces.COFFEE_BROKEN: fn = 'coffee-broken.png'
elif self == Surfaces.EXPLOSION: fn = 'bug-explode.png'
elif self == Surfaces.EFFECT: fn = 'effect.png'
else: raise Exception('Unknown Surface Type: {}'.format(str(self)))
return locations.image(fn)
def get_surface(self):
global _surfaces
if self in _surfaces:
return _surfaces[self]
surface = pygame.image.load(self.get_filename()).convert_alpha()
_surfaces[self] = surface
return surface
class Player(animation.Animation):
def __init__(self, player_type: Surfaces):
super().__init__(player_type.get_surface(), 1, 1, True)
class RandomEditor(animation.Animation):
def __init__(self):
super().__init__(Surfaces.RANDOM.get_surface(), 6, 6, False)
class Bug(animation.Animation):
def __init__(self, bug_type: Surfaces):
super().__init__(bug_type.get_surface(), 3, 8, False)
class TryExcept(animation.Animation):
def __init__(self):
super().__init__(Surfaces.TRY_EXCEPT.get_surface(), 1, 1, True)
class CatchException(animation.Animation):
def __init__(self):
super().__init__(Surfaces.CATCH_EXCEPTION.get_surface(), 8, 8, True)
class Snippet(animation.Animation):
def __init__(self, snippet_type: Surfaces):
super().__init__(snippet_type.get_surface(), 1, 1, True)
class Error(animation.Animation):
def __init__(self, error_type: Surfaces):
super().__init__(error_type.get_surface(), 1, 1, True)
class Coffee(animation.Animation):
def __init__(self):
super().__init__(Surfaces.COFFEE.get_surface(), 5, 6, False)
class CoffeeBroken(animation.Animation):
def __init__(self):
super().__init__(Surfaces.COFFEE_BROKEN.get_surface(), 1, 1, True)
class Explosion(animation.Animation):
def __init__(self):
super().__init__(Surfaces.EXPLOSION.get_surface(), 5, 8, True)
class Effect(animation.Animation):
def __init__(self):
super().__init__(Surfaces.EFFECT.get_surface(), 5, 6, False)