GameBox 0.9.0__tar.gz → 0.9.1__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 (34) hide show
  1. {gamebox-0.9.0 → gamebox-0.9.1}/PKG-INFO +1 -1
  2. {gamebox-0.9.0 → gamebox-0.9.1}/pyproject.toml +1 -1
  3. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/GameLevel_ui/_sprites.py +1 -59
  4. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/_game.py +21 -0
  5. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/basics/_net.py +2 -0
  6. gamebox-0.9.1/src/GameBox/basics/_shapes.py +44 -0
  7. gamebox-0.9.1/src/GameBox/basics/cammera.py +36 -0
  8. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/helpers/_Conditions.py +9 -18
  9. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/helpers/_collisions.py +6 -3
  10. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/helpers/_input.py +0 -4
  11. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/player/_player.py +1 -18
  12. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/player/_playerSprite.py +3 -3
  13. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/tilemap/_tilemap.py +0 -14
  14. gamebox-0.9.1/src/GameBox/ui/_basicUI.py +36 -0
  15. {gamebox-0.9.0 → gamebox-0.9.1}/tests/GettingStarted.py +9 -7
  16. {gamebox-0.9.0 → gamebox-0.9.1}/tests/basicScreen.py +1 -1
  17. gamebox-0.9.0/src/GameBox/basics/_shapes.py +0 -88
  18. gamebox-0.9.0/src/GameBox/basics/cammera.py +0 -75
  19. gamebox-0.9.0/src/GameBox/ui/_basicUI.py +0 -65
  20. {gamebox-0.9.0 → gamebox-0.9.1}/.gitignore +0 -0
  21. {gamebox-0.9.0 → gamebox-0.9.1}/LICENSE +0 -0
  22. {gamebox-0.9.0 → gamebox-0.9.1}/README.md +0 -0
  23. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/GameLevel_ui/_Animations.py +0 -0
  24. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/__init__.py +0 -0
  25. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/basics/__init__.py +0 -0
  26. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/basics/utils.py +0 -0
  27. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/player/_playerControler.py +0 -0
  28. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/player/_playerPhysics.py +0 -0
  29. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/tilemap/_Editor.py +0 -0
  30. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/tilemap/_collisionDef.py +0 -0
  31. {gamebox-0.9.0 → gamebox-0.9.1}/src/GameBox/tilemap/_editorBrushes.py +0 -0
  32. {gamebox-0.9.0 → gamebox-0.9.1}/tests/Player.png +0 -0
  33. {gamebox-0.9.0 → gamebox-0.9.1}/tests/levelTiles.png +0 -0
  34. {gamebox-0.9.0 → gamebox-0.9.1}/tests/testMap.json +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GameBox
3
- Version: 0.9.0
3
+ Version: 0.9.1
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.9.0"
6
+ version = "0.9.1"
7
7
  authors = [
8
8
  { name="Sam Fertig", email="sfertig007@gmail.com" },
9
9
  ]
@@ -77,44 +77,7 @@ def split_image(image, tileDim, startPos):
77
77
  return image.subsurface((x, y, tileDim[0], tileDim[1]))
78
78
 
79
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
80
  def __init__(self, pos, image, imageDim, tileDim, frames, speed, scale = 1.0, collision = True, dirrection = 1):
114
- """
115
-
116
- """
117
-
118
81
  self.animation = Animation(image, tileDim, (0, 0), frames, speed)
119
82
  self.collision = collision
120
83
  self.dir = dirrection
@@ -167,27 +130,6 @@ class Animated_Sprite2D:
167
130
  self.image = pygame.transform.scale_by(self.image, scale)
168
131
 
169
132
  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
133
  def __init__(self, pos, scale):
192
134
  self.pos = pos
193
135
  self.scale = scale
@@ -218,7 +160,7 @@ class AnimationPlayer2D:
218
160
 
219
161
  def __remove__(self):
220
162
  if self in Global.game.objs:
221
- Global.game.objs.remove(self)
163
+ Global.game.objs.remove(self)\
222
164
 
223
165
  def set_scale(self, scale: float):
224
166
  for anim in self.anims:
