crystalwindow 3.6.6__py3-none-any.whl → 3.6.9__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 CHANGED
@@ -1,55 +1,71 @@
1
1
  class Gravity:
2
- def __init__(self, obj, force=1, terminal_velocity=15, bouncy=False, bounce_strength=0.7):
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 # for squishy effect
21
+ self.stretch_factor = 0 # optional squishy effect
12
22
 
13
- # --- NEW: choose mode ---
14
- # If object has .sprite use that, else fallback to rect mode
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 = getattr(s, "x", 0)
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 = getattr(self.obj, "x", 0)
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
- def update(self, dt, platforms=[]):
36
- # apply gravity
37
- self.obj.vel_y += self.force * dt * 60
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
- # move object
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
- # check collisions
61
+ # Platform collisions
47
62
  for plat in platforms:
48
- plat_w = getattr(plat, "width", getattr(plat, "w", 0))
49
- plat_h = getattr(plat, "height", getattr(plat, "h", 0))
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
- # slowly reset stretch
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
- # write back position
70
- if self.mode == "sprite":
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)
crystalwindow/window.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # === Window Management (tkinter version) ===
2
2
  import tkinter as tk
3
- import base64, io, os, sys, contextlib
3
+ import base64, io, os, sys, contextlib, time
4
4
 
5
5
  # === Boot ===
6
6
  main_file = os.path.basename(sys.argv[0])
@@ -114,6 +114,8 @@ class Window:
114
114
  self._mouse_pressed = (False, False, False)
115
115
  self._bg_color = (20, 20, 50)
116
116
  self.draw_calls = []
117
+ self._key_last = {} # new dict to store last press time per key
118
+ self._key_cooldown = 0.15 # seconds, tweak for faster/slower input
117
119
 
118
120
  # === Event bindings ===
119
121
  self.root.bind("<KeyPress>", self._on_keydown)
@@ -148,7 +150,16 @@ class Window:
148
150
  def key_pressed(self, key):
149
151
  if isinstance(key, str):
150
152
  key = self.KEY_MAP.get(key, key)
151
- return self.keys.get(key, False)
153
+
154
+ now = time.time()
155
+ pressed = self.keys.get(key, False)
156
+
157
+ last = self._key_last.get(key, 0)
158
+ if pressed and (now - last) >= self._key_cooldown:
159
+ self._key_last[key] = now
160
+ return True
161
+
162
+ return False
152
163
 
153
164
  def mouse_pressed(self, button=1):
154
165
  return self._mouse_pressed[button - 1]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: crystalwindow
3
- Version: 3.6.6
3
+ Version: 3.6.9
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=tMctHYubpcUJRogz4kNg3XZGDPE3605zON-4YumiVGo,2752
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
@@ -19,7 +19,7 @@ crystalwindow/player.py,sha256=4wpIdUZLTlRXV8fDRQ11yVJRbx_cv8Ekpn2y7pQGgAQ,3442
19
19
  crystalwindow/sprites.py,sha256=YVoLnpLsCHlHmTahk8hwWnUtkcI-FC_w4OjZN4YtmLs,2569
20
20
  crystalwindow/tilemap.py,sha256=PHoKL1eWuNeHIf0w-Jh5MGdQGEgklVsxqqJOS-GNMKI,322
21
21
  crystalwindow/ver_warner.py,sha256=qEN3ulc1NixBy15FFx2R3Zu0DhyJTVJwiESGAPwpynM,3373
22
- crystalwindow/window.py,sha256=JmWjR0aOm4Q8OoboqDHzGKqUmxlAJbj37KBBY0QPjrs,17779
22
+ crystalwindow/window.py,sha256=07YzeF-XHNBbQu2USscAvfE3_V-dmkjxzibnvKJFcVQ,18169
23
23
  crystalwindow/Icons/default_icon.png,sha256=Loq27Pxb8Wb3Sz-XwtNF1RmlLNxR4TcfOWfK-1lWcII,7724
24
24
  crystalwindow/docs/getting_started.md,sha256=e_XEhJk8eatS22MX0nRX7hQNkYkwN9both1ObabZSTw,5759
25
25
  crystalwindow/docs/index.md,sha256=bd14uLWtRSeRBm28zngGyfGDI1J6bJRvHkQLDpYwgOE,747
@@ -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.6.dist-info/licenses/LICENSE,sha256=7pvUgvRXL3ED5VVAZPH5oGn1CaIXcyoDC9gqox6sB0g,1079
35
- crystalwindow-3.6.6.dist-info/METADATA,sha256=okNZBTtaxrXf1LzZmjfzY7kiXRmwF4ydG8c_MBUbAZs,7340
36
- crystalwindow-3.6.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
- crystalwindow-3.6.6.dist-info/top_level.txt,sha256=PeQSld4b19XWT-zvbYkvE2Xg8sakIMbDzSzSdOSRN8o,14
38
- crystalwindow-3.6.6.dist-info/RECORD,,
34
+ crystalwindow-3.6.9.dist-info/licenses/LICENSE,sha256=7pvUgvRXL3ED5VVAZPH5oGn1CaIXcyoDC9gqox6sB0g,1079
35
+ crystalwindow-3.6.9.dist-info/METADATA,sha256=TslLKDnbCPJgnapM3zXOu70iIYHxZJnq9gezOu_LsQk,7340
36
+ crystalwindow-3.6.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
+ crystalwindow-3.6.9.dist-info/top_level.txt,sha256=PeQSld4b19XWT-zvbYkvE2Xg8sakIMbDzSzSdOSRN8o,14
38
+ crystalwindow-3.6.9.dist-info/RECORD,,