GameBox 0.0.5__py3-none-any.whl → 0.1.0__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.
- GameBox/__init__.py +9 -18
- GameBox/_game.py +38 -0
- GameBox/basics/_net.py +29 -0
- GameBox/basics/_shapes.py +23 -0
- GameBox/basics/cammera.py +30 -0
- GameBox/basics/utils.py +17 -0
- GameBox/player/_player.py +35 -0
- GameBox/player/_playerControler.py +54 -0
- GameBox/player/_playerPhysics.py +105 -0
- gamebox-0.1.0.dist-info/METADATA +20 -0
- gamebox-0.1.0.dist-info/RECORD +14 -0
- {gamebox-0.0.5.dist-info → gamebox-0.1.0.dist-info}/WHEEL +1 -1
- GameBox/basics/Defaults.json +0 -12
- GameBox/basics/Functions.py +0 -43
- GameBox/basics/_core.py +0 -41
- GameBox/basics/camera.py +0 -14
- GameBox/basics/player.py +0 -284
- GameBox/basics/shapes.py +0 -30
- GameBox/entities/basicNPCs.py +0 -21
- GameBox/entities/basicTypes.py +0 -79
- GameBox/game.py +0 -30
- GameBox/inputs/BasicInput.py +0 -11
- GameBox/sound/BasicSound.py +0 -66
- GameBox/tilemap/editor.py +0 -267
- GameBox/tilemap/tilemap.py +0 -146
- gamebox-0.0.5.dist-info/METADATA +0 -40
- gamebox-0.0.5.dist-info/RECORD +0 -19
- {gamebox-0.0.5.dist-info → gamebox-0.1.0.dist-info}/licenses/LICENSE +0 -0
GameBox/__init__.py
CHANGED
|
@@ -9,29 +9,20 @@ __version__ = "0.0.3"
|
|
|
9
9
|
__author__ = "Sam Fertig"
|
|
10
10
|
|
|
11
11
|
#____imports____
|
|
12
|
-
from .
|
|
13
|
-
from .basics.
|
|
14
|
-
from .basics.
|
|
15
|
-
from .
|
|
16
|
-
from .
|
|
17
|
-
from .inputs.BasicInput import Input
|
|
18
|
-
from .sound.BasicSound import Sound
|
|
19
|
-
from .basics.Functions import State_conditions
|
|
20
|
-
from .entities.basicTypes import Static_enemy, Dynamic_enemy
|
|
12
|
+
from ._game import Game
|
|
13
|
+
from .basics.cammera import Cammera
|
|
14
|
+
from .basics._shapes import Rect
|
|
15
|
+
from .player._player import Player
|
|
16
|
+
from .basics.utils import clamp, moveTward, zeroOut
|
|
21
17
|
|
|
22
18
|
|
|
23
19
|
__all__ = [
|
|
24
20
|
"Game",
|
|
25
|
-
"
|
|
21
|
+
"Cammera",
|
|
26
22
|
"Rect",
|
|
27
23
|
"Player",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"Text",
|
|
32
|
-
"Animation",
|
|
33
|
-
"State_conditions",
|
|
34
|
-
"Static_enemy",
|
|
35
|
-
"Dynamic_enemy",
|
|
24
|
+
"clamp",
|
|
25
|
+
"moveTward",
|
|
26
|
+
"zeroOut"
|
|
36
27
|
]
|
|
37
28
|
|
GameBox/_game.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from .basics._net import Global
|
|
5
|
+
from .player._player import Player
|
|
6
|
+
|
|
7
|
+
class Game:
|
|
8
|
+
def __init__(self, width, height, bg_color, WinTitle="GameBox"):
|
|
9
|
+
"""
|
|
10
|
+
Initialize the Game object.
|
|
11
|
+
|
|
12
|
+
ParameArters:
|
|
13
|
+
width (int): The width of the game window.
|
|
14
|
+
height (int): The height of the game window.
|
|
15
|
+
bg_color (tuple): The background color of the game window.
|
|
16
|
+
WinTitle (str): The title of the game window.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
None
|
|
20
|
+
"""
|
|
21
|
+
Global.screenDim = (width, height)
|
|
22
|
+
Global.screen = pygame.display.set_mode(Global.screenDim)
|
|
23
|
+
pygame.display.set_caption(WinTitle)
|
|
24
|
+
Global.bgColor = bg_color
|
|
25
|
+
Global.clock = pygame.time.Clock()
|
|
26
|
+
Global.game = self
|
|
27
|
+
self.objs = []
|
|
28
|
+
|
|
29
|
+
def update(self, frame_rate=60):
|
|
30
|
+
Global.collisions.clear()
|
|
31
|
+
Global.dt = Global.clock.tick(frame_rate) / 1000.0
|
|
32
|
+
Global.screen.fill(Global.bgColor)
|
|
33
|
+
player = None
|
|
34
|
+
for obj in self.objs:
|
|
35
|
+
if type(obj) == Player: player = obj
|
|
36
|
+
else: obj.update()
|
|
37
|
+
if player != None: player.update()
|
|
38
|
+
pygame.display.update()
|
GameBox/basics/_net.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
class _global_:
|
|
5
|
+
def __init__(self):
|
|
6
|
+
#screen info and win data
|
|
7
|
+
self.screen: pygame.Surface = None
|
|
8
|
+
self.dt: float = 0
|
|
9
|
+
self.screenDim: tuple = None
|
|
10
|
+
self.bgColor: tuple = None
|
|
11
|
+
self.clock: pygame.time.Clock = None
|
|
12
|
+
|
|
13
|
+
#basics
|
|
14
|
+
#--game and cam
|
|
15
|
+
self.game: object = None
|
|
16
|
+
self.cam: object = None
|
|
17
|
+
#-collisions
|
|
18
|
+
self.collisions: list[pygame.Rect] = []
|
|
19
|
+
|
|
20
|
+
#objects
|
|
21
|
+
self.player = self._player()
|
|
22
|
+
|
|
23
|
+
class _player:
|
|
24
|
+
def __init__(self):
|
|
25
|
+
self.pos: tuple = None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
Global = _global_()
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
rect = pygame.Rect(self.x - Global.cam.x
|
|
16
|
+
, self.y - Global.cam.y
|
|
17
|
+
, self.width, self.height)
|
|
18
|
+
if self.collision: Global.collisions.append(rect)
|
|
19
|
+
pygame.draw.rect(Global.screen, self.color, rect)
|
|
20
|
+
|
|
21
|
+
def move(self, x, y):
|
|
22
|
+
self.x += x
|
|
23
|
+
self.y += y
|
|
@@ -0,0 +1,30 @@
|
|
|
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):
|
|
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
|
+
|
|
17
|
+
def move(self, x, y):
|
|
18
|
+
self.x += x
|
|
19
|
+
self.y += y
|
|
20
|
+
|
|
21
|
+
def update(self):
|
|
22
|
+
return
|
|
23
|
+
if self.follow is not None:
|
|
24
|
+
self.x = (self.follow.x - self.diff[0])
|
|
25
|
+
self.y = (self.follow.y - self.diff[1])
|
|
26
|
+
|
|
27
|
+
def set_follow_target(self, target: object):
|
|
28
|
+
self.follow = target
|
|
29
|
+
print(target)
|
|
30
|
+
self.diff = (target.x - self.x, target.y - self.y)
|
GameBox/basics/utils.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
import math
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
def clamp(value, min_value, max_value):
|
|
6
|
+
return max(min(value, max_value), min_value)
|
|
7
|
+
def moveTward(value, target, speed):
|
|
8
|
+
if value < target:
|
|
9
|
+
value += speed
|
|
10
|
+
elif value > target:
|
|
11
|
+
value -= speed
|
|
12
|
+
return value
|
|
13
|
+
|
|
14
|
+
def zeroOut(value, max):
|
|
15
|
+
if value < 0 and value > -max: value = 0
|
|
16
|
+
if value > 0 and value < max: value = 0
|
|
17
|
+
return value
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from ..basics._net import Global
|
|
5
|
+
|
|
6
|
+
from ..player._playerPhysics import _playerPhysics
|
|
7
|
+
|
|
8
|
+
class Player:
|
|
9
|
+
def __init__(self, pos: tuple, size: tuple, color: tuple = (0, 0, 0), gravity: bool = False):
|
|
10
|
+
self.x, self.y = pos
|
|
11
|
+
self.screenPos = pos
|
|
12
|
+
self.dim = size
|
|
13
|
+
self.color = color
|
|
14
|
+
|
|
15
|
+
self.gravity = gravity
|
|
16
|
+
|
|
17
|
+
Global.game.objs.append(self)
|
|
18
|
+
Global.player.pos = pos
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def add_physics(self, speed: float = 1.0, gravity: float = 0.0, jump: float = 10.0, maxV: float = 10.0, airRes: float = 0.2):
|
|
22
|
+
self.physics = _playerPhysics(self, speed, gravity, jump, maxV, airRes)
|
|
23
|
+
|
|
24
|
+
def update(self):
|
|
25
|
+
self.physics.update()
|
|
26
|
+
#debug rect
|
|
27
|
+
rect = pygame.Rect(self.x, self.y, self.dim[0], self.dim[1])
|
|
28
|
+
pygame.draw.rect(Global.screen, "green", rect)
|
|
29
|
+
|
|
30
|
+
#movement
|
|
31
|
+
def top_down_movement(self):
|
|
32
|
+
self.physics.top_down_movement()
|
|
33
|
+
|
|
34
|
+
def platforming_movement(self):
|
|
35
|
+
self.physics.platforming_movement()
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from ..basics._net import Global
|
|
5
|
+
from ..basics.utils import clamp, moveTward, zeroOut
|
|
6
|
+
|
|
7
|
+
class _playerControler:
|
|
8
|
+
def __init__(self, player: object, speed: float = 1.0, gravity: float = 0.0, jump: float = 0.0, maxV: float = 10.0, airRes: float = 0.2):
|
|
9
|
+
self.speed = speed
|
|
10
|
+
self.gravity = gravity
|
|
11
|
+
self.jump = jump
|
|
12
|
+
self.player = player
|
|
13
|
+
self.maxV = maxV
|
|
14
|
+
self.airRes = airRes
|
|
15
|
+
|
|
16
|
+
def update(self):
|
|
17
|
+
self.player.vx = clamp(self.player.vx, -self.maxV, self.maxV)
|
|
18
|
+
#self.player.vy = clamp(self.player.vy, -self.maxV, self.maxV)
|
|
19
|
+
|
|
20
|
+
self.player.vx = moveTward(self.player.vx, 0, self.airRes)
|
|
21
|
+
self.player.vy = moveTward(self.player.vy, 0, self.airRes)
|
|
22
|
+
|
|
23
|
+
self.player.vx = zeroOut(self.player.vx, 0.3)
|
|
24
|
+
self.player.vy = zeroOut(self.player.vy, 0.3)
|
|
25
|
+
|
|
26
|
+
if self.player.gravity and not self.player.onGround: self.player.vy += self.gravity
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def move(self, x, y):
|
|
32
|
+
self.player.vx += x * self.speed
|
|
33
|
+
self.player.vy += y * self.speed
|
|
34
|
+
|
|
35
|
+
def top_down_movement(self):
|
|
36
|
+
keys = pygame.key.get_pressed()
|
|
37
|
+
if keys[pygame.K_a]:
|
|
38
|
+
self.move(-1, 0)
|
|
39
|
+
if keys[pygame.K_d]:
|
|
40
|
+
self.move(1, 0)
|
|
41
|
+
if keys[pygame.K_w]:
|
|
42
|
+
self.move(0, -1)
|
|
43
|
+
if keys[pygame.K_s]:
|
|
44
|
+
self.move(0, 1)
|
|
45
|
+
|
|
46
|
+
def platforming_movement(self):
|
|
47
|
+
keys = pygame.key.get_pressed()
|
|
48
|
+
if keys[pygame.K_a]:
|
|
49
|
+
self.move(-1, 0)
|
|
50
|
+
if keys[pygame.K_d]:
|
|
51
|
+
self.move(1, 0)
|
|
52
|
+
if keys[pygame.K_SPACE] and self.player.onGround:
|
|
53
|
+
self.player.vy = -self.jump
|
|
54
|
+
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from ..basics._net import Global
|
|
5
|
+
from ..basics.utils import clamp, moveTward, zeroOut
|
|
6
|
+
|
|
7
|
+
class _playerPhysics:
|
|
8
|
+
def __init__(self, player, speed: float = 1.0, gravity: float = 0.0, jump: float = 0.0, maxV: float = 10.0, airRes: float = 0.2):
|
|
9
|
+
self.player = player
|
|
10
|
+
self.rect = pygame.Rect(self.player.x, self.player.y, self.player.dim[0], self.player.dim[1])
|
|
11
|
+
|
|
12
|
+
self.speed = speed
|
|
13
|
+
self.gravity = gravity
|
|
14
|
+
self.jump = jump
|
|
15
|
+
self.player = player
|
|
16
|
+
self.maxV = maxV
|
|
17
|
+
self.airRes = airRes
|
|
18
|
+
self.onGround = False
|
|
19
|
+
self.canJump = False
|
|
20
|
+
|
|
21
|
+
self.vx, self.vy = 0, 0
|
|
22
|
+
|
|
23
|
+
def update(self):
|
|
24
|
+
self.ckeck_is_on_ground()
|
|
25
|
+
self.fixVelocities()
|
|
26
|
+
x, y = self.check_collisions()
|
|
27
|
+
if type(Global.cam.follow) != type(self.player):
|
|
28
|
+
self.player.x = x
|
|
29
|
+
self.player.y = y
|
|
30
|
+
elif type(Global.cam.follow) == type(self.player):
|
|
31
|
+
dx = -(self.player.x - x)
|
|
32
|
+
dy = -(self.player.y - y)
|
|
33
|
+
Global.cam.move(self.vx, self.vy)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def check_collisions(self):
|
|
38
|
+
x, y = self.player.x + self.vx, self.player.y + self.vy
|
|
39
|
+
|
|
40
|
+
# X-axis collisions
|
|
41
|
+
new_rect = pygame.Rect((x, self.player.y), self.player.dim)
|
|
42
|
+
for collision in Global.collisions:
|
|
43
|
+
if collision.colliderect(new_rect):
|
|
44
|
+
if self.vx > 0:
|
|
45
|
+
x = collision.left - self.player.dim[0]
|
|
46
|
+
elif self.vx < 0:
|
|
47
|
+
x = collision.right
|
|
48
|
+
self.vx = 0
|
|
49
|
+
|
|
50
|
+
# Y-axis collisions
|
|
51
|
+
new_rect = pygame.Rect((x, y), self.player.dim)
|
|
52
|
+
for collision in Global.collisions:
|
|
53
|
+
if collision.colliderect(new_rect):
|
|
54
|
+
if self.vy > 0: # falling
|
|
55
|
+
y = collision.top - self.player.dim[1]
|
|
56
|
+
self.vy = 0
|
|
57
|
+
elif self.vy < 0: # jumping
|
|
58
|
+
y = collision.bottom
|
|
59
|
+
self.vy = 0
|
|
60
|
+
|
|
61
|
+
return x, y
|
|
62
|
+
|
|
63
|
+
def ckeck_is_on_ground(self):
|
|
64
|
+
self.canJump = False
|
|
65
|
+
rect = pygame.Rect(self.player.x, self.player.y + self.player.dim[1], self.player.dim[0], 10)
|
|
66
|
+
for collision in Global.collisions:
|
|
67
|
+
if collision.colliderect(rect):
|
|
68
|
+
self.canJump = True
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def move(self, x, y):
|
|
72
|
+
self.vx += x * self.speed
|
|
73
|
+
self.vy += y * self.speed
|
|
74
|
+
|
|
75
|
+
def top_down_movement(self):
|
|
76
|
+
keys = pygame.key.get_pressed()
|
|
77
|
+
if keys[pygame.K_a]:
|
|
78
|
+
self.move(-1, 0)
|
|
79
|
+
if keys[pygame.K_d]:
|
|
80
|
+
self.move(1, 0)
|
|
81
|
+
if keys[pygame.K_w]:
|
|
82
|
+
self.move(0, -1)
|
|
83
|
+
if keys[pygame.K_s]:
|
|
84
|
+
self.move(0, 1)
|
|
85
|
+
#limit velocity
|
|
86
|
+
self.vx = clamp(self.vx, -self.maxV, self.maxV)
|
|
87
|
+
self.vy = clamp(self.vy, -self.maxV, self.maxV)
|
|
88
|
+
self.vx = moveTward(self.vx, 0, self.airRes)
|
|
89
|
+
self.vy = moveTward(self.vy, 0, self.airRes)
|
|
90
|
+
self.vx = zeroOut(self.vx, 0.3)
|
|
91
|
+
self.vy = zeroOut(self.vy, 0.3)
|
|
92
|
+
|
|
93
|
+
def platforming_movement(self):
|
|
94
|
+
keys = pygame.key.get_pressed()
|
|
95
|
+
if keys[pygame.K_a]:
|
|
96
|
+
self.move(-1, 0)
|
|
97
|
+
if keys[pygame.K_d]:
|
|
98
|
+
self.move(1, 0)
|
|
99
|
+
if keys[pygame.K_w] and self.canJump:
|
|
100
|
+
self.vy -= self.jump
|
|
101
|
+
#limit velocity
|
|
102
|
+
self.vx = clamp(self.vx, -self.maxV, self.maxV)
|
|
103
|
+
self.vx = moveTward(self.vx, 0, self.airRes)
|
|
104
|
+
self.vx = zeroOut(self.vx, 0.3)
|
|
105
|
+
if self.player.gravity and not self.onGround: self.vy += self.gravity
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: GameBox
|
|
3
|
+
Version: 0.1.0
|
|
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
|
+
Author-email: Sam Fertig <sfertig007@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
GameBox is a lightweight 2D game framework built on pygame.
|
|
14
|
+
This is an early technical preview of a full engine rewrite.
|
|
15
|
+
APIs may change frequently.
|
|
16
|
+
|
|
17
|
+
Versioning
|
|
18
|
+
GameBox follows a modified semantic versioning scheme.
|
|
19
|
+
Versions starting with 0.x.x are experimental and may change without notice.
|
|
20
|
+
Stable, marketed releases will begin at 1.0.0.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
GameBox/__init__.py,sha256=ZGp_MWKpBN5yyxOqNg2XamrccMDJtsg9eLoejEYe72E,625
|
|
2
|
+
GameBox/_game.py,sha256=CB8GzTAheE-UvF4-emRsKZm3kmSC-gkpSn46K8D6Vqc,1222
|
|
3
|
+
GameBox/basics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
GameBox/basics/_net.py,sha256=Mdxa8-V3Xm0Gvhb-2lkGj3DfhM0MnREI_nLsccR14xc,658
|
|
5
|
+
GameBox/basics/_shapes.py,sha256=zlRxwSakcKgrtIM75hnfnmlks6rQdxP2Ie9U4s4imCk,730
|
|
6
|
+
GameBox/basics/cammera.py,sha256=r5veuC6T3PUHM_9O-d-kjsNEDQv0k5-8_AKke2XGn0E,728
|
|
7
|
+
GameBox/basics/utils.py,sha256=w6H34MhxcNoX58iQtlvbT5-4GXefy3RIMTxZGP9fSxA,432
|
|
8
|
+
GameBox/player/_player.py,sha256=A1a281ToYM_kbMMaTZT3OLFXPDpqZpnAfMNd4WxwWfI,1066
|
|
9
|
+
GameBox/player/_playerControler.py,sha256=XEb87RFlgLFoXnXqxIS4lpzHN0wywMNCX5y-NIhw0cs,1715
|
|
10
|
+
GameBox/player/_playerPhysics.py,sha256=1DWjWk8J4eH5YpGCTHaJQVHOWExjJdPZArJVNKrfliA,3685
|
|
11
|
+
gamebox-0.1.0.dist-info/METADATA,sha256=DnUktpoPqNzEJ6Ru0dceEy3xUSHjJ0dNNsvsNvFzTis,1015
|
|
12
|
+
gamebox-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
13
|
+
gamebox-0.1.0.dist-info/licenses/LICENSE,sha256=gcuuhKKc5-dwvyvHsXjlC9oM6N5gZ6umYbC8ewW1Yvg,35821
|
|
14
|
+
gamebox-0.1.0.dist-info/RECORD,,
|
GameBox/basics/Defaults.json
DELETED
GameBox/basics/Functions.py
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
|
|
3
|
-
def DisplayText(text, color, size, pos, screen):
|
|
4
|
-
font = pygame.font.Font(None, size)
|
|
5
|
-
textSurf = font.render(text, False, color)
|
|
6
|
-
screen.blit(textSurf, pos)
|
|
7
|
-
|
|
8
|
-
def getTilePosInGrid(pos, grid_size):
|
|
9
|
-
x, y = pos
|
|
10
|
-
return (x // grid_size, y // grid_size)
|
|
11
|
-
|
|
12
|
-
class IsWithinBounds:
|
|
13
|
-
def __init__(self, dim, offset):
|
|
14
|
-
self.offset = offset
|
|
15
|
-
self.dim = dim
|
|
16
|
-
|
|
17
|
-
def checkPos(self, pos):
|
|
18
|
-
x, y = pos
|
|
19
|
-
w, h = self.dim
|
|
20
|
-
w+=self.offset
|
|
21
|
-
h+=self.offset
|
|
22
|
-
if x > w or y > h:
|
|
23
|
-
return False
|
|
24
|
-
w=-self.offset
|
|
25
|
-
h=-self.offset
|
|
26
|
-
if x < w or y < h:
|
|
27
|
-
return False
|
|
28
|
-
return True
|
|
29
|
-
|
|
30
|
-
class State_conditions:
|
|
31
|
-
def __init__(self):
|
|
32
|
-
self.top = "C^"
|
|
33
|
-
self.bottom = "C_"
|
|
34
|
-
self.left = "C<"
|
|
35
|
-
self.right = "C>"
|
|
36
|
-
self.any = "C#"
|
|
37
|
-
self.none = "CN"
|
|
38
|
-
self.move_up = "M^"
|
|
39
|
-
self.move_down = "M_"
|
|
40
|
-
self.move_left = "m<"
|
|
41
|
-
self.move_right = "M>"
|
|
42
|
-
self.move_any = "M#"
|
|
43
|
-
self.move_none = "MN"
|
GameBox/basics/_core.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import os
|
|
3
|
-
|
|
4
|
-
class _GLOBALNETWORK:
|
|
5
|
-
def __init__(self):
|
|
6
|
-
self.collisions = []
|
|
7
|
-
self.playerPosition = None
|
|
8
|
-
self.BaseInfo = {}
|
|
9
|
-
self.screen = None
|
|
10
|
-
|
|
11
|
-
class _CONFIG:
|
|
12
|
-
def __init__(self, path="Defaults.json"):
|
|
13
|
-
self.data = {}
|
|
14
|
-
self.load(path)
|
|
15
|
-
|
|
16
|
-
def load(self, path):
|
|
17
|
-
"""Load JSON data with fallback defaults."""
|
|
18
|
-
if not os.path.exists(path):
|
|
19
|
-
print("[GameBox] No Default.json found — using override settings.")
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
with open(path, "r") as f:
|
|
23
|
-
try:
|
|
24
|
-
self.data = json.load(f)
|
|
25
|
-
print("[GameBox] Config loaded successfully.")
|
|
26
|
-
except json.JSONDecodeError:
|
|
27
|
-
print("[GameBox] Error: Invalid JSON format.")
|
|
28
|
-
|
|
29
|
-
def get(self, *keys, default=None):
|
|
30
|
-
"""Nested key access: config.get('player', 'speed')"""
|
|
31
|
-
ref = self.data
|
|
32
|
-
for key in keys:
|
|
33
|
-
if isinstance(ref, dict) and key in ref:
|
|
34
|
-
ref = ref[key]
|
|
35
|
-
else:
|
|
36
|
-
return default
|
|
37
|
-
return ref
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
GLOBAL = _GLOBALNETWORK()
|
GameBox/basics/camera.py
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
|
|
3
|
-
class Camera:
|
|
4
|
-
def __init__(self, width, height, type = "dynamic"):
|
|
5
|
-
"""Camera type can be fixed or dynamic depending on your needs. Defaults to dynamic."""
|
|
6
|
-
self.type = type
|
|
7
|
-
self.dim = width, height
|
|
8
|
-
self.pos = 0, 0
|
|
9
|
-
|
|
10
|
-
def move(self, x, y):
|
|
11
|
-
X, Y = self.pos
|
|
12
|
-
X+=x
|
|
13
|
-
Y+=y
|
|
14
|
-
self.pos = X, Y
|