-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsprite.py
More file actions
29 lines (23 loc) · 771 Bytes
/
Copy pathsprite.py
File metadata and controls
29 lines (23 loc) · 771 Bytes
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
import curses
class Sprite:
def __init__(self, y, x, id, content):
self.y = y
self.x = x
self.id = id
self.content = content
self.background = []
def save_background(self, win):
self.background = [win.inch(self.y, self.x + i) for i in range(len(self.content))]
def restore_background(self, win):
for i, char in enumerate(self.background):
win.addch(self.y, self.x + i, char)
def draw(self, win):
self.save_background(win)
win.addstr(self.y, self.x, self.content, curses.A_REVERSE)
def delete(self, win):
self.restore_background(win)
def move_to(self, win, y, x):
self.delete(win)
self.y = y
self.x = x
self.draw(win)