crystalwindow 3.6.6__py3-none-any.whl → 3.6.7__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/gravity.py +45 -34
- {crystalwindow-3.6.6.dist-info → crystalwindow-3.6.7.dist-info}/METADATA +1 -1
- {crystalwindow-3.6.6.dist-info → crystalwindow-3.6.7.dist-info}/RECORD +6 -6
- {crystalwindow-3.6.6.dist-info → crystalwindow-3.6.7.dist-info}/WHEEL +0 -0
- {crystalwindow-3.6.6.dist-info → crystalwindow-3.6.7.dist-info}/licenses/LICENSE +0 -0
- {crystalwindow-3.6.6.dist-info → crystalwindow-3.6.7.dist-info}/top_level.txt +0 -0
crystalwindow/gravity.py
CHANGED
|
@@ -1,55 +1,71 @@
|
|
|
1
1
|
class Gravity:
|
|
2
|
-
def __init__(self, obj, force=
|
|
2
|
+
def __init__(self, obj, force=0.6, terminal_velocity=18, bouncy=False, bounce_strength=0.7):
|
|
3
|
+
"""
|
|
4
|
+
obj: Sprite (or object with x, y, width, height, vel_y)
|
|
5
|
+
force: gravity per frame
|
|
6
|
+
terminal_velocity: max falling speed
|
|
7
|
+
bouncy: should object bounce on collision
|
|
8
|
+
bounce_strength: fraction of vel_y to keep when bouncing
|
|
9
|
+
"""
|
|
3
10
|
self.obj = obj
|
|
11
|
+
|
|
12
|
+
# Ensure velocity exists
|
|
4
13
|
if not hasattr(self.obj, "vel_y"):
|
|
5
14
|
self.obj.vel_y = 0
|
|
15
|
+
|
|
6
16
|
self.force = force
|
|
7
17
|
self.terminal_velocity = terminal_velocity
|
|
8
18
|
self.bouncy = bouncy
|
|
9
19
|
self.bounce_strength = bounce_strength
|
|
10
20
|
self.on_ground = False
|
|
11
|
-
self.stretch_factor = 0 #
|
|
21
|
+
self.stretch_factor = 0 # optional squishy effect
|
|
12
22
|
|
|
13
|
-
#
|
|
14
|
-
|
|
15
|
-
if hasattr(obj, "sprite"):
|
|
16
|
-
self.mode = "sprite"
|
|
17
|
-
else:
|
|
18
|
-
self.mode = "rect"
|
|
23
|
+
# Decide mode (rect or sprite)
|
|
24
|
+
self.mode = "sprite" if hasattr(obj, "sprite") else "rect"
|
|
19
25
|
|
|
26
|
+
# -----------------------
|
|
27
|
+
# Rect getter
|
|
28
|
+
# -----------------------
|
|
20
29
|
def get_obj_rect(self):
|
|
21
|
-
# helper to get x,y,w,h depending on mode
|
|
22
30
|
if self.mode == "sprite":
|
|
23
31
|
s = self.obj.sprite
|
|
24
|
-
x
|
|
25
|
-
y = getattr(s, "y", 0)
|
|
26
|
-
w = getattr(s, "width", getattr(s, "w", 32))
|
|
27
|
-
h = getattr(s, "height", getattr(s, "h", 32))
|
|
32
|
+
return s.x, s.y, s.width, s.height
|
|
28
33
|
else:
|
|
29
|
-
x
|
|
30
|
-
y = getattr(self.obj, "y", 0)
|
|
31
|
-
w = getattr(self.obj, "width", getattr(self.obj, "w", 32))
|
|
32
|
-
h = getattr(self.obj, "height", getattr(self.obj, "h", 32))
|
|
33
|
-
return x, y, w, h
|
|
34
|
+
return self.obj.x, self.obj.y, self.obj.width, self.obj.height
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
# -----------------------
|
|
37
|
+
# Rect setter
|
|
38
|
+
# -----------------------
|
|
39
|
+
def set_obj_rect(self, x, y):
|
|
40
|
+
if self.mode == "sprite":
|
|
41
|
+
self.obj.sprite.x = x
|
|
42
|
+
self.obj.sprite.y = y
|
|
43
|
+
else:
|
|
44
|
+
self.obj.x = x
|
|
45
|
+
self.obj.y = y
|
|
46
|
+
|
|
47
|
+
# -----------------------
|
|
48
|
+
# Update gravity
|
|
49
|
+
# -----------------------
|
|
50
|
+
def update(self, dt=1, platforms=[]):
|
|
51
|
+
# Apply gravity (per frame, not dt scaled)
|
|
52
|
+
self.obj.vel_y += self.force
|
|
38
53
|
if self.obj.vel_y > self.terminal_velocity:
|
|
39
54
|
self.obj.vel_y = self.terminal_velocity
|
|
40
55
|
|
|
41
|
-
#
|
|
56
|
+
# Move
|
|
42
57
|
x, y, w, h = self.get_obj_rect()
|
|
43
58
|
y += self.obj.vel_y
|
|
44
59
|
self.on_ground = False
|
|
45
60
|
|
|
46
|
-
#
|
|
61
|
+
# Platform collisions
|
|
47
62
|
for plat in platforms:
|
|
48
|
-
plat_w = getattr(plat, "width",
|
|
49
|
-
plat_h = getattr(plat, "height",
|
|
63
|
+
plat_w = getattr(plat, "width", 32)
|
|
64
|
+
plat_h = getattr(plat, "height", 32)
|
|
65
|
+
|
|
50
66
|
if (x + w > plat.x and x < plat.x + plat_w and
|
|
51
67
|
y + h > plat.y and y < plat.y + plat_h):
|
|
52
|
-
|
|
68
|
+
# Land on top
|
|
53
69
|
y = plat.y - h
|
|
54
70
|
self.on_ground = True
|
|
55
71
|
|
|
@@ -60,16 +76,11 @@ class Gravity:
|
|
|
60
76
|
self.obj.vel_y = 0
|
|
61
77
|
self.stretch_factor = 0
|
|
62
78
|
|
|
63
|
-
#
|
|
79
|
+
# Slowly reset stretch
|
|
64
80
|
if self.stretch_factor > 0:
|
|
65
81
|
self.stretch_factor -= 0.05
|
|
66
82
|
if self.stretch_factor < 0:
|
|
67
83
|
self.stretch_factor = 0
|
|
68
84
|
|
|
69
|
-
#
|
|
70
|
-
|
|
71
|
-
self.obj.sprite.x = x
|
|
72
|
-
self.obj.sprite.y = y
|
|
73
|
-
else:
|
|
74
|
-
self.obj.x = x
|
|
75
|
-
self.obj.y = y
|
|
85
|
+
# Write back position
|
|
86
|
+
self.set_obj_rect(x, y)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: crystalwindow
|
|
3
|
-
Version: 3.6.
|
|
3
|
+
Version: 3.6.7
|
|
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
|
|
@@ -11,7 +11,7 @@ crystalwindow/draw_rects.py,sha256=o7siET3y35N2LPeNBGe8QhsQbOH8J-xF6fOUz07rymU,1
|
|
|
11
11
|
crystalwindow/draw_text_helper.py,sha256=qv5fFCuTCKWeGDk9Z_ZpOzrTFP8YYwlgQrrorwrq9Hg,1298
|
|
12
12
|
crystalwindow/draw_tool.py,sha256=1YYEqjmgt4HpV3S15sTjCSmcqgHup4fD8gskTkxU0t4,1638
|
|
13
13
|
crystalwindow/fun_helpers.py,sha256=fo5yTwGENltdtVIVwgITtUkvzpsImujOcqTxe8XPzR8,760
|
|
14
|
-
crystalwindow/gravity.py,sha256=
|
|
14
|
+
crystalwindow/gravity.py,sha256=pZJykZzO-mKVBPsZRP55nnlvUoYQfR29wPgJcI4IbBs,2904
|
|
15
15
|
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
|
|
@@ -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.6.
|
|
35
|
-
crystalwindow-3.6.
|
|
36
|
-
crystalwindow-3.6.
|
|
37
|
-
crystalwindow-3.6.
|
|
38
|
-
crystalwindow-3.6.
|
|
34
|
+
crystalwindow-3.6.7.dist-info/licenses/LICENSE,sha256=7pvUgvRXL3ED5VVAZPH5oGn1CaIXcyoDC9gqox6sB0g,1079
|
|
35
|
+
crystalwindow-3.6.7.dist-info/METADATA,sha256=va5lxkx7-ygKzOZqvmKUuNy33bYscHNVAQPy06JAZXY,7340
|
|
36
|
+
crystalwindow-3.6.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
37
|
+
crystalwindow-3.6.7.dist-info/top_level.txt,sha256=PeQSld4b19XWT-zvbYkvE2Xg8sakIMbDzSzSdOSRN8o,14
|
|
38
|
+
crystalwindow-3.6.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|