sverpykit 0.2.14__tar.gz → 0.2.16__tar.gz
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.
- {sverpykit-0.2.14 → sverpykit-0.2.16}/PKG-INFO +3 -1
- {sverpykit-0.2.14 → sverpykit-0.2.16}/README.md +2 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/pyproject.toml +1 -1
- sverpykit-0.2.16/sverpykit/Collide/Collide.py +57 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/Draw/Draw.py +1 -1
- sverpykit-0.2.14/sverpykit/Objects/Entity.py → sverpykit-0.2.16/sverpykit/Objects/Object.py +63 -19
- sverpykit-0.2.16/sverpykit/Shapes/Circle.py +22 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/Ui/SearchBar.py +6 -3
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/Ui/TextBlock.py +26 -3
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/__init__.py +12 -2
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/core/Config.py +8 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/core/FileManager.py +0 -1
- sverpykit-0.2.16/sverpykit/core/Json.py +19 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/core/Runtime.py +1 -1
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit.egg-info/PKG-INFO +3 -1
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit.egg-info/SOURCES.txt +3 -2
- sverpykit-0.2.14/sverpykit/Collide/Collide.py +0 -13
- sverpykit-0.2.14/sverpykit/Objects/Platform.py +0 -28
- {sverpykit-0.2.14 → sverpykit-0.2.16}/LICENSE +0 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/setup.cfg +0 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/Ui/Button.py +0 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/Ui/DropDown.py +0 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/Ui/Window.py +0 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/core/Objects.py +0 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit/core/initialize.py +0 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit.egg-info/dependency_links.txt +0 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit.egg-info/requires.txt +0 -0
- {sverpykit-0.2.14 → sverpykit-0.2.16}/sverpykit.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sverpykit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.16
|
|
4
4
|
Summary: A wrapper for pygame.
|
|
5
5
|
Description-Content-Type: text/markdown
|
|
6
6
|
License-File: LICENSE
|
|
@@ -10,6 +10,8 @@ Dynamic: license-file
|
|
|
10
10
|
# Sverrys PygameTools
|
|
11
11
|
Sverrys PygameTools is a wrapper for the library "pygame" that adds a UI and game logic.
|
|
12
12
|
|
|
13
|
+
<img src="sverpykit_icon.svg" height=200 width=200>
|
|
14
|
+
|
|
13
15
|
How to use:<br>
|
|
14
16
|
To use Sverrys PygameTools you must install it from github by executing this command
|
|
15
17
|
in your terminal:<br>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Sverrys PygameTools
|
|
2
2
|
Sverrys PygameTools is a wrapper for the library "pygame" that adds a UI and game logic.
|
|
3
3
|
|
|
4
|
+
<img src="sverpykit_icon.svg" height=200 width=200>
|
|
5
|
+
|
|
4
6
|
How to use:<br>
|
|
5
7
|
To use Sverrys PygameTools you must install it from github by executing this command
|
|
6
8
|
in your terminal:<br>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from sverpykit.Shapes import Circle
|
|
2
|
+
import pygame, math
|
|
3
|
+
|
|
4
|
+
class collides:
|
|
5
|
+
|
|
6
|
+
@ staticmethod
|
|
7
|
+
def rect_rect(
|
|
8
|
+
rect1: pygame.Rect,
|
|
9
|
+
rect2: pygame.Rect
|
|
10
|
+
) -> bool:
|
|
11
|
+
return rect1.colliderect(rect2)
|
|
12
|
+
|
|
13
|
+
@ staticmethod
|
|
14
|
+
def rect_point(
|
|
15
|
+
rect: pygame.Rect,
|
|
16
|
+
point: tuple[int, int]
|
|
17
|
+
) -> bool:
|
|
18
|
+
return rect.collidepoint(point)
|
|
19
|
+
|
|
20
|
+
@ staticmethod
|
|
21
|
+
def circle_circle(
|
|
22
|
+
circle1: Circle.Circle,
|
|
23
|
+
circle2: Circle.Circle
|
|
24
|
+
) -> bool:
|
|
25
|
+
"""
|
|
26
|
+
:param circle1: The first circle.
|
|
27
|
+
:param circle2: The second circle.
|
|
28
|
+
:return: Returns if the circles collide.
|
|
29
|
+
"""
|
|
30
|
+
return math.sqrt(
|
|
31
|
+
math.pow(circle1.center[0] - circle2.center[0], 2) + math.pow(circle1.center[1] - circle2.center[1], 2)
|
|
32
|
+
) < circle1.diameter/2 + circle2.diameter/2
|
|
33
|
+
|
|
34
|
+
@ staticmethod
|
|
35
|
+
def circle_point(
|
|
36
|
+
circle: Circle.Circle,
|
|
37
|
+
point: tuple[int, int]
|
|
38
|
+
) -> bool:
|
|
39
|
+
"""
|
|
40
|
+
:param circle: The circle.
|
|
41
|
+
:param point: The coordinates of the point.
|
|
42
|
+
:return: Returns if the coordinates are in the circle.
|
|
43
|
+
"""
|
|
44
|
+
return math.sqrt(
|
|
45
|
+
math.pow(circle.center[0] - point[0], 2) + math.pow(circle.center[1] - point[1], 2)
|
|
46
|
+
) < circle.diameter
|
|
47
|
+
|
|
48
|
+
# @ staticmethod
|
|
49
|
+
# def circle_rect(
|
|
50
|
+
# circle: Circle.Circle,
|
|
51
|
+
# rect: pygame.Rect
|
|
52
|
+
# ) -> bool:
|
|
53
|
+
# """
|
|
54
|
+
# :param circle: The circle.
|
|
55
|
+
# :param rect: The rect.
|
|
56
|
+
# :return: Returns if the rectangle collides with the circle.
|
|
57
|
+
# """
|
|
@@ -2,16 +2,17 @@ from sverpykit.core import Config, Runtime
|
|
|
2
2
|
from typing import Callable, Any
|
|
3
3
|
import pygame
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class Object:
|
|
6
6
|
def __init__(
|
|
7
7
|
self,
|
|
8
8
|
hitbox: pygame.Rect,
|
|
9
9
|
surface: pygame.Surface,
|
|
10
|
-
|
|
10
|
+
events: dict[str, Callable] | None = None,
|
|
11
11
|
statistics: dict[str, Any] | None = None,
|
|
12
|
-
states: dict[str, Any] | None = None
|
|
12
|
+
states: dict[str, Any] | None = None,
|
|
13
|
+
resize_surface: bool = True
|
|
13
14
|
):
|
|
14
|
-
|
|
15
|
+
events = events if isinstance(events, dict)\
|
|
15
16
|
else {}
|
|
16
17
|
statistics = statistics if isinstance(statistics, dict)\
|
|
17
18
|
else {}
|
|
@@ -19,10 +20,17 @@ class Entity:
|
|
|
19
20
|
else {}
|
|
20
21
|
self.hitbox = hitbox
|
|
21
22
|
self.surface = surface
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if resize_surface:
|
|
24
|
+
self.surface = pygame.transform.scale(surface, (hitbox.w, hitbox.h))
|
|
25
|
+
|
|
26
|
+
self.states: dict[str, str | int | float | bool | dict[str, str | int | float | bool]] = {
|
|
27
|
+
"surface": "solid", # Will be used later with slippery and bouncy.
|
|
28
|
+
"physics": {
|
|
29
|
+
"enabled": False,
|
|
30
|
+
"terminal_velocity": 1 # This is a multiplier, but 0 = off (Keep speeding up forever).
|
|
31
|
+
},
|
|
32
|
+
"vy": 0.0,
|
|
33
|
+
"vx": 0.0,
|
|
26
34
|
"show_hitbox": False
|
|
27
35
|
}
|
|
28
36
|
self.states.update(states)
|
|
@@ -34,10 +42,14 @@ class Entity:
|
|
|
34
42
|
self.stats.update(statistics)
|
|
35
43
|
|
|
36
44
|
self.accepted_events = {
|
|
37
|
-
"key":
|
|
38
|
-
"mouse":
|
|
45
|
+
"key": Object.key_events,
|
|
46
|
+
"mouse": Object.mouse_events,
|
|
47
|
+
"random": Object.random_event
|
|
39
48
|
}
|
|
40
|
-
self.accepted_events.update(
|
|
49
|
+
self.accepted_events.update(events)
|
|
50
|
+
|
|
51
|
+
self.standing_on: Object | None = None
|
|
52
|
+
self.on_ground = False
|
|
41
53
|
|
|
42
54
|
def key_events(self, keys: dict):
|
|
43
55
|
pass
|
|
@@ -45,6 +57,9 @@ class Entity:
|
|
|
45
57
|
def mouse_events(self, button: int, pos: tuple[int, int]):
|
|
46
58
|
pass
|
|
47
59
|
|
|
60
|
+
def random_event(self, number):
|
|
61
|
+
pass
|
|
62
|
+
|
|
48
63
|
def draw(self):
|
|
49
64
|
Config.screen.blit(
|
|
50
65
|
self.surface, self.hitbox
|
|
@@ -57,11 +72,25 @@ class Entity:
|
|
|
57
72
|
width=1
|
|
58
73
|
)
|
|
59
74
|
|
|
60
|
-
def
|
|
61
|
-
self.hitbox.
|
|
75
|
+
def physics(self):
|
|
76
|
+
mass = self.hitbox.w * self.hitbox.h
|
|
77
|
+
terminal_velocity = mass * Config.terminal_velocity
|
|
78
|
+
self.states["vy"] = min(terminal_velocity, max(-terminal_velocity, self.states["vy"] - Config.delta_time * Config.gravity))
|
|
79
|
+
|
|
80
|
+
friction_force_x = int(
|
|
81
|
+
Config.slippery_friction if self.standing_on.states["surface"] == "slippery" else Config.solid_friction* (mass * Config.gravity)
|
|
82
|
+
) if self.standing_on else Config.air_friction
|
|
83
|
+
if self.states["vx"] > 0:
|
|
84
|
+
self.states["vx"] = max(0, self.states["vx"] - friction_force_x)
|
|
85
|
+
if self.states["vx"] < 0:
|
|
86
|
+
self.states["vx"] = min(0, self.states["vx"] + friction_force_x)
|
|
87
|
+
|
|
88
|
+
self.hitbox.y -= self.states["vy"] * Config.delta_time * Config.gravity
|
|
62
89
|
self.check_y_collision()
|
|
63
|
-
self.hitbox.x += self.states["vx"] * Config.delta_time
|
|
90
|
+
self.hitbox.x += self.states["vx"] * Config.delta_time * Config.gravity
|
|
64
91
|
self.check_x_collision()
|
|
92
|
+
|
|
93
|
+
def events(self):
|
|
65
94
|
click = pygame.mouse.get_pressed()
|
|
66
95
|
mp = pygame.mouse.get_pos()
|
|
67
96
|
if any(click):
|
|
@@ -69,6 +98,8 @@ class Entity:
|
|
|
69
98
|
keys = pygame.key.get_pressed()
|
|
70
99
|
if any(keys):
|
|
71
100
|
self.accepted_events["key"](self, keys)
|
|
101
|
+
if self.states["physics"]:
|
|
102
|
+
self.physics()
|
|
72
103
|
|
|
73
104
|
def check_x_collision(self) -> None:
|
|
74
105
|
"""
|
|
@@ -82,12 +113,14 @@ class Entity:
|
|
|
82
113
|
continue
|
|
83
114
|
if not obj.collides(self.hitbox):
|
|
84
115
|
continue
|
|
116
|
+
if obj is self:
|
|
117
|
+
continue
|
|
85
118
|
|
|
86
119
|
if self.states["vx"] > 0:
|
|
87
|
-
self.hitbox.x = obj.
|
|
120
|
+
self.hitbox.x = obj.hitbox.x - self.hitbox.w
|
|
88
121
|
reset_velocity = True
|
|
89
122
|
elif self.states["vx"] < 0:
|
|
90
|
-
self.hitbox.x = obj.
|
|
123
|
+
self.hitbox.x = obj.hitbox.x + obj.rect.w
|
|
91
124
|
reset_velocity = True
|
|
92
125
|
|
|
93
126
|
if reset_velocity:
|
|
@@ -98,20 +131,31 @@ class Entity:
|
|
|
98
131
|
This check should be run after every time you update the y-position of the entity.
|
|
99
132
|
"""
|
|
100
133
|
|
|
134
|
+
self.on_ground = False
|
|
101
135
|
reset_velocity = False
|
|
136
|
+
collides_on = None
|
|
102
137
|
|
|
103
138
|
for obj in Runtime.game_objects:
|
|
139
|
+
print(hasattr(obj, "collides"))
|
|
104
140
|
if not hasattr(obj, "collides"):
|
|
105
141
|
continue
|
|
106
142
|
if not obj.collides(self.hitbox):
|
|
107
143
|
continue
|
|
144
|
+
if obj is self:
|
|
145
|
+
continue
|
|
108
146
|
|
|
109
147
|
if self.states["vy"] > 0:
|
|
110
|
-
self.hitbox.y = obj.
|
|
148
|
+
self.hitbox.y = obj.hitbox.y + obj.hitbox.h
|
|
111
149
|
reset_velocity = True
|
|
112
150
|
elif self.states["vy"] < 0:
|
|
113
|
-
self.hitbox.y = obj.
|
|
151
|
+
self.hitbox.y = obj.hitbox.y - self.hitbox.h
|
|
114
152
|
reset_velocity = True
|
|
153
|
+
collides_on = obj
|
|
154
|
+
self.on_ground = True
|
|
115
155
|
|
|
116
156
|
if reset_velocity:
|
|
117
|
-
self.states["vy"] = 0
|
|
157
|
+
self.states["vy"] = 0
|
|
158
|
+
self.standing_on = collides_on
|
|
159
|
+
|
|
160
|
+
def collides(self, hitbox: pygame.Rect):
|
|
161
|
+
return self.hitbox.colliderect(hitbox)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
|
|
3
|
+
class Circle:
|
|
4
|
+
def __init__(
|
|
5
|
+
self,
|
|
6
|
+
center: tuple[int, int],
|
|
7
|
+
diameter: int
|
|
8
|
+
):
|
|
9
|
+
self.center = center
|
|
10
|
+
self.diameter = diameter
|
|
11
|
+
|
|
12
|
+
def draw(
|
|
13
|
+
self,
|
|
14
|
+
display: pygame.Surface,
|
|
15
|
+
color: tuple[int, int, int]
|
|
16
|
+
) -> None:
|
|
17
|
+
pygame.draw.circle(
|
|
18
|
+
surface=display,
|
|
19
|
+
color=color,
|
|
20
|
+
center=self.center,
|
|
21
|
+
radius=self.diameter/2
|
|
22
|
+
)
|
|
@@ -12,17 +12,20 @@ class SearchBar:
|
|
|
12
12
|
display: pygame.Surface,
|
|
13
13
|
function: Callable = lambda x: None,
|
|
14
14
|
color: pygame.Color | tuple[int, int, int] = (50, 50, 50),
|
|
15
|
+
preset: str = "",
|
|
15
16
|
**kwargs
|
|
16
17
|
):
|
|
17
18
|
self.rect: pygame.Rect = rect
|
|
18
19
|
self.hitbox_offset = (0, 0)
|
|
19
20
|
|
|
21
|
+
self.preset = preset
|
|
22
|
+
|
|
20
23
|
self.display: pygame.Surface = display
|
|
21
24
|
self.color: pygame.Color | tuple[int, int, int] = color
|
|
22
25
|
|
|
23
26
|
self.stored: str = ""
|
|
24
27
|
self.last_stored: str = ""
|
|
25
|
-
self.stored_surf: pygame.Surface = Config.fonts['default'].render(self.stored, True, Config.BEIGE)
|
|
28
|
+
self.stored_surf: pygame.Surface = Config.fonts['default'].render(f"{self.preset}: {self.stored}", True, Config.BEIGE)
|
|
26
29
|
|
|
27
30
|
self.selected: bool = False
|
|
28
31
|
|
|
@@ -84,13 +87,13 @@ class SearchBar:
|
|
|
84
87
|
self.stored += event.unicode
|
|
85
88
|
|
|
86
89
|
if self.stored != self.last_stored:
|
|
87
|
-
self.stored_surf = Draw.render_text(self.stored)
|
|
90
|
+
self.stored_surf = Draw.render_text(f"{self.preset}: {self.stored}")
|
|
88
91
|
self.last_stored = self.stored
|
|
89
92
|
|
|
90
93
|
if not click:
|
|
91
94
|
return
|
|
92
95
|
|
|
93
|
-
if Collide.rect_point(
|
|
96
|
+
if Collide.collides.rect_point(
|
|
94
97
|
rect=pygame.Rect(
|
|
95
98
|
self.rect.x + self.hitbox_offset[0],
|
|
96
99
|
self.rect.y + self.hitbox_offset[1],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from sverpykit.core import Config
|
|
2
2
|
from sverpykit.Draw import Draw
|
|
3
|
-
from sverpykit.Ui import Window
|
|
3
|
+
from sverpykit.Ui import Window, SearchBar
|
|
4
4
|
from typing import Callable, Any
|
|
5
5
|
import pygame
|
|
6
6
|
|
|
@@ -15,6 +15,7 @@ class TextBlock:
|
|
|
15
15
|
self.rect = rect
|
|
16
16
|
self.text = text
|
|
17
17
|
self.text_surfs: list[dict] = [{"text": Draw.render_text(str(text), name=font), "newline": newline}]
|
|
18
|
+
self.searchbars: list[SearchBar.SearchBar] = []
|
|
18
19
|
self.font = font
|
|
19
20
|
|
|
20
21
|
self.owner = None
|
|
@@ -28,6 +29,7 @@ class TextBlock:
|
|
|
28
29
|
|
|
29
30
|
offset_x = 0
|
|
30
31
|
offset_y = 0
|
|
32
|
+
searchbars_index = 0
|
|
31
33
|
for payload in self.text_surfs:
|
|
32
34
|
Draw.draw_surface(
|
|
33
35
|
payload["text"], (
|
|
@@ -52,7 +54,17 @@ class TextBlock:
|
|
|
52
54
|
offset_x = 0
|
|
53
55
|
else:
|
|
54
56
|
offset_x += payload["text"].get_width()
|
|
57
|
+
|
|
58
|
+
if payload.get("input", False) and payload["input"][0]:
|
|
59
|
+
sb = self.searchbars[searchbars_index]
|
|
60
|
+
if self.owner:
|
|
61
|
+
sb.hitbox_offset = (self.owner.rect.x, self.owner.rect.y)
|
|
62
|
+
sb.rect.x = offset_x
|
|
63
|
+
sb.rect.y = offset_y
|
|
64
|
+
searchbars_index += 1
|
|
55
65
|
self.last_size = offset_y
|
|
66
|
+
[sb.draw(display) for sb in self.searchbars]
|
|
67
|
+
[sb.events() for sb in self.searchbars]
|
|
56
68
|
|
|
57
69
|
def events(self):
|
|
58
70
|
mp = pygame.mouse.get_pos()
|
|
@@ -112,14 +124,25 @@ class TextBlock:
|
|
|
112
124
|
font: str,
|
|
113
125
|
color: tuple[int, int, int],
|
|
114
126
|
hyperlink: tuple[Callable, list[Any]] | None = None,
|
|
127
|
+
input_: tuple[bool, Callable, list[Any], str] = (False, lambda : None, [], ""),
|
|
115
128
|
newline: bool = False
|
|
116
129
|
):
|
|
117
|
-
self.text = self.text +
|
|
130
|
+
self.text = self.text + text
|
|
118
131
|
self.text_surfs.append({
|
|
119
132
|
"text": Draw.render_text(text, True, color, font),
|
|
120
133
|
"hyperlink": hyperlink,
|
|
121
|
-
"newline": newline
|
|
134
|
+
"newline": newline,
|
|
135
|
+
"input": input_
|
|
122
136
|
})
|
|
137
|
+
if input_[0]:
|
|
138
|
+
print(input_)
|
|
139
|
+
self.searchbars.append(SearchBar.SearchBar(
|
|
140
|
+
*input_[2],
|
|
141
|
+
rect=pygame.Rect(0, 0, 200, Config.fonts[self.font].get_height()),
|
|
142
|
+
display=Config.screen,
|
|
143
|
+
function=input_[1],
|
|
144
|
+
preset=input_[3]
|
|
145
|
+
))
|
|
123
146
|
|
|
124
147
|
def reset(self):
|
|
125
148
|
self.text = ""
|
|
@@ -6,12 +6,19 @@ from .core.Runtime import add_layer, add_game_object, start, update as run_frame
|
|
|
6
6
|
from .core.Config import default_exit as quit_game
|
|
7
7
|
from .core.initialize import set_display, set_frame_method, set_font, set_quit_method, set_tick_method,\
|
|
8
8
|
set_src_path, max_rate
|
|
9
|
+
|
|
10
|
+
# File Management
|
|
11
|
+
from .core import Json
|
|
9
12
|
from .core.FileManager import resource_path
|
|
10
13
|
|
|
14
|
+
# Collision
|
|
15
|
+
from .Collide.Collide import collides
|
|
16
|
+
|
|
11
17
|
# Drawing
|
|
12
18
|
from .Draw.Draw import draw_surface, draw_rect, draw_circle, render_text
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
|
|
20
|
+
# Object
|
|
21
|
+
from .Objects.Object import Object
|
|
15
22
|
|
|
16
23
|
# Ui parts
|
|
17
24
|
from .Ui.Button import Button
|
|
@@ -20,6 +27,9 @@ from .Ui.DropDown import DropDown
|
|
|
20
27
|
from .Ui.Window import Window
|
|
21
28
|
from .Ui.TextBlock import TextBlock
|
|
22
29
|
|
|
30
|
+
# Colors
|
|
31
|
+
from .core.Config import BEIGE
|
|
32
|
+
|
|
23
33
|
__all__ = [
|
|
24
34
|
"Config",
|
|
25
35
|
"Runtime",
|
|
@@ -24,6 +24,14 @@ events: list[pygame.event.Event] = []
|
|
|
24
24
|
clock: pygame.time.Clock = pygame.time.Clock()
|
|
25
25
|
delta_time: int
|
|
26
26
|
|
|
27
|
+
# Physics
|
|
28
|
+
gravity = 20
|
|
29
|
+
terminal_velocity = 10
|
|
30
|
+
|
|
31
|
+
solid_friction = 1
|
|
32
|
+
slippery_friction = 0.7
|
|
33
|
+
air_friction = 0.25
|
|
34
|
+
|
|
27
35
|
# Functions
|
|
28
36
|
exit_function: Callable = default_exit
|
|
29
37
|
frame_function: Callable = frame
|
|
@@ -12,6 +12,5 @@ def resource_path(relative_path: str) -> str:
|
|
|
12
12
|
if not os.path.exists(src_path):
|
|
13
13
|
raise TypeError(f"Please set the src path before you run this function!")
|
|
14
14
|
if hasattr(sys, '_MEIPASS'):
|
|
15
|
-
print("Not supported yet!")
|
|
16
15
|
return os.path.join(sys._MEIPASS, f"{relative_path}")
|
|
17
16
|
return os.path.join(src_path, f"{relative_path}")
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
def read_json(path: str, obj: int | str | None = None) -> dict | list | int | str:
|
|
4
|
+
with open(path, "r") as f:
|
|
5
|
+
data = json.load(f)
|
|
6
|
+
return data.get(obj, data)
|
|
7
|
+
|
|
8
|
+
def write_json(path: str, obj: dict | list) -> None:
|
|
9
|
+
with open(path, "w") as f:
|
|
10
|
+
json.dump(obj, f, indent=4)
|
|
11
|
+
|
|
12
|
+
def update_json(path: str, obj: dict | list) -> None:
|
|
13
|
+
with open(path, "r") as f:
|
|
14
|
+
data: list | dict = json.load(f)
|
|
15
|
+
if not isinstance(obj, type(data)):
|
|
16
|
+
raise ValueError("Object does not have the same type as JSON file!")
|
|
17
|
+
with open(path, "w") as f:
|
|
18
|
+
data.update(obj) if isinstance(data, dict) else data.extend(obj)
|
|
19
|
+
json.dump(data, f, indent=4)
|
|
@@ -107,9 +107,9 @@ def update():
|
|
|
107
107
|
register_tick()
|
|
108
108
|
|
|
109
109
|
Config.screen.fill(Config.background_color)
|
|
110
|
-
Config.frame_function()
|
|
111
110
|
[layer.draw() for layer in ui_layers]
|
|
112
111
|
[obj.draw() for obj in game_objects]
|
|
112
|
+
Config.frame_function()
|
|
113
113
|
|
|
114
114
|
pygame.display.flip()
|
|
115
115
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sverpykit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.16
|
|
4
4
|
Summary: A wrapper for pygame.
|
|
5
5
|
Description-Content-Type: text/markdown
|
|
6
6
|
License-File: LICENSE
|
|
@@ -10,6 +10,8 @@ Dynamic: license-file
|
|
|
10
10
|
# Sverrys PygameTools
|
|
11
11
|
Sverrys PygameTools is a wrapper for the library "pygame" that adds a UI and game logic.
|
|
12
12
|
|
|
13
|
+
<img src="sverpykit_icon.svg" height=200 width=200>
|
|
14
|
+
|
|
13
15
|
How to use:<br>
|
|
14
16
|
To use Sverrys PygameTools you must install it from github by executing this command
|
|
15
17
|
in your terminal:<br>
|
|
@@ -9,8 +9,8 @@ sverpykit.egg-info/requires.txt
|
|
|
9
9
|
sverpykit.egg-info/top_level.txt
|
|
10
10
|
sverpykit/Collide/Collide.py
|
|
11
11
|
sverpykit/Draw/Draw.py
|
|
12
|
-
sverpykit/Objects/
|
|
13
|
-
sverpykit/
|
|
12
|
+
sverpykit/Objects/Object.py
|
|
13
|
+
sverpykit/Shapes/Circle.py
|
|
14
14
|
sverpykit/Ui/Button.py
|
|
15
15
|
sverpykit/Ui/DropDown.py
|
|
16
16
|
sverpykit/Ui/SearchBar.py
|
|
@@ -18,6 +18,7 @@ sverpykit/Ui/TextBlock.py
|
|
|
18
18
|
sverpykit/Ui/Window.py
|
|
19
19
|
sverpykit/core/Config.py
|
|
20
20
|
sverpykit/core/FileManager.py
|
|
21
|
+
sverpykit/core/Json.py
|
|
21
22
|
sverpykit/core/Objects.py
|
|
22
23
|
sverpykit/core/Runtime.py
|
|
23
24
|
sverpykit/core/initialize.py
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
|
|
3
|
-
class Platform:
|
|
4
|
-
def __init__(
|
|
5
|
-
self,
|
|
6
|
-
rect: pygame.Rect,
|
|
7
|
-
surface: pygame.Surface,
|
|
8
|
-
display: pygame.Surface,
|
|
9
|
-
resize_surface: bool = True
|
|
10
|
-
):
|
|
11
|
-
self.rect = rect
|
|
12
|
-
self.surface = pygame.transform.scale(
|
|
13
|
-
surface, (self.rect.w, self.rect.h)
|
|
14
|
-
) if resize_surface else surface
|
|
15
|
-
self.display = display
|
|
16
|
-
|
|
17
|
-
def draw(self, display: pygame.Surface | None = None):
|
|
18
|
-
display = display if display else self.display
|
|
19
|
-
|
|
20
|
-
display.blit(
|
|
21
|
-
self.surface, self.rect
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
def events(self):
|
|
25
|
-
pass
|
|
26
|
-
|
|
27
|
-
def collides(self, rect: pygame.Rect):
|
|
28
|
-
return self.rect.colliderect(rect)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|