-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprites.py
75 lines (53 loc) · 1.75 KB
/
sprites.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
import tkinter as tk
import pyautogui
from typing import List
class Sprite:
frames: List[tk.PhotoImage]
frame_count: int
image_path: str
image_width: int
image_height: int
x: int
y: int
vx: int
vy: int
offset_x: int
offset_y: int
def __init__(self, image_path: str, image_width: int, image_height: int, frame_count: int, x: int, y: int, vx: int, vy: int, offset_x: int, offset_y: int):
self.frame_count = frame_count
self.image_path = image_path
self.frames = [tk.PhotoImage(file=image_path, format = 'gif -index %i' %(i)) for i in range(frame_count)]
self.image_width = image_width
self.image_height = image_height
self.x = x
self.y = y
self.vx = vx
self.vy = vy
self.offset_x = offset_x
self.offset_y = offset_y
def update_sprite_constant(self):
self.x += self.vx
self.y += self.vy
def update_sprite_to_mouse(self):
mouse_position = pyautogui.position()
self.x = int(mouse_position.x - self.offset_x)
self.y = int(mouse_position.y - self.offset_y)
def get_geometry(self):
return f'{self.image_resolution}+{self.x}+{self.y}'
def set_x(self, x: int):
self.x = x
def set_y(self, y: int):
self.y = y
def set_vx(self, vx: int):
self.vx = vx
def set_vy(self, vy: int):
self.vy = vy
def set_offset_x(self, offset_x):
self.offset_x = offset_x
def set_offset_y(self, offset_y):
self.offset_y = offset_y
def set_sprite(self,file_path):
self.image_path = file_path
@property
def image_resolution(self):
return f'{self.image_width}x{self.image_height}'