@@ -57,4 +57,25 @@ class Game:
57
57
  if hasattr(obj, "_quit") and callable(obj._quit):
58
58
  obj._quit()
59
59
 
60
+ def _set_debug(self, debug: bool):
61
+ """
62
+ Set the debug mode for the game. This will show / hide debuging information
63
+ like collisions. Note: This feture is for development and testing purposes only.
64
+
65
+ Parameters:
66
+ debug (bool): The debug mode.
67
+
68
+ Returns:
69
+ None
70
+ """
71
+ Global._debug = debug
72
+ def _get_debug_state(self):
73
+ """
74
+ Get the debug mode for the game.
75
+
76
+ Returns:
77
+ bool: The debug mode.
78
+ """
79
+ return Global._debug
80
+
60
81
 
@@ -20,6 +20,8 @@ class _global_:
20
20
 
21
21
  self.cond: object = None
22
22
 
23
+ self._debug: bool = False
24
+
23
25
  #objects
24
26
  self.player = self._player()
25
27
  self.tilemap = []
@@ -0,0 +1,44 @@
1
+ import pygame
2
+ import numpy as np
3
+
4
+ from ..basics._net import Global
5
+
6
+ class Rect:
7
+ def __init__(self, pos: tuple, size: tuple, color: tuple = (0, 0, 0), collision: bool = True):
8
+ self.x, self.y = pos
9
+ self.width, self.height = size
10
+ self.color = color
11
+ Global.game.objs.append(self)
12
+ self.collision = collision
13
+
14
+ def update(self):
15
+ width = self.width * Global.cam.scale
16
+ height = self.height * Global.cam.scale
17
+ if (Global.cam.follow) != (self):
18
+ x = self.x - Global.cam.x
19
+ y = self.y - Global.cam.y
20
+ elif (Global.cam.follow) == (self):
21
+ x = self.x
22
+ y = self.y
23
+
24
+ rect = pygame.Rect(x, y, width ,height)
25
+ if self.collision: Global.collisions.append(rect)
26
+ pygame.draw.rect(Global.screen, self.color, rect)
27
+
28
+ def move(self, x, y):
29
+ if (Global.cam.follow) != (self):
30
+ self.x += x
31
+ self.y += y
32
+ else:
33
+ Global.cam._move(x, y)
34
+
35
+ def move_to(self, x, y):
36
+ if (Global.cam.follow) != (self):
37
+ self.x = x
38
+ self.y = y
39
+ else:
40
+ Global.cam.x = x
41
+ Global.cam.y = y
42
+
43
+ def __remove__(self):
44
+ Global.game.objs.remove(self)
@@ -0,0 +1,36 @@
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
+ def __init__(self, scale: float = 1.0):
10
+ self.x = 0
11
+ self.y = 0
12
+ Global.game.objs.append(self)
13
+ Global.cam = self
14
+ self.follow = None
15
+ self.diff = (0, 0)
16
+ self.scale = scale
17
+
18
+ def _move(self, x: int, y: int):
19
+ self.x += x
20
+ self.y += y
21
+
22
+ def update(self):
23
+ return
24
+ if self.follow is not None:
25
+ self.x = (self.follow.x - self.diff[0])
26
+ self.y = (self.follow.y - self.diff[1])
27
+
28
+ def set_follow_target(self, target: object):
29
+ self.follow = target
30
+ print(target)
31
+ self.diff = (target.x - self.x, target.y - self.y)
32
+
33
+ def set_scale(self, scale: float = 1.0):
34
+ self.scale = scale
35
+ def change_scale(self, scale: float = 1.0):
36
+ self.scale += scale
@@ -5,22 +5,14 @@ from ..basics.utils import zeroOut
5
5
  from ..basics._net import Global
6
6
 
7
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
8
  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
9
+ #conditions start with 'C' and then command ('v' for velocity), and dir (^ up, _ down, < left, > right, # none, ~ any)
10
+ self.velocity_up = 'CV^'
11
+ self.velocity_down = 'CV_'
12
+ self.velocity_left = 'CV<'
13
+ self.velocity_right = 'CV>'
14
+ self.velocity_none = 'CV#'
15
+ self.velocity_any = 'CV~'
24
16
 
25
17
  Conditions = _Conditions()
26
18
  Global.cond = Conditions
@@ -43,9 +35,8 @@ class Condition_check:
43
35
 
44
36
  def _resolve_velocities(self, velocities, cond):
45
37
  vx, vy = velocities
46
- Max = 0.3
47
- vx = zeroOut(vx, Max)
48
- vy = zeroOut(vy, Max)
38
+ vx = zeroOut(vx, 0.1)
39
+ vy = zeroOut(vy, 0.1)
49
40
  dir = cond[2]
50
41
  print(vx, vy, dir)
51
42
  #resolve in order up, down, left, right, none, any
@@ -17,9 +17,11 @@ def _mainCollisionLogic(collisions, x, y, vx, vy, dim):
17
17
  # Y-axis collisions
18
18
  py = y
19
19
  new_rect = pygame.Rect((x, y), dim)
20
- pygame.draw.rect(Global.screen, "green", new_rect, 5)
20
+ if Global._debug:
21
+ pygame.draw.rect(Global.screen, "green", new_rect, 5)
21
22
  for collision in collisions:
22
- pygame.draw.rect(Global.screen, "yellow", collision, 5)
23
+ if Global._debug:
24
+ pygame.draw.rect(Global.screen, "yellow", collision, 5)
23
25
  if collision.colliderect(new_rect):
24
26
  if vy > 0: # falling
25
27
  y = collision.top - dim[1]
@@ -30,7 +32,8 @@ def _mainCollisionLogic(collisions, x, y, vx, vy, dim):
30
32
 
31
33
  new_rect = pygame.Rect((x, py), dim)
32
34
  for collision in collisions:
33
- pygame.draw.rect(Global.screen, "yellow", collision, 5)
35
+ if Global._debug:
36
+ pygame.draw.rect(Global.screen, "yellow", collision, 5)
34
37
  if collision.colliderect(new_rect):
35
38
  if vx > 0:
36
39
  x = collision.left - dim[0]
@@ -4,9 +4,6 @@ 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
- """
10
7
  def __init__(self):
11
8
 
12
9
  #alphabet
@@ -64,7 +61,6 @@ class _keys:
64
61
 
65
62
  #mouse
66
63
  self.mouse_x, self.mouse_y = 0, 0
67
-
68
64
  def init(self): Global.game.objs.append(self)
69
65
 
70
66
  def is_pressed(self, key):
@@ -9,38 +9,21 @@ from ..player._playerSprite import _playerSprite
9
9
  from ..GameLevel_ui._sprites import Sprite_2d
10
10
 
11
11
  class Player:
12
- """
13
- Initialize a Player object.
14
-
15
- Parameters:
16
- pos (tuple): The position of the Player in world space.
17
- size (tuple): The size of the Player in world space.
18
- color (tuple): The color of the Player (default: (0, 0, 0)).
19
- gravity (bool): Whether the Player is affected by gravity (default: False).
20
-
21
- Returns:
22
- None
23
- """
24
12
  def __init__(self, pos: tuple, size: tuple, color: tuple = (0, 0, 0), gravity: bool = False):
25
- # Set the position and size of the Player
26
13
  self.x, self.y = pos
27
14
  self.screenPos = pos
28
15
  self.dim = size
29
16
  self.color = color
30
17
  self.width, self.height = size
31
18
 
32
- # Set whether the Player is affected by gravity
33
19
  self.gravity = gravity
34
20
 
35
- # State of the Player (e.g. "jumping", "standing", etc.)
36
21
  self.state = ""
37
-
38
- # Add the Player to the game
22
+
39
23
  Global.game.objs.append(self)
40
24
  Global.player.pos = pos
41
25
  Global.player.player = self
42
26
 
43
- # Initialize the sprite for the Player
44
27
  self.sprite = _playerSprite(self)
45
28
 
46
29
 
@@ -50,7 +50,7 @@ class _playerSprite:
50
50
  self.sprite.__worldPos__ = False
51
51
  self.sprite.__remove__()
52
52
 
53
- def add_animated_sprite_2d(self, image, imageDim, tileDim, frames, speed, scale = 1.0, collision = False, dirrection = 1):
53
+ def add_animated_sprite_2d(self, image, imageDim, tileDim, frames, speed, scale = 1.0, collision = True, dirrection = 1):
54
54
  self.sprite = Animated_Sprite2D((self.player.x, self.player.y), image, imageDim, tileDim, frames, speed, scale, collision, dirrection)
55
55
  if Global.cam.follow == self.player:
56
56
  self.sprite.__worldPos__ = False
@@ -66,8 +66,8 @@ class _playerSprite:
66
66
  self.sprite.set_worldPos(False)
67
67
  self.sprite.__remove__()
68
68
 
69
- def add_animation(self, name, image, imageDim, tileDim, frames, speed, scale = 1.0, collision = True, dirrection = 1):
70
- self.sprite.add_animation(name, image, imageDim, tileDim, frames, speed, scale, collision, dirrection)
69
+ def add_animation(self, name, image, imageDim, tileDim, frames, speed, scale = 1.0, dirrection = 1):
70
+ self.sprite.add_animation(name, image, imageDim, tileDim, frames, speed, scale, False, dirrection)
71
71
  self.sprite.__remove__()
72
72
  self.sprite.set_worldPos(False)
73
73
 
@@ -9,20 +9,6 @@ from ._Editor import _tilemapEditor
9
9
 
10
10
  class TileMap:
11
11
  def __init__(self, tileSet: str, tileDim: tuple, tileScale: float, mapDim: tuple, mapFill: int, saveFile = None):
12
- """
13
- Constructor for TileMap object.
14
-
15
- Args:
16
- tileSet (str): filepath to tileset image
17
- tileDim (tuple): dimensions of a single tile
18
- tileScale (float): scale of tiles relative to tileset image
19
- mapDim (tuple): dimensions of the map
20
- mapFill (int): default tile id to fill map with
21
- saveFile (str): filepath to save map to (default is None)
22
-
23
- Returns:
24
- None
25
- """
26
12
  self.tilesetFile = tileSet
27
13
  self.mapFile = saveFile
28
14
  self.tileDim = (tileDim[0] * tileScale, tileDim[1] * tileScale)
@@ -0,0 +1,36 @@
1
+ import pygame
2
+ import numpy as np
3
+
4
+ from ..basics._net import Global
5
+
6
+ from ..GameLevel_ui._sprites import Sprite_2d
7
+
8
+ class Image:
9
+ def __init__(self, pos: tuple, image, scale: float = 1.0):
10
+ """
11
+ Initialize an Image UI element.
12
+
13
+ Args:
14
+ pos: Tuple (x, y) for the image position
15
+ image: Either a file path (str) or pygame.Surface object
16
+ scale: Scale factor for the image (default: 1.0)
17
+ """
18
+ #add to game
19
+ self.image = Sprite_2d(pos, image, scale)
20
+ self.image.__remove__()
21
+ Global.game.ui_objs.append(self)
22
+
23
+ def move_by(self, x: int, y: int):
24
+ self.image.move_by(x, y)
25
+
26
+ def move_to(self, x: int, y: int):
27
+ self.image.move_to(x, y)
28
+
29
+ def get_pos(self):
30
+ return self.image.get_pos()
31
+
32
+ def rescale(self, scale: float):
33
+ self.image.rescale(scale)
34
+
35
+ def update(self):
36
+ Global.screen.blit(self.image.image, self.image.pos)
@@ -15,19 +15,17 @@ player = Player((width / 2, height / 2), (64, 64), "green", False)
15
15
  player.add_physics(1.0, 3.0, 16, 7.0, 0.5)
16
16
 
17
17
  player.sprite.add_animation_player(2.0)
18
- player.sprite.add_animation("Walk Left", "tests/Player.png", (5, 1), (32, 32), 5, 0.075, 2.0, True, -1)
19
- player.sprite.add_animation("Walk Right", "tests/Player.png", (5, 1), (32, 32), 5, 0.075, 2.0, True, 1)
20
- player.sprite.add_animation("Idle", "tests/Player.png", (5, 1), (32, 32), 1, 0.075, 2.0, True, 1)
18
+ player.sprite.add_animation("Walk", "tests/Player.png", (5, 1), (32, 32), 5, 0.075, 2.0, 1)
19
+ player.sprite.add_animation("Idle", "tests/Player.png", (5, 1), (32, 32), 1, 0.075, 2.0, 1)
21
20
 
22
21
  player.sprite.set_animation("Idle")
23
22
 
24
23
 
25
24
  stateTree = {
26
- "Idle": {Conditions.velocity_left: "Walk Left", Conditions.velocity_right: "Walk Right"},
27
- "Walk Left": {Conditions.velocity_none: "Idle", Conditions.velocity_right: "Walk Right"},
28
- "Walk Right": {Conditions.velocity_none: "Idle", Conditions.velocity_left: "Walk Left"}
25
+ "Idle": {Conditions.velocity_any: "Walk"},
26
+ "Walk": {Conditions.velocity_none: "Idle"}
29
27
  }
30
- player.sprite.set_states(stateTree, "Idle")
28
+ player.sprite.set_states(stateTree, "Walk")
31
29
 
32
30
  rect = Rect((width / 2, height / 4), (64, 64), "red", True)
33
31
 
@@ -46,6 +44,10 @@ while running:
46
44
  #print player state
47
45
  os.system("cls")
48
46
  print(player.sprite.state)
47
+
48
+ if Keys.is_pressed(pygame.K_i):
49
+ game._set_debug(not game._get_debug_state())
50
+
49
51
 
50
52
  game.quit()
51
53
  pygame.quit()
@@ -10,7 +10,7 @@ Keys.init()
10
10
 
11
11
  cam = Cammera()
12
12
 
13
- player = Player((width / 2, height / 4), (50, 50), "green", False)
13
+ player = Player((width / 2, height / 4), (64, 64), "green", False)
14
14
  player.add_physics(1.0, 3.0, 16, 7.0, 0.5)
15
15
 
16
16
  map = TileMap("tests/levelTiles.png", (16, 16), 5, (25, 25), 0)
@@ -1,88 +0,0 @@
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)
@@ -1,75 +0,0 @@
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
@@ -1,65 +0,0 @@
1
- import pygame
2
- import numpy as np
3
-
4
- from ..basics._net import Global
5
-
6
- from ..GameLevel_ui._sprites import Sprite_2d
7
-
8
- class Image:
9
- def __init__(self, pos: tuple, image, scale: float = 1.0):
10
- """
11
- Initialize an Image UI element.
12
-
13
- Args:
14
- pos: Tuple (x, y) for the image position
15
- image: Either a file path (str) or pygame.Surface object
16
- scale: Scale factor for the image (default: 1.0)
17
- """
18
- #add to game
19
- self.image = Sprite_2d(pos, image, scale)
20
- self.image.__remove__()
21
- Global.game.ui_objs.append(self)
22
-
23
- def move_by(self, x: int, y: int):
24
- """
25
- Move the image by (x, y) in world space.
26
-
27
- Args:
28
- x: int, the x component of the movement
29
- y: int, the y component of the movement
30
- """
31
- self.image.move_by(x, y)
32
-
33
- def move_to(self, x: int, y: int):
34
- """
35
- Move the image to (x, y) in world space.
36
-
37
- Args:
38
- x: int, the x component of the position
39
- y: int, the y component of the position
40
- """
41
- self.image.move_to(x, y)
42
-
43
- def get_pos(self):
44
- """
45
- Get the position of the image in world space.
46
-
47
- Returns:
48
- tuple: (x, y) the position of the image
49
- """
50
- return self.image.get_pos()
51
-
52
- def rescale(self, scale: float):
53
- """
54
- Rescale the image by the given scale.
55
-
56
- Args:
57
- scale: float, the scale factor
58
- """
59
- self.image.rescale(scale)
60
-
61
- def update(self):
62
- """
63
- Update the image by drawing it on the screen.
64
- """
65
- Global.screen.blit(self.image.image, self.image.pos)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes