GameBox 0.2.0__tar.gz → 0.9.0__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.
Files changed (35) hide show
  1. {gamebox-0.2.0 → gamebox-0.9.0}/PKG-INFO +1 -1
  2. {gamebox-0.2.0 → gamebox-0.9.0}/pyproject.toml +1 -1
  3. gamebox-0.9.0/src/GameBox/GameLevel_ui/_Animations.py +39 -0
  4. gamebox-0.9.0/src/GameBox/GameLevel_ui/_sprites.py +243 -0
  5. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/__init__.py +11 -1
  6. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/_game.py +6 -0
  7. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/basics/_net.py +2 -0
  8. gamebox-0.9.0/src/GameBox/basics/_shapes.py +88 -0
  9. gamebox-0.9.0/src/GameBox/basics/cammera.py +75 -0
  10. gamebox-0.9.0/src/GameBox/helpers/_Conditions.py +65 -0
  11. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/helpers/_collisions.py +13 -12
  12. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/helpers/_input.py +4 -0
  13. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/player/_player.py +32 -6
  14. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/player/_playerPhysics.py +2 -2
  15. gamebox-0.9.0/src/GameBox/player/_playerSprite.py +86 -0
  16. gamebox-0.9.0/src/GameBox/tilemap/_Editor.py +36 -0
  17. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/tilemap/_collisionDef.py +7 -0
  18. gamebox-0.9.0/src/GameBox/tilemap/_editorBrushes.py +166 -0
  19. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/tilemap/_tilemap.py +17 -1
  20. gamebox-0.9.0/src/GameBox/ui/_basicUI.py +65 -0
  21. gamebox-0.9.0/tests/GettingStarted.py +52 -0
  22. gamebox-0.9.0/tests/Player.png +0 -0
  23. {gamebox-0.2.0 → gamebox-0.9.0}/tests/basicScreen.py +6 -4
  24. gamebox-0.9.0/tests/testMap.json +1 -0
  25. gamebox-0.2.0/src/GameBox/basics/_shapes.py +0 -33
  26. gamebox-0.2.0/src/GameBox/basics/cammera.py +0 -36
  27. gamebox-0.2.0/src/GameBox/tilemap/_Editor.py +0 -101
  28. gamebox-0.2.0/tests/testMap.json +0 -1
  29. {gamebox-0.2.0 → gamebox-0.9.0}/.gitignore +0 -0
  30. {gamebox-0.2.0 → gamebox-0.9.0}/LICENSE +0 -0
  31. {gamebox-0.2.0 → gamebox-0.9.0}/README.md +0 -0
  32. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/basics/__init__.py +0 -0
  33. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/basics/utils.py +0 -0
  34. {gamebox-0.2.0 → gamebox-0.9.0}/src/GameBox/player/_playerControler.py +0 -0
  35. {gamebox-0.2.0 → gamebox-0.9.0}/tests/levelTiles.png +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GameBox
3
- Version: 0.2.0
3
+ Version: 0.9.0
4
4
  Summary: GameBox is a beginner-friendly Python package built on top of pygame, designed to make 2D game development faster and easier. It provides ready-to-use modules, utilities, and abstractions that let new developers create polished games without needing advanced coding knowledge—while still offering the flexibility for experienced coders to customize and extend.
5
5
  Author-email: Sam Fertig <sfertig007@gmail.com>
6
6
  License-Expression: MIT
@@ -3,7 +3,7 @@ requires = ["hatchling >= 1.26"]
3
3
  build-backend = "hatchling.build"
4
4
  [project]
5
5
  name = "GameBox"
6
- version = "0.2.0"
6
+ version = "0.9.0"
7
7
  authors = [
8
8
  { name="Sam Fertig", email="sfertig007@gmail.com" },
9
9
  ]
@@ -0,0 +1,39 @@
1
+ import pygame
2
+ import numpy as np
3
+
4
+ from ..basics._net import Global
5
+
6
+ class Animation:
7
+ def __init__(self, image, tileDim, startPos, frames, dur):
8
+ if type(image) == str:
9
+ image = pygame.image.load(image)
10
+
11
+ #others
12
+ self.dur = dur
13
+ self.currentFrame = 0
14
+ self.currentDur = 0
15
+
16
+ #get frames from image
17
+ self.frames = []
18
+ x, y = startPos
19
+ x *= tileDim[0]
20
+ y *= tileDim[1]
21
+ for i in range(frames):
22
+ self.frames.append(image.subsurface(x, y, tileDim[0], tileDim[1]))
23
+ x += tileDim[0]
24
+ if x >= image.get_width():
25
+ x = 0
26
+ y += tileDim[1]
27
+
28
+ def update(self, dt):
29
+ self.currentDur += dt
30
+ if self.currentDur >= self.dur:
31
+ self.currentDur = 0
32
+ self.currentFrame += 1
33
+ if self.currentFrame >= len(self.frames):
34
+ self.currentFrame = 0
35
+
36
+ def getFrame(self):
37
+ return self.frames[self.currentFrame]
38
+
39
+
@@ -0,0 +1,243 @@
1
+ import pygame
2
+ import numpy as np
3
+
4
+ from ..basics._net import Global
5
+ from ._Animations import Animation
6
+
7
+ class Sprite_2d:
8
+ def __init__(self, pos: tuple, image, scale: float = 1.0, collision = True, dirrection: int = 1):
9
+ """
10
+ Initialize a 2D sprite.
11
+
12
+ Args:
13
+ pos: Tuple (x, y) for the sprite position
14
+ image: Either a file path (str) or pygame.Surface object
15
+ scale: Scale factor for the sprite (default: 1.0)
16
+ """
17
+ #add to game
18
+ Global.game.objs.append(self)
19
+ self.collision = collision
20
+ self.__worldPos__ = True
21
+ self.dir = dirrection
22
+
23
+ self.pos = pos
24
+ if type(image) == str:
25
+ self.image = pygame.image.load(image)
26
+ else:
27
+ self.image = image
28
+
29
+ #scale image
30
+ print(self.image)
31
+ self.image = pygame.transform.scale_by(self.image, scale)
32
+ #flip image
33
+ if self.dir == -1:
34
+ self.image = pygame.transform.flip(self.image, True, False)
35
+
36
+ def update(self):
37
+ #world space
38
+ x, y = self.pos
39
+ if self.__worldPos__:
40
+ x = x - Global.cam.x
41
+ y = y - Global.cam.y
42
+ Global.screen.blit(self.image, (x, y))
43
+ if self.collision:
44
+ rect = self.image.get_rect()
45
+ rect.x = x
46
+ rect.y = y
47
+ Global.collisions.append(rect)
48
+
49
+ def switch_dirrection(self):
50
+ self.image = pygame.transform.flip(self.image, True, False)
51
+
52
+
53
+ def move_by(self, x: int, y: int):
54
+ self.pos = (self.pos[0] + x, self.pos[1] + y)
55
+
56
+ def move_to(self, x: int, y: int):
57
+ self.pos = (x, y)
58
+
59
+ def get_pos(self):
60
+ return self.pos
61
+
62
+ def rescale(self, scale: float):
63
+ self.image = pygame.transform.scale_by(self.image, scale)
64
+
65
+ def __remove__(self):
66
+ Global.game.objs.remove(self)
67
+
68
+ def split_image(image, tileDim, startPos):
69
+ if type(image) == str:
70
+ image = pygame.image.load(image)
71
+ else:
72
+ image = image
73
+
74
+ #return image split
75
+ x = startPos[0] * tileDim[0]
76
+ y = startPos[1] * tileDim[1]
77
+ return image.subsurface((x, y, tileDim[0], tileDim[1]))
78
+
79
+ class Animated_Sprite2D:
80
+ """
81
+ A class for animated 2D sprites.
82
+
83
+ Args:
84
+ pos (tuple): The position of the sprite in world space.
85
+ image (str or pygame.Surface): The image of the sprite.
86
+ imageDim (tuple): The dimensions of the image.
87
+ tileDim (tuple): The dimensions of the tiles in the image.
88
+ frames (int): The number of frames in the animation.
89
+ speed (float): The speed of the animation.
90
+ scale (float): The scale of the sprite.
91
+ collision (bool): Whether the sprite has collision.
92
+ dirrection (int): The direction of the sprite.
93
+
94
+ Attributes:
95
+ animation (Animation): The animation of the sprite.
96
+ collision (bool): Whether the sprite has collision.
97
+ dir (int): The direction of the sprite.
98
+ pos (tuple): The position of the sprite in world space.
99
+ scale (float): The scale of the sprite.
100
+ image (pygame.Surface): The current frame of the animation.
101
+ __worldPos__ (bool): Whether the sprite is in world space.
102
+
103
+ Methods:
104
+ update (None): Updates the sprite.
105
+ __remove__ (None): Removes the sprite from the game.
106
+ switch_dirrection (None): Switches the direction of the sprite.
107
+ move_by (x, y): Moves the sprite by (x, y) in world space.
108
+ move_to (x, y): Moves the sprite to (x, y) in world space.
109
+ get_pos (None): Returns the position of the sprite in world space.
110
+ rescale (scale): Rescales the sprite by the given scale.
111
+ """
112
+
113
+ def __init__(self, pos, image, imageDim, tileDim, frames, speed, scale = 1.0, collision = True, dirrection = 1):
114
+ """
115
+
116
+ """
117
+
118
+ self.animation = Animation(image, tileDim, (0, 0), frames, speed)
119
+ self.collision = collision
120
+ self.dir = dirrection
121
+ self.pos = pos
122
+
123
+ self.scale = scale
124
+ self.image = pygame.transform.scale_by(self.animation.getFrame(), scale)
125
+ if self.dir == -1:
126
+ self.image = pygame.transform.flip(self.image, True, False)
127
+
128
+ self.__worldPos__ = True
129
+
130
+ #add to game
131
+ Global.game.objs.append(self)
132
+
133
+ def update(self):
134
+ self.animation.update(Global.dt)
135
+ self.image = pygame.transform.scale_by(self.animation.getFrame(), self.scale)
136
+ if self.dir == -1:
137
+ self.image = pygame.transform.flip(self.image, True, False)
138
+
139
+ #world space
140
+ x, y = self.pos
141
+ if self.__worldPos__:
142
+ x = x - Global.cam.x
143
+ y = y - Global.cam.y
144
+ Global.screen.blit(self.image, (x, y))
145
+ if self.collision:
146
+ rect = self.image.get_rect()
147
+ rect.x = x
148
+ rect.y = y
149
+ Global.collisions.append(rect)
150
+
151
+ def __remove__(self):
152
+ Global.game.objs.remove(self)
153
+
154
+ def switch_dirrection(self):
155
+ self.image = pygame.transform.flip(self.image, True, False)
156
+
157
+ def move_by(self, x: int, y: int):
158
+ self.pos = (self.pos[0] + x, self.pos[1] + y)
159
+
160
+ def move_to(self, x: int, y: int):
161
+ self.pos = (x, y)
162
+
163
+ def get_pos(self):
164
+ return self.pos
165
+
166
+ def rescale(self, scale: float):
167
+ self.image = pygame.transform.scale_by(self.image, scale)
168
+
169
+ class AnimationPlayer2D:
170
+ """
171
+ Class for playing animations in a 2D game.
172
+
173
+ Attributes:
174
+ pos (tuple): Position of the AnimationPlayer2D.
175
+ scale (float): Scale of the AnimationPlayer2D.
176
+ anims (dict): Dictionary of animations that can be played, where the key is the name of the animation and the value is an instance of Animated_Sprite2D.
177
+ currentAnim (str): The name of the currently playing animation.
178
+
179
+ Methods:
180
+ update (None): Updates the currently playing animation.
181
+ add_animation (name, image, imageDim, tileDim, frames, speed, scale = 1.0, collision = True, dirrection = 1): Adds an animation to the AnimationPlayer2D.
182
+ remove_animation (name: str): Removes an animation from the AnimationPlayer2D.
183
+ set_worldPos (worldPos: bool): Sets the world position of all animations in the AnimationPlayer2D.
184
+ __remove__ (None): Removes the AnimationPlayer2D from the game.
185
+ set_scale (scale: float): Sets the scale of all animations in the AnimationPlayer2D.
186
+ set_animation (anim: str): Sets the currently playing animation.
187
+ move_by (x, y): Moves the AnimationPlayer2D by (x, y) in world space.
188
+ move_to (x, y): Moves the AnimationPlayer2D to (x, y) in world space.
189
+ get_pos (None): Returns the position of the AnimationPlayer2D in world space.
190
+ """
191
+ def __init__(self, pos, scale):
192
+ self.pos = pos
193
+ self.scale = scale
194
+ self.anims = {}
195
+ self.currentAnim = None
196
+
197
+ self.__worldPos__ = True
198
+
199
+ #add to game
200
+ Global.game.objs.append(self)
201
+
202
+ def update(self):
203
+ if self.currentAnim is not None:
204
+ self.anims[self.currentAnim].update()
205
+
206
+ def add_animation(self, name, image, imageDim, tileDim, frames, speed, scale = 1.0, collision = True, dirrection = 1):
207
+ self.anims[name] = Animated_Sprite2D(self.pos, image, imageDim, tileDim, frames, speed, scale, collision, dirrection)
208
+ self.currentAnim = name
209
+ self.anims[self.currentAnim].__remove__()
210
+
211
+ def remove_animation(self, name: str):
212
+ self.anims[name].__remove__()
213
+ del self.anims[name]
214
+
215
+ def set_worldPos(self, worldPos: bool):
216
+ for anim in self.anims:
217
+ self.anims[anim].__worldPos__ = worldPos
218
+
219
+ def __remove__(self):
220
+ if self in Global.game.objs:
221
+ Global.game.objs.remove(self)
222
+
223
+ def set_scale(self, scale: float):
224
+ for anim in self.anims:
225
+ self.anims[anim].rescale(scale)
226
+
227
+ def set_animation(self, anim: str):
228
+ self.currentAnim = anim
229
+
230
+ def move_by(self, x: int, y: int):
231
+ self.pos = (self.pos[0] + x, self.pos[1] + y)
232
+ for anim in self.anims:
233
+ self.anims[anim].move_by(x, y)
234
+
235
+ def move_to(self, x: int, y: int):
236
+ self.pos = (x, y)
237
+ for anim in self.anims:
238
+ self.anims[anim].move_to(x, y)
239
+
240
+ def get_pos(self):
241
+ return self.pos
242
+
243
+
@@ -5,7 +5,7 @@ GameBox makes it easy to build 2D games with graphics, sound, and UI in just a f
5
5
  """
6
6
 
7
7
 
8
- __version__ = "0.1.3"
8
+ __version__ = "0.3.0"
9
9
  __author__ = "Sam Fertig"
10
10
 
11
11
  #____imports____
@@ -16,6 +16,10 @@ from .player._player import Player
16
16
  from .basics.utils import clamp, moveTward, zeroOut
17
17
  from .tilemap._tilemap import TileMap
18
18
  from.helpers._input import Keys
19
+ from .ui._basicUI import Image
20
+
21
+ from .GameLevel_ui._sprites import Sprite_2d, Animated_Sprite2D, AnimationPlayer2D, split_image
22
+ from.helpers._Conditions import Conditions
19
23
 
20
24
 
21
25
  __all__ = [
@@ -28,5 +32,11 @@ __all__ = [
28
32
  "zeroOut",
29
33
  "TileMap",
30
34
  "Keys",
35
+ "Image",
36
+ "Sprite_2d",
37
+ "Animated_Sprite2D",
38
+ "AnimationPlayer2D",
39
+ "split_image",
40
+ "Conditions",
31
41
  ]
32
42
 
@@ -26,6 +26,7 @@ class Game:
26
26
  Global.clock = pygame.time.Clock()
27
27
  Global.game = self
28
28
  self.objs = []
29
+ self.ui_objs = []
29
30
 
30
31
 
31
32
  def update(self, event: pygame.event,frame_rate=60):
@@ -40,6 +41,11 @@ class Game:
40
41
  if type(obj) == Player: player = obj
41
42
  else: obj.update()
42
43
  if player != None: player.update()
44
+
45
+ #update ui
46
+ for obj in self.ui_objs:
47
+ obj.update()
48
+
43
49
  pygame.display.update()
44
50
 
45
51
  def get_screen(self):
@@ -18,6 +18,8 @@ class _global_:
18
18
  #-collisions
19
19
  self.collisions: list[pygame.Rect] = []
20
20
 
21
+ self.cond: object = None
22
+
21
23
  #objects
22
24
  self.player = self._player()
23
25
  self.tilemap = []
@@ -0,0 +1,88 @@
1
+ import pygame
2
+ import numpy as np
3
+
4
+ from ..basics._net import Global
5
+
6
+ class Rect:
7
+ """
8
+ A rectangle shape used for rendering and collision detection.
9
+
10
+ Args:
11
+ pos (tuple): The position of the rectangle.
12
+ size (tuple): The size of the rectangle.
13
+ color (tuple, optional): The color of the rectangle. Defaults to (0,0,0).
14
+ collision (bool, optional): Whether the rectangle should be used for collision detection. Defaults to True.
15
+ """
16
+
17
+ def __init__(self, pos: tuple, size: tuple, color: tuple = (0, 0, 0), collision: bool = True):
18
+ """
19
+ Initialize the rectangle object.
20
+
21
+ Args:
22
+ pos (tuple): The position of the rectangle.
23
+ size (tuple): The size of the rectangle.
24
+ color (tuple, optional): The color of the rectangle. Defaults to (0,0,0).
25
+ collision (bool, optional): Whether the rectangle should be used for collision detection. Defaults to True.
26
+ """
27
+ self.x, self.y = pos
28
+ self.width, self.height = size
29
+ self.color = color
30
+ Global.game.objs.append(self)
31
+ self.collision = collision
32
+
33
+ def update(self):
34
+ """
35
+ Update the rectangle object.
36
+
37
+ This method updates the position and size of the rectangle based on the camera's position and scale.
38
+ It then renders the rectangle to the screen and adds it to the collision detection list if necessary.
39
+ """
40
+ width = self.width * Global.cam.scale
41
+ height = self.height * Global.cam.scale
42
+ if (Global.cam.follow) != (self):
43
+ x = self.x - Global.cam.x
44
+ y = self.y - Global.cam.y
45
+ elif (Global.cam.follow) == (self):
46
+ x = self.x
47
+ y = self.y
48
+
49
+ rect = pygame.Rect(x, y, width, height)
50
+ if self.collision: Global.collisions.append(rect)
51
+ pygame.draw.rect(Global.screen, self.color, rect)
52
+
53
+ def move(self, x, y):
54
+ """
55
+ Move the rectangle object.
56
+
57
+ Args:
58
+ x (int): The x-coordinate to move the rectangle by.
59
+ y (int): The y-coordinate to move the rectangle by.
60
+ """
61
+ if (Global.cam.follow) != (self):
62
+ self.x += x
63
+ self.y += y
64
+ else:
65
+ Global.cam._move(x, y)
66
+
67
+ def move_to(self, x, y):
68
+ """
69
+ Move the rectangle object to a specific position.
70
+
71
+ Args:
72
+ x (int): The x-coordinate to move the rectangle to.
73
+ y (int): The y-coordinate to move the rectangle to.
74
+ """
75
+ if (Global.cam.follow) != (self):
76
+ self.x = x
77
+ self.y = y
78
+ else:
79
+ Global.cam.x = x
80
+ Global.cam.y = y
81
+
82
+ def __remove__(self):
83
+ """
84
+ Remove the rectangle object from the game.
85
+
86
+ This method removes the rectangle object from the game's object list.
87
+ """
88
+ Global.game.objs.remove(self)
@@ -0,0 +1,75 @@
1
+ import pygame
2
+ import numpy as np
3
+
4
+ from ._net import Global
5
+
6
+ from ..basics.utils import moveTward
7
+
8
+ class Cammera:
9
+ """
10
+ A class for the camera object.
11
+ """
12
+
13
+ def __init__(self, scale: float = 1.0):
14
+ """
15
+ Initialize the camera object.
16
+
17
+ Args:
18
+ scale (float): The scale of the camera (default: 1.0)
19
+ """
20
+ self.x = 0
21
+ self.y = 0
22
+ Global.game.objs.append(self)
23
+ Global.cam = self
24
+ self.follow = None
25
+ self.diff = (0, 0)
26
+ self.scale = scale
27
+
28
+ def _move(self, x: int, y: int):
29
+ """
30
+ Move the camera by (x, y).
31
+
32
+ Args:
33
+ x (int): The x component of the movement
34
+ y (int): The y component of the movement
35
+ """
36
+ self.x += x
37
+ self.y += y
38
+
39
+ def update(self):
40
+ """
41
+ Update the camera position based on the follow target.
42
+ """
43
+ return
44
+ if self.follow is not None:
45
+ self.x = (self.follow.x - self.diff[0])
46
+ self.y = (self.follow.y - self.diff[1])
47
+
48
+ def set_follow_target(self, target: object):
49
+ """
50
+ Set the follow target for the camera.
51
+
52
+ Args:
53
+ target (object): The object to follow
54
+ """
55
+ self.follow = target
56
+ print(target)
57
+ self.diff = (target.x - self.x, target.y - self.y)
58
+
59
+ def set_scale(self, scale: float = 1.0):
60
+ """
61
+ Set the scale of the camera.
62
+
63
+ Args:
64
+ scale (float): The scale of the camera (default: 1.0)
65
+ """
66
+ self.scale = scale
67
+
68
+ def change_scale(self, scale: float = 1.0):
69
+ """
70
+ Change the scale of the camera by the given amount.
71
+
72
+ Args:
73
+ scale (float): The amount to change the scale by (default: 1.0)
74
+ """
75
+ self.scale += scale
@@ -0,0 +1,65 @@
1
+ import pygame
2
+ import numpy as np
3
+
4
+ from ..basics.utils import zeroOut
5
+ from ..basics._net import Global
6
+
7
+ class _Conditions:
8
+ """
9
+ Class containing the predefined conditions for the game.
10
+ Conditions are in the format of 'C' followed by the command ('v' for velocity), and dir (^ up, _ down, < left, > right, # none, ~ any)
11
+ """
12
+
13
+ def __init__(self):
14
+ """
15
+ Initialize the conditions.
16
+ """
17
+ # conditions start with 'C' and then command ('v' for velocity), and dir (^ up, _ down, < left, > right, # none, ~ any)
18
+ self.velocity_up = 'CV^' # velocity up
19
+ self.velocity_down = 'CV_' # velocity down
20
+ self.velocity_left = 'CV<' # velocity left
21
+ self.velocity_right = 'CV>' # velocity right
22
+ self.velocity_none = 'CV#' # velocity none
23
+ self.velocity_any = 'CV~' # velocity any
24
+
25
+ Conditions = _Conditions()
26
+ Global.cond = Conditions
27
+
28
+ class Condition_check:
29
+ def __init__(self, stateTree: dict[str, dict[_Conditions, str]], currentState: str):
30
+ self.stateTree = stateTree
31
+ self.currentState = currentState
32
+
33
+ def check(self, velocity: tuple, pos: tuple):
34
+ state = self.stateTree[self.currentState]
35
+ for cond, next in state.items():
36
+ #velocities
37
+ if cond[1] == 'V':
38
+ if self._resolve_velocities(velocity, cond):
39
+ self.currentState = next
40
+ return next
41
+ return self.currentState
42
+
43
+
44
+ def _resolve_velocities(self, velocities, cond):
45
+ vx, vy = velocities
46
+ Max = 0.3
47
+ vx = zeroOut(vx, Max)
48
+ vy = zeroOut(vy, Max)
49
+ dir = cond[2]
50
+ print(vx, vy, dir)
51
+ #resolve in order up, down, left, right, none, any
52
+ if dir == "^" and vy < 0: return True
53
+ if dir == "_" and vy > 0: return True
54
+ if dir == "<" and vx < 0: return True
55
+ if dir == ">" and vx > 0: return True
56
+ if dir == "#" and vx == 0 and vy == 0: return True
57
+ if dir == "~" and (vx != 0 or vy != 0): return True
58
+ return False
59
+
60
+ def updateState(self, state: str):
61
+ self.currentState = state
62
+ def updateStateTree(self, stateTree: dict[str, dict[_Conditions, str]]):
63
+ self.stateTree = stateTree
64
+
65
+
@@ -7,7 +7,6 @@ from ..basics._net import Global
7
7
  def CheckCollisions(x, y, vx, vy, dim, sample, obj):
8
8
  x, y = x + vx, y + vy
9
9
 
10
-
11
10
  #basic object collisions
12
11
  x, y, vx, vy = _mainCollisionLogic(Global.collisions, x, y, vx, vy, dim)
13
12
  x, y, vx, vy = _checkTilemapCollisions(x, y, vx, vy, dim, sample, obj)
@@ -15,20 +14,12 @@ def CheckCollisions(x, y, vx, vy, dim, sample, obj):
15
14
  return x, y, vx, vy
16
15
 
17
16
  def _mainCollisionLogic(collisions, x, y, vx, vy, dim):
18
- new_rect = pygame.Rect((x, y), dim)
19
- for collision in collisions:
20
- #pygame.draw.rect(Global.screen, (255, 0, 0), collision, 1)
21
- if collision.colliderect(new_rect):
22
- if vx > 0:
23
- x = collision.left - dim[0]
24
- elif vx < 0:
25
- x = collision.right
26
- vx = 0
27
-
28
17
  # Y-axis collisions
18
+ py = y
29
19
  new_rect = pygame.Rect((x, y), dim)
20
+ pygame.draw.rect(Global.screen, "green", new_rect, 5)
30
21
  for collision in collisions:
31
- #pygame.draw.rect(Global.screen, (255, 0, 0), collision, 1)
22
+ pygame.draw.rect(Global.screen, "yellow", collision, 5)
32
23
  if collision.colliderect(new_rect):
33
24
  if vy > 0: # falling
34
25
  y = collision.top - dim[1]
@@ -36,6 +27,16 @@ def _mainCollisionLogic(collisions, x, y, vx, vy, dim):
36
27
  elif vy < 0: # jumping
37
28
  y = collision.bottom
38
29
  vy = 0
30
+
31
+ new_rect = pygame.Rect((x, py), dim)
32
+ for collision in collisions:
33
+ pygame.draw.rect(Global.screen, "yellow", collision, 5)
34
+ if collision.colliderect(new_rect):
35
+ if vx > 0:
36
+ x = collision.left - dim[0]
37
+ elif vx < 0:
38
+ x = collision.right
39
+ vx = 0
39
40
 
40
41
  return x, y, vx, vy
41
42
 
@@ -4,6 +4,9 @@ from ..basics._net import Global
4
4
 
5
5
 
6
6
  class _keys:
7
+ """
8
+ A class that holds all the key bindings for the game
9
+ """
7
10
  def __init__(self):
8
11
 
9
12
  #alphabet
@@ -61,6 +64,7 @@ class _keys:
61
64
 
62
65
  #mouse
63
66
  self.mouse_x, self.mouse_y = 0, 0
67
+
64
68
  def init(self): Global.game.objs.append(self)
65
69
 
66
70
  def is_pressed(self, key):