crystalwindow 3.8.1__py3-none-any.whl → 3.8.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crystalwindow/sprites.py +56 -63
- {crystalwindow-3.8.1.dist-info → crystalwindow-3.8.3.dist-info}/METADATA +1 -1
- {crystalwindow-3.8.1.dist-info → crystalwindow-3.8.3.dist-info}/RECORD +6 -6
- {crystalwindow-3.8.1.dist-info → crystalwindow-3.8.3.dist-info}/WHEEL +0 -0
- {crystalwindow-3.8.1.dist-info → crystalwindow-3.8.3.dist-info}/licenses/LICENSE +0 -0
- {crystalwindow-3.8.1.dist-info → crystalwindow-3.8.3.dist-info}/top_level.txt +0 -0
crystalwindow/sprites.py
CHANGED
|
@@ -1,44 +1,55 @@
|
|
|
1
1
|
# sprites.py
|
|
2
|
+
import random
|
|
2
3
|
from tkinter import PhotoImage
|
|
3
|
-
from PIL import Image, ImageTk
|
|
4
4
|
|
|
5
|
+
try:
|
|
6
|
+
from PIL import Image, ImageTk
|
|
7
|
+
except ImportError:
|
|
8
|
+
Image = None
|
|
9
|
+
ImageTk = None
|
|
5
10
|
|
|
6
11
|
class Sprite:
|
|
7
12
|
def __init__(self, pos, size=None, image=None, color=(255, 0, 0)):
|
|
8
|
-
|
|
13
|
+
"""
|
|
14
|
+
pos: (x, y)
|
|
15
|
+
size: (w, h) optional
|
|
16
|
+
image: PhotoImage or PIL ImageTk.PhotoImage
|
|
17
|
+
color: fallback rectangle color
|
|
18
|
+
"""
|
|
9
19
|
self.pos = pos
|
|
10
|
-
|
|
11
|
-
self.image =
|
|
20
|
+
self.x, self.y = pos
|
|
21
|
+
self.image = image
|
|
12
22
|
self.color = color
|
|
13
23
|
|
|
14
|
-
#
|
|
15
|
-
if
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
# Determine width/height
|
|
25
|
+
if image is not None:
|
|
26
|
+
try:
|
|
27
|
+
# Tkinter PhotoImage
|
|
28
|
+
self.width = image.width()
|
|
29
|
+
self.height = image.height()
|
|
30
|
+
except Exception:
|
|
31
|
+
try:
|
|
32
|
+
# PIL ImageTk.PhotoImage
|
|
33
|
+
self.width = image.width
|
|
34
|
+
self.height = image.height
|
|
35
|
+
except Exception:
|
|
36
|
+
raise ValueError("Sprite image has no size info")
|
|
24
37
|
elif size is not None:
|
|
25
38
|
self.width, self.height = size
|
|
26
|
-
|
|
27
39
|
else:
|
|
28
40
|
raise ValueError("Sprite needs 'size' or 'image'")
|
|
29
41
|
|
|
30
|
-
#
|
|
42
|
+
# Optional velocity
|
|
31
43
|
self.vel_x = 0
|
|
32
44
|
self.vel_y = 0
|
|
33
45
|
|
|
34
|
-
|
|
35
|
-
self.facing_left = False
|
|
36
|
-
|
|
37
|
-
# --------------------------------------
|
|
38
|
-
# Constructors
|
|
39
|
-
# --------------------------------------
|
|
46
|
+
# === CLASS METHODS ===
|
|
40
47
|
@classmethod
|
|
41
48
|
def image(cls, img, pos):
|
|
49
|
+
"""
|
|
50
|
+
Create a sprite from an image.
|
|
51
|
+
Accepts fallback dict or actual PhotoImage.
|
|
52
|
+
"""
|
|
42
53
|
if isinstance(img, dict) and img.get("fallback"):
|
|
43
54
|
w, h = img["size"]
|
|
44
55
|
color = img["color"]
|
|
@@ -47,12 +58,12 @@ class Sprite:
|
|
|
47
58
|
|
|
48
59
|
@classmethod
|
|
49
60
|
def rect(cls, pos, w, h, color=(255, 0, 0)):
|
|
61
|
+
"""Create sprite using a plain colored rectangle"""
|
|
50
62
|
return cls(pos, size=(w, h), color=color)
|
|
51
63
|
|
|
52
|
-
#
|
|
53
|
-
# Draw
|
|
54
|
-
# --------------------------------------
|
|
64
|
+
# === METHODS ===
|
|
55
65
|
def draw(self, win, cam=None):
|
|
66
|
+
"""Draw sprite on CrystalWindow / Tk canvas"""
|
|
56
67
|
if cam:
|
|
57
68
|
draw_x, draw_y = cam.apply(self)
|
|
58
69
|
else:
|
|
@@ -63,9 +74,6 @@ class Sprite:
|
|
|
63
74
|
else:
|
|
64
75
|
win.draw_rect(self.color, (draw_x, draw_y, self.width, self.height))
|
|
65
76
|
|
|
66
|
-
# --------------------------------------
|
|
67
|
-
# Movement
|
|
68
|
-
# --------------------------------------
|
|
69
77
|
def move(self, dx, dy):
|
|
70
78
|
self.x += dx
|
|
71
79
|
self.y += dy
|
|
@@ -76,40 +84,25 @@ class Sprite:
|
|
|
76
84
|
self.y += self.vel_y * dt
|
|
77
85
|
self.pos = (self.x, self.y)
|
|
78
86
|
|
|
79
|
-
# --------------------------------------
|
|
80
|
-
# Image setter
|
|
81
|
-
# --------------------------------------
|
|
82
|
-
def set_image(self, new_image):
|
|
83
|
-
"""Set sprite image and update size."""
|
|
84
|
-
self.image = new_image
|
|
85
|
-
self.width = new_image.width()
|
|
86
|
-
self.height = new_image.height()
|
|
87
|
-
|
|
88
|
-
# --------------------------------------
|
|
89
|
-
# In-place flipping (optional)
|
|
90
|
-
# --------------------------------------
|
|
91
|
-
def flip_horizontal(self):
|
|
92
|
-
if not self.image:
|
|
93
|
-
return
|
|
94
|
-
pil = ImageTk.getimage(self.image)
|
|
95
|
-
flipped = pil.transpose(Image.FLIP_LEFT_RIGHT)
|
|
96
|
-
self.set_image(ImageTk.PhotoImage(flipped))
|
|
97
|
-
self.facing_left = not self.facing_left
|
|
98
|
-
|
|
99
|
-
def flip_vertical(self):
|
|
100
|
-
if not self.image:
|
|
101
|
-
return
|
|
102
|
-
pil = ImageTk.getimage(self.image)
|
|
103
|
-
flipped = pil.transpose(Image.FLIP_TOP_BOTTOM)
|
|
104
|
-
self.set_image(ImageTk.PhotoImage(flipped))
|
|
105
|
-
|
|
106
|
-
# --------------------------------------
|
|
107
|
-
# Collision
|
|
108
|
-
# --------------------------------------
|
|
109
87
|
def colliderect(self, other):
|
|
110
88
|
return (
|
|
111
|
-
self.x < other.x + other
|
|
112
|
-
self.x + self
|
|
113
|
-
self.y < other.y + other
|
|
114
|
-
self.y + self
|
|
115
|
-
)
|
|
89
|
+
self.x < other.x + getattr(other, "width", 0) and
|
|
90
|
+
self.x + getattr(self, "width", 0) > other.x and
|
|
91
|
+
self.y < other.y + getattr(other, "height", 0) and
|
|
92
|
+
self.y + getattr(self, "height", 0) > other.y
|
|
93
|
+
), # returns tuple for consistency
|
|
94
|
+
|
|
95
|
+
def set_image(self, img):
|
|
96
|
+
"""Update sprite's image at runtime (like flipping)"""
|
|
97
|
+
self.image = img
|
|
98
|
+
# update width/height
|
|
99
|
+
if img is not None:
|
|
100
|
+
try:
|
|
101
|
+
self.width = img.width()
|
|
102
|
+
self.height = img.height()
|
|
103
|
+
except Exception:
|
|
104
|
+
try:
|
|
105
|
+
self.width = img.width
|
|
106
|
+
self.height = img.height
|
|
107
|
+
except:
|
|
108
|
+
pass
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: crystalwindow
|
|
3
|
-
Version: 3.8.
|
|
3
|
+
Version: 3.8.3
|
|
4
4
|
Summary: A Tkinter powered window + GUI toolkit made by Crystal (MEEEEEE)! Easier apps, smoother UI and all-in-one helpers!
|
|
5
5
|
Home-page: https://pypi.org/project/crystalwindow/
|
|
6
6
|
Author: CrystalBallyHereXD
|
|
@@ -16,7 +16,7 @@ crystalwindow/gui.py,sha256=D-El18XUaZQR-XZoOr28hnhO7EEoGuypCHxPbPR_yng,3680
|
|
|
16
16
|
crystalwindow/gui_ext.py,sha256=ZhNgc5eK6Vzj-jUNeFzimuEbLnTmM7Bx594Z34_N0oM,2856
|
|
17
17
|
crystalwindow/math.py,sha256=slOY3KQZ99VDMUMxsSJabMyRtJcwVzEyxR2RoXspHho,963
|
|
18
18
|
crystalwindow/player.py,sha256=4wpIdUZLTlRXV8fDRQ11yVJRbx_cv8Ekpn2y7pQGgAQ,3442
|
|
19
|
-
crystalwindow/sprites.py,sha256=
|
|
19
|
+
crystalwindow/sprites.py,sha256=V84FBsr4DJKLtart3OEb8lvLow20wZ6JuVZ5I4TRiFg,3412
|
|
20
20
|
crystalwindow/tilemap.py,sha256=PHoKL1eWuNeHIf0w-Jh5MGdQGEgklVsxqqJOS-GNMKI,322
|
|
21
21
|
crystalwindow/ver_warner.py,sha256=qEN3ulc1NixBy15FFx2R3Zu0DhyJTVJwiESGAPwpynM,3373
|
|
22
22
|
crystalwindow/window.py,sha256=e6C8yIdVdjOduIeU0ZmlrNn8GmyvHuzKs473pRggkz0,18180
|
|
@@ -31,8 +31,8 @@ crystalwindow/gametests/guitesting.py,sha256=SrOssY5peCQEV6TQ1AiOWtjb9phVGdRzW-Q
|
|
|
31
31
|
crystalwindow/gametests/sandbox.py,sha256=Oo2tU2N0y3BPVa6T5vs_h9N6islhQrjSrr_78XLut5I,1007
|
|
32
32
|
crystalwindow/gametests/squaremove.py,sha256=poP2Zjl2oc2HVvIAgIK34H2jVj6otL4jEdvAOR6L9sI,572
|
|
33
33
|
crystalwindow/gametests/windowtesting.py,sha256=_9X6wnV1-_X_PtNS-0zu-k209NtFIwAc4vpxLPp7V2o,97
|
|
34
|
-
crystalwindow-3.8.
|
|
35
|
-
crystalwindow-3.8.
|
|
36
|
-
crystalwindow-3.8.
|
|
37
|
-
crystalwindow-3.8.
|
|
38
|
-
crystalwindow-3.8.
|
|
34
|
+
crystalwindow-3.8.3.dist-info/licenses/LICENSE,sha256=7pvUgvRXL3ED5VVAZPH5oGn1CaIXcyoDC9gqox6sB0g,1079
|
|
35
|
+
crystalwindow-3.8.3.dist-info/METADATA,sha256=h_abo60ExVg_jZNFt6rUHUUzAmx1MTDaDcxMJJ-v4CI,7340
|
|
36
|
+
crystalwindow-3.8.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
37
|
+
crystalwindow-3.8.3.dist-info/top_level.txt,sha256=PeQSld4b19XWT-zvbYkvE2Xg8sakIMbDzSzSdOSRN8o,14
|
|
38
|
+
crystalwindow-3.8.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|