GameBox 0.9.2__py3-none-any.whl → 0.10.0.dev1__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/Game.py +68 -0
- GameBox/__init__.py +21 -24
- GameBox/basics/Cammera.py +43 -0
- GameBox/basics/Net.py +28 -0
- GameBox/basics/Shapes.py +80 -0
- GameBox/basics/sound.py +16 -0
- GameBox/basics/ui.py +70 -0
- GameBox/basics/utils.py +2 -1
- GameBox/helpers/{_input.py → Input.py} +8 -3
- GameBox/helpers/_collisions.py +60 -147
- GameBox/player/Player.py +45 -0
- GameBox/player/_playerControler.py +27 -52
- GameBox/player/_playerPhysics.py +27 -76
- GameBox/tilemap/Tilemap.py +46 -0
- {gamebox-0.9.2.dist-info → gamebox-0.10.0.dev1.dist-info}/METADATA +1 -1
- gamebox-0.10.0.dev1.dist-info/RECORD +18 -0
- GameBox/GameLevel_ui/_Animations.py +0 -39
- GameBox/GameLevel_ui/_sprites.py +0 -185
- GameBox/_game.py +0 -81
- GameBox/basics/__init__.py +0 -0
- GameBox/basics/_net.py +0 -36
- GameBox/basics/_shapes.py +0 -44
- GameBox/basics/cammera.py +0 -36
- GameBox/helpers/_Conditions.py +0 -56
- GameBox/player/_player.py +0 -61
- GameBox/player/_playerSprite.py +0 -86
- GameBox/tilemap/_Editor.py +0 -36
- GameBox/tilemap/_collisionDef.py +0 -41
- GameBox/tilemap/_editorBrushes.py +0 -166
- GameBox/tilemap/_tilemap.py +0 -94
- GameBox/ui/_basicUI.py +0 -36
- gamebox-0.9.2.dist-info/RECORD +0 -25
- {gamebox-0.9.2.dist-info → gamebox-0.10.0.dev1.dist-info}/WHEEL +0 -0
- {gamebox-0.9.2.dist-info → gamebox-0.10.0.dev1.dist-info}/licenses/LICENSE +0 -0
GameBox/basics/_shapes.py
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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)
|
GameBox/basics/cammera.py
DELETED
|
@@ -1,36 +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
|
-
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
|
GameBox/helpers/_Conditions.py
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
def __init__(self):
|
|
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~'
|
|
16
|
-
|
|
17
|
-
Conditions = _Conditions()
|
|
18
|
-
Global.cond = Conditions
|
|
19
|
-
|
|
20
|
-
class Condition_check:
|
|
21
|
-
def __init__(self, stateTree: dict[str, dict[_Conditions, str]], currentState: str):
|
|
22
|
-
self.stateTree = stateTree
|
|
23
|
-
self.currentState = currentState
|
|
24
|
-
|
|
25
|
-
def check(self, velocity: tuple, pos: tuple):
|
|
26
|
-
state = self.stateTree[self.currentState]
|
|
27
|
-
for cond, next in state.items():
|
|
28
|
-
#velocities
|
|
29
|
-
if cond[1] == 'V':
|
|
30
|
-
if self._resolve_velocities(velocity, cond):
|
|
31
|
-
self.currentState = next
|
|
32
|
-
return next
|
|
33
|
-
return self.currentState
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def _resolve_velocities(self, velocities, cond):
|
|
37
|
-
vx, vy = velocities
|
|
38
|
-
vx = zeroOut(vx, 0.1)
|
|
39
|
-
vy = zeroOut(vy, 0.1)
|
|
40
|
-
dir = cond[2]
|
|
41
|
-
print(vx, vy, dir)
|
|
42
|
-
#resolve in order up, down, left, right, none, any
|
|
43
|
-
if dir == "^" and vy < 0: return True
|
|
44
|
-
if dir == "_" and vy > 0: return True
|
|
45
|
-
if dir == "<" and vx < 0: return True
|
|
46
|
-
if dir == ">" and vx > 0: return True
|
|
47
|
-
if dir == "#" and vx == 0 and vy == 0: return True
|
|
48
|
-
if dir == "~" and (vx != 0 or vy != 0): return True
|
|
49
|
-
return False
|
|
50
|
-
|
|
51
|
-
def updateState(self, state: str):
|
|
52
|
-
self.currentState = state
|
|
53
|
-
def updateStateTree(self, stateTree: dict[str, dict[_Conditions, str]]):
|
|
54
|
-
self.stateTree = stateTree
|
|
55
|
-
|
|
56
|
-
|
GameBox/player/_player.py
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
import numpy as np
|
|
3
|
-
|
|
4
|
-
from ..basics._net import Global
|
|
5
|
-
|
|
6
|
-
from ..player._playerPhysics import _playerPhysics
|
|
7
|
-
from ..player._playerSprite import _playerSprite
|
|
8
|
-
|
|
9
|
-
from ..GameLevel_ui._sprites import Sprite_2d
|
|
10
|
-
|
|
11
|
-
class Player:
|
|
12
|
-
def __init__(self, pos: tuple, size: tuple, color: tuple = (0, 0, 0), gravity: bool = False):
|
|
13
|
-
self.x, self.y = pos
|
|
14
|
-
self.screenPos = pos
|
|
15
|
-
self.dim = size
|
|
16
|
-
self.color = color
|
|
17
|
-
self.width, self.height = size
|
|
18
|
-
|
|
19
|
-
self.gravity = gravity
|
|
20
|
-
|
|
21
|
-
self.state = ""
|
|
22
|
-
|
|
23
|
-
Global.game.objs.append(self)
|
|
24
|
-
Global.player.pos = pos
|
|
25
|
-
Global.player.player = self
|
|
26
|
-
|
|
27
|
-
self.sprite = _playerSprite(self)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def add_physics(self, speed: float = 1.0, gravity: float = 0.0, jump: float = 10.0, maxV: float = 10.0, airRes: float = 0.2):
|
|
31
|
-
self.physics = _playerPhysics(self, speed, gravity, jump, maxV, airRes)
|
|
32
|
-
|
|
33
|
-
def update(self):
|
|
34
|
-
self.physics.update()
|
|
35
|
-
#ui
|
|
36
|
-
|
|
37
|
-
if (Global.cam.follow) != (self):
|
|
38
|
-
x = self.x - Global.cam.x
|
|
39
|
-
y = self.y - Global.cam.y
|
|
40
|
-
elif (Global.cam.follow) == (self):
|
|
41
|
-
x = self.x
|
|
42
|
-
y = self.y
|
|
43
|
-
velocity = (self.physics.vx, self.physics.vy)
|
|
44
|
-
self.sprite.update(x, y, velocity)
|
|
45
|
-
|
|
46
|
-
#movement
|
|
47
|
-
def top_down_movement(self):
|
|
48
|
-
self.physics.top_down_movement()
|
|
49
|
-
|
|
50
|
-
def platforming_movement(self):
|
|
51
|
-
self.physics.platforming_movement()
|
|
52
|
-
|
|
53
|
-
def set_tilemap_sample(self, sample: int = 10):
|
|
54
|
-
"""
|
|
55
|
-
Sets the sample size for player physics collisions.
|
|
56
|
-
Is the radius of tiles that will be used to get tilemap collisions around player. Note:
|
|
57
|
-
The larger the sample size the longer it may take to calculate collisions per frame.
|
|
58
|
-
"""
|
|
59
|
-
self.physics.sample = sample
|
|
60
|
-
|
|
61
|
-
|
GameBox/player/_playerSprite.py
DELETED
|
@@ -1,86 +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, Animated_Sprite2D, AnimationPlayer2D
|
|
7
|
-
from ..helpers._Conditions import Condition_check, _Conditions
|
|
8
|
-
|
|
9
|
-
class _playerSprite:
|
|
10
|
-
def __init__(self, player):
|
|
11
|
-
self.player = player
|
|
12
|
-
|
|
13
|
-
self.state = player.state
|
|
14
|
-
self.statetree = {}
|
|
15
|
-
self.condition_check = None
|
|
16
|
-
|
|
17
|
-
self.sprite = None
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def update(self, x, y, velocity):
|
|
21
|
-
#state updates
|
|
22
|
-
if self.condition_check is not None:
|
|
23
|
-
self.state = self.condition_check.check(velocity, self.player.screenPos)
|
|
24
|
-
#set animation if possible
|
|
25
|
-
if type(self.sprite) == AnimationPlayer2D:
|
|
26
|
-
if self.state in self.sprite.anims:
|
|
27
|
-
self.sprite.set_animation(self.state)
|
|
28
|
-
#any changes to follow target
|
|
29
|
-
if Global.cam.follow == self.player and self.sprite is not None:
|
|
30
|
-
self.sprite.__worldPos__ = False
|
|
31
|
-
self.sprite.move_to(self.player.screenPos[0], self.player.screenPos[1])
|
|
32
|
-
elif Global.cam.follow != self.player and self.sprite is not None:
|
|
33
|
-
self.sprite.__worldPos__ = True
|
|
34
|
-
self.sprite.move_to(self.player.x, self.player.y)
|
|
35
|
-
|
|
36
|
-
if self.sprite is None:
|
|
37
|
-
#rect (x, y) is top left corner
|
|
38
|
-
rect = pygame.Rect((x, y), self.player.dim)
|
|
39
|
-
pygame.draw.rect(Global.screen, self.player.color, rect)
|
|
40
|
-
if type(self.sprite) == Sprite_2d:
|
|
41
|
-
self.sprite.update()
|
|
42
|
-
elif type(self.sprite) == Animated_Sprite2D:
|
|
43
|
-
self.sprite.update()
|
|
44
|
-
elif type(self.sprite) == AnimationPlayer2D:
|
|
45
|
-
self.sprite.update()
|
|
46
|
-
|
|
47
|
-
def add_sprite_2d(self, image, scale=1.0, dirrection=1):
|
|
48
|
-
self.sprite = Sprite_2d((self.player.x, self.player.y), image, scale, False, dirrection)
|
|
49
|
-
if Global.cam.follow == self.player:
|
|
50
|
-
self.sprite.__worldPos__ = False
|
|
51
|
-
self.sprite.__remove__()
|
|
52
|
-
|
|
53
|
-
def add_animated_sprite_2d(self, image, imageDim, tileDim, frames, speed, scale = 1.0, collision = True, dirrection = 1):
|
|
54
|
-
self.sprite = Animated_Sprite2D((self.player.x, self.player.y), image, imageDim, tileDim, frames, speed, scale, collision, dirrection)
|
|
55
|
-
if Global.cam.follow == self.player:
|
|
56
|
-
self.sprite.__worldPos__ = False
|
|
57
|
-
self.sprite.__remove__()
|
|
58
|
-
|
|
59
|
-
def remove_sprite(self):
|
|
60
|
-
if self.sprite is not None:
|
|
61
|
-
self.sprite = None
|
|
62
|
-
|
|
63
|
-
def add_animation_player(self, scale = 1.0):
|
|
64
|
-
self.sprite = AnimationPlayer2D((self.player.x, self.player.y), scale)
|
|
65
|
-
if Global.cam.follow == self.player:
|
|
66
|
-
self.sprite.set_worldPos(False)
|
|
67
|
-
self.sprite.__remove__()
|
|
68
|
-
|
|
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
|
-
self.sprite.__remove__()
|
|
72
|
-
self.sprite.set_worldPos(False)
|
|
73
|
-
|
|
74
|
-
def remove_animation(self, name: str):
|
|
75
|
-
self.sprite.remove_animation(name)
|
|
76
|
-
|
|
77
|
-
def set_animation(self, anim: str):
|
|
78
|
-
self.sprite.set_animation(anim)
|
|
79
|
-
|
|
80
|
-
def set_states(self, stateTree: dict[str, dict[_Conditions, str]], currentState: str):
|
|
81
|
-
self.statetree = stateTree
|
|
82
|
-
self.state = currentState
|
|
83
|
-
self.condition_check = Condition_check(self.statetree, self.state)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
GameBox/tilemap/_Editor.py
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
import numpy as np
|
|
3
|
-
|
|
4
|
-
from..helpers._input import Keys
|
|
5
|
-
from ..basics._net import Global
|
|
6
|
-
from ._collisionDef import _tileCollisionDefs
|
|
7
|
-
|
|
8
|
-
from._editorBrushes import _brushPencil, _collisionsPencil
|
|
9
|
-
|
|
10
|
-
class _tilemapEditor:
|
|
11
|
-
def __init__(self, tilemap, activation):
|
|
12
|
-
self.tilemap = tilemap
|
|
13
|
-
self.activation = activation
|
|
14
|
-
self.active = False
|
|
15
|
-
|
|
16
|
-
self.mode = _brushPencil()
|
|
17
|
-
|
|
18
|
-
self.changes = {
|
|
19
|
-
"pencil": Keys.b,
|
|
20
|
-
"collisions": Keys.c
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
def _update(self):
|
|
25
|
-
if self.active:
|
|
26
|
-
self.change_mode()
|
|
27
|
-
#editor stuff
|
|
28
|
-
self.mode.update(self.tilemap)
|
|
29
|
-
#toggle
|
|
30
|
-
if Keys.is_pressed(self.activation): self.active = not self.active
|
|
31
|
-
|
|
32
|
-
def change_mode(self):
|
|
33
|
-
#key presses
|
|
34
|
-
if Keys.is_pressed(self.changes["pencil"]): self.mode = _brushPencil()
|
|
35
|
-
elif Keys.is_pressed(self.changes["collisions"]): self.mode = _collisionsPencil(self.tilemap)
|
|
36
|
-
|
GameBox/tilemap/_collisionDef.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
|
|
3
|
-
class _tileCollisionDefs:
|
|
4
|
-
def __init__(self, tileDim):
|
|
5
|
-
width, height = tileDim
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
self.rects = ["full", "none", "halfLeft", "halfRight", "halfTop", "halfBottom", "topRight",
|
|
9
|
-
"topLeft", "bottomRight", "bottomLeft", "dot"]
|
|
10
|
-
|
|
11
|
-
self.num = len(self.rects) + 1
|
|
12
|
-
|
|
13
|
-
self.full = pygame.Rect(0, 0, width, height)
|
|
14
|
-
|
|
15
|
-
self.halfLeft = pygame.Rect(0, 0, width / 2, height)
|
|
16
|
-
self.halfRight = pygame.Rect(width / 2, 0, width / 2, height)
|
|
17
|
-
self.halfTop = pygame.Rect(0, 0, width, height / 2)
|
|
18
|
-
self.halfBottom = pygame.Rect(0, height / 2, width, height / 2)
|
|
19
|
-
|
|
20
|
-
self.topRight = pygame.Rect(width / 2, 0, width / 2, height / 2)
|
|
21
|
-
self.topLeft = pygame.Rect(0, 0, width / 2, height / 2)
|
|
22
|
-
self.bottomRight = pygame.Rect(width / 2, height / 2, width / 2, height / 2)
|
|
23
|
-
self.bottomLeft = pygame.Rect(0, height / 2, width / 2, height / 2)
|
|
24
|
-
|
|
25
|
-
self.dot = pygame.Rect(0, 0, 3, 3)
|
|
26
|
-
|
|
27
|
-
self.center = pygame.Rect(width / 2, height / 2, width / 2, height / 2)
|
|
28
|
-
|
|
29
|
-
self.none = pygame.Rect(0, 0, 0, 0)
|
|
30
|
-
|
|
31
|
-
def regenerate(self, tileDim):
|
|
32
|
-
width, height = tileDim
|
|
33
|
-
self.full = pygame.Rect(0, 0, width, height)
|
|
34
|
-
|
|
35
|
-
self.halfLeft = pygame.Rect(0, 0, width / 2, height)
|
|
36
|
-
self.halfRight = pygame.Rect(width / 2, 0, width / 2, height)
|
|
37
|
-
self.halfTop = pygame.Rect(0, 0, width, height / 2)
|
|
38
|
-
self.halfBottom = pygame.Rect(0, height / 2, width, height / 2)
|
|
39
|
-
|
|
40
|
-
self.center = pygame.Rect(width / 2, height / 2, width / 2, height / 2)
|
|
41
|
-
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
import numpy as np
|
|
3
|
-
|
|
4
|
-
from ..basics._net import Global
|
|
5
|
-
from ..helpers._input import Keys
|
|
6
|
-
from ._collisionDef import _tileCollisionDefs
|
|
7
|
-
|
|
8
|
-
class _brushPencil():
|
|
9
|
-
def __init__(self):
|
|
10
|
-
self.selectedTile = 1
|
|
11
|
-
self.mode = "paint"
|
|
12
|
-
|
|
13
|
-
def update(self, tilemap):
|
|
14
|
-
#get all mouse calculations
|
|
15
|
-
x, y = Keys.mouse_x, Keys.mouse_y
|
|
16
|
-
x += Global.cam.x
|
|
17
|
-
y += Global.cam.y
|
|
18
|
-
mx = x // tilemap.tileDim[0] * tilemap.tileDim[0]
|
|
19
|
-
my = y // tilemap.tileDim[1] * tilemap.tileDim[1]
|
|
20
|
-
|
|
21
|
-
#get mode
|
|
22
|
-
x, y = Keys.mouse_x, Keys.mouse_y
|
|
23
|
-
if x > tilemap.tileset.get_size()[0] * tilemap.tilescale / 2 or y > tilemap.tileset.get_size()[1] * tilemap.tilescale / 2:
|
|
24
|
-
self.mode = "paint"
|
|
25
|
-
else:
|
|
26
|
-
self.mode = "select"
|
|
27
|
-
|
|
28
|
-
#--show tileset
|
|
29
|
-
tile = tilemap.tiles[self.selectedTile]
|
|
30
|
-
image = pygame.transform.scale_by(tilemap.tileset, tilemap.tilescale / 2)
|
|
31
|
-
Global.screen.blit(image, (0, 0))
|
|
32
|
-
#--show outlined sellected tile
|
|
33
|
-
x, y = tilemap.tilePosInImage[self.selectedTile]
|
|
34
|
-
x *= tilemap.tilescale / 2
|
|
35
|
-
y *= tilemap.tilescale / 2
|
|
36
|
-
width = tilemap.orginDim[0] * tilemap.tilescale / 2
|
|
37
|
-
height = tilemap.orginDim[1] * tilemap.tilescale / 2
|
|
38
|
-
outline = pygame.Rect(x, y, width, height)
|
|
39
|
-
pygame.draw.rect(Global.screen, "white", outline, 2)
|
|
40
|
-
#other stuff
|
|
41
|
-
if self.mode == "paint":
|
|
42
|
-
x = mx
|
|
43
|
-
y = my
|
|
44
|
-
|
|
45
|
-
x -= Global.cam.x
|
|
46
|
-
y -= Global.cam.y
|
|
47
|
-
Global.screen.blit(tile, (x, y))
|
|
48
|
-
#set tile or erase
|
|
49
|
-
if pygame.mouse.get_pressed()[0]:
|
|
50
|
-
#check if mouse is on tilemap
|
|
51
|
-
x, y = mx // tilemap.tileDim[0], my // tilemap.tileDim[1]
|
|
52
|
-
if x >= 0 and x < tilemap.mapDim[0] and y >= 0 and y < tilemap.mapDim[1]:
|
|
53
|
-
tilemap.map[int(y)][int(x)] = self.selectedTile
|
|
54
|
-
elif pygame.mouse.get_pressed()[2]:
|
|
55
|
-
x, y = mx // tilemap.tileDim[0], my // tilemap.tileDim[1]
|
|
56
|
-
if x >= 0 and x < tilemap.mapDim[0] and y >= 0 and y < tilemap.mapDim[1]:
|
|
57
|
-
tilemap.map[int(y)][int(x)] = 0
|
|
58
|
-
elif self.mode == "select":
|
|
59
|
-
#paint mouse hovered tile
|
|
60
|
-
x, y = Keys.mouse_x, Keys.mouse_y
|
|
61
|
-
x = (x // width)
|
|
62
|
-
y = (y // height)
|
|
63
|
-
outline = pygame.Rect(x * width, y * width, width, height)
|
|
64
|
-
pygame.draw.rect(Global.screen, "black", outline, 2)
|
|
65
|
-
if pygame.mouse.get_pressed()[0]:
|
|
66
|
-
x *= tilemap.orginDim[0]
|
|
67
|
-
y *= tilemap.orginDim[1]
|
|
68
|
-
self.selectedTile = tilemap.posToTile[(int(x), int(y))]
|
|
69
|
-
|
|
70
|
-
#move selection by arrow keys
|
|
71
|
-
x, y = tilemap.tilePosInImage[self.selectedTile]
|
|
72
|
-
|
|
73
|
-
width = 16
|
|
74
|
-
height = 16
|
|
75
|
-
|
|
76
|
-
if Keys.is_pressed(Keys.left): x -= width
|
|
77
|
-
if Keys.is_pressed(Keys.right): x += width
|
|
78
|
-
if Keys.is_pressed(Keys.up): y -= height
|
|
79
|
-
if Keys.is_pressed(Keys.down): y += height
|
|
80
|
-
|
|
81
|
-
if (int(x), int(y)) in tilemap.posToTile:
|
|
82
|
-
self.selectedTile = tilemap.posToTile[(int(x), int(y))]
|
|
83
|
-
|
|
84
|
-
class _collisionsPencil():
|
|
85
|
-
def __init__(self, tilemap):
|
|
86
|
-
self.selectedTile = 0
|
|
87
|
-
self.shapes = tilemap.collisionShapes.num
|
|
88
|
-
self.mode = "paint"
|
|
89
|
-
size = tilemap.tilescale / 2
|
|
90
|
-
self.size = tilemap.orginDim[0] * size
|
|
91
|
-
self.coll = _tileCollisionDefs((tilemap.orginDim[0] * size, tilemap.orginDim[1] * size))
|
|
92
|
-
|
|
93
|
-
def update(self, tilemap):
|
|
94
|
-
x, y = Keys.mouse_x, Keys.mouse_y
|
|
95
|
-
#draw tilesets and background
|
|
96
|
-
Global.screen.fill("darkgrey")
|
|
97
|
-
image = pygame.transform.scale_by(tilemap.tileset, tilemap.tilescale / 2)
|
|
98
|
-
Global.screen.blit(image, (0, 0))
|
|
99
|
-
Global.screen.blit(image, (0, image.get_size()[1]+ 10))
|
|
100
|
-
#draw all collision rects on top tileset
|
|
101
|
-
for tile in range(tilemap.tilesetNum - 1):
|
|
102
|
-
tile+=1
|
|
103
|
-
if str(tile) not in tilemap.collisionDict: continue
|
|
104
|
-
rectshape = tilemap.collisionDict[str(tile)]
|
|
105
|
-
rect = getattr(self.coll, rectshape).copy()
|
|
106
|
-
tx, ty = tilemap.tilePosInImage[int(tile)]
|
|
107
|
-
tx = (tx // tilemap.orginDim[0]) * self.size
|
|
108
|
-
ty = (ty // tilemap.orginDim[1]) * self.size
|
|
109
|
-
rect.x += tx
|
|
110
|
-
rect.y += ty
|
|
111
|
-
pygame.draw.rect(Global.screen, "yellow", rect, 5)
|
|
112
|
-
outline = pygame.Rect(tx, ty, self.size, self.size)
|
|
113
|
-
pygame.draw.rect(Global.screen, "gray", outline, 2)
|
|
114
|
-
#change mode
|
|
115
|
-
if y > image.get_size()[1] * 2 + 50: self.mode = "select"
|
|
116
|
-
else: self.mode = "paint"
|
|
117
|
-
#draw collisions tiles at bottom
|
|
118
|
-
tx, ty = 0, image.get_size()[1] * 2 + 50
|
|
119
|
-
for tile in range(self.shapes-1):
|
|
120
|
-
rect = getattr(self.coll, tilemap.collisionShapes.rects[tile]).copy()
|
|
121
|
-
rect.x += tx
|
|
122
|
-
rect.y += ty
|
|
123
|
-
pygame.draw.rect(Global.screen, "yellow", rect, 5)
|
|
124
|
-
outline = pygame.Rect(tx, ty, self.size, self.size)
|
|
125
|
-
pygame.draw.rect(Global.screen, "gray", outline, 2)
|
|
126
|
-
tx += self.size + self.size / 2
|
|
127
|
-
#paint mode
|
|
128
|
-
if self.mode == "paint":
|
|
129
|
-
#draw tile around mouse
|
|
130
|
-
rect = getattr(self.coll, tilemap.collisionShapes.rects[self.selectedTile]).copy()
|
|
131
|
-
rect.x += x - self.size / 2
|
|
132
|
-
rect.y += y - self.size / 2
|
|
133
|
-
pygame.draw.rect(Global.screen, "yellow", rect, 5)
|
|
134
|
-
outline = pygame.Rect(x, y, self.size, self.size)
|
|
135
|
-
outline.center = (Keys.mouse_x, Keys.mouse_y)
|
|
136
|
-
pygame.draw.rect(Global.screen, "gray", outline, 2)
|
|
137
|
-
#paint collisions
|
|
138
|
-
size = tilemap.orginDim[0]
|
|
139
|
-
if pygame.mouse.get_pressed()[0]:
|
|
140
|
-
x = (x - (x % self.size)) // self.size
|
|
141
|
-
y = (y - (y % self.size)) // self.size
|
|
142
|
-
px = x * size
|
|
143
|
-
py = y * size
|
|
144
|
-
if (int(px), int(py)) in tilemap.posToTile:
|
|
145
|
-
tilemap.collisionDict[str(tilemap.posToTile[(int(px), int(py))])] = self.coll.rects[self.selectedTile]
|
|
146
|
-
#erase collisions
|
|
147
|
-
if pygame.mouse.get_pressed()[2]:
|
|
148
|
-
x = (x - (x % self.size)) // self.size
|
|
149
|
-
y = (y - (y % self.size)) // self.size
|
|
150
|
-
px = x * size
|
|
151
|
-
py = y * size
|
|
152
|
-
if (int(px), int(py)) in tilemap.posToTile:
|
|
153
|
-
tilemap.collisionDict[tilemap.posToTile[(int(px), int(py))]] = "none"
|
|
154
|
-
|
|
155
|
-
elif self.mode == "select":
|
|
156
|
-
#get tile at mouse
|
|
157
|
-
x = int(x // (self.size + self.size / 2))
|
|
158
|
-
#draw underline
|
|
159
|
-
underline = pygame.Rect((0, 0), (self.size, 5))
|
|
160
|
-
underline.center = (Keys.mouse_x, ty + self.size+5)
|
|
161
|
-
pygame.draw.rect(Global.screen, "black", underline)
|
|
162
|
-
#select tile
|
|
163
|
-
if pygame.mouse.get_pressed()[0] and x < self.shapes-1 and x >= 0:
|
|
164
|
-
self.selectedTile = int(x)
|
|
165
|
-
|
|
166
|
-
|
GameBox/tilemap/_tilemap.py
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
import numpy as np
|
|
3
|
-
import json
|
|
4
|
-
|
|
5
|
-
from ..basics._net import Global
|
|
6
|
-
|
|
7
|
-
from ._collisionDef import _tileCollisionDefs
|
|
8
|
-
from ._Editor import _tilemapEditor
|
|
9
|
-
|
|
10
|
-
class TileMap:
|
|
11
|
-
def __init__(self, tileSet: str, tileDim: tuple, tileScale: float, mapDim: tuple, mapFill: int, saveFile = None):
|
|
12
|
-
self.tilesetFile = tileSet
|
|
13
|
-
self.mapFile = saveFile
|
|
14
|
-
self.tileDim = (tileDim[0] * tileScale, tileDim[1] * tileScale)
|
|
15
|
-
self.tileDim = (self.tileDim[0] * Global.cam.scale, self.tileDim[1] * Global.cam.scale)
|
|
16
|
-
self.mapDim = mapDim
|
|
17
|
-
self.tilescale = tileScale
|
|
18
|
-
self.orginDim = tileDim
|
|
19
|
-
|
|
20
|
-
self.tilesetNum = 0
|
|
21
|
-
|
|
22
|
-
self.editor = None
|
|
23
|
-
|
|
24
|
-
Global.game.objs.append(self)
|
|
25
|
-
|
|
26
|
-
self.collisionShapes = _tileCollisionDefs(self.tileDim)
|
|
27
|
-
|
|
28
|
-
self.collisionDict = {}
|
|
29
|
-
|
|
30
|
-
self.tilePosInImage = {}
|
|
31
|
-
self.posToTile = {}
|
|
32
|
-
|
|
33
|
-
#map, tile splitting, ect
|
|
34
|
-
#--create map
|
|
35
|
-
self.map = np.full(self.mapDim, mapFill)
|
|
36
|
-
#--split map into tiles
|
|
37
|
-
self.tiles = {}
|
|
38
|
-
tileset = pygame.image.load(tileSet).convert_alpha()
|
|
39
|
-
self.tileset = tileset
|
|
40
|
-
tile_w, tile_h = tileDim
|
|
41
|
-
tile_id = 1
|
|
42
|
-
tileset_w, tileset_h = tileset.get_size()
|
|
43
|
-
|
|
44
|
-
for y in range(0, tileset_h, tile_h):
|
|
45
|
-
for x in range(0, tileset_w, tile_w):
|
|
46
|
-
tile = pygame.Surface(tileDim, pygame.SRCALPHA)
|
|
47
|
-
tile.blit(tileset, (0, 0), (x, y, tile_w, tile_h))
|
|
48
|
-
self.tiles[tile_id] = pygame.transform.scale(tile, self.tileDim)
|
|
49
|
-
self.tilePosInImage[tile_id] = (x, y)
|
|
50
|
-
self.posToTile[(x, y)] = tile_id
|
|
51
|
-
self.tilesetNum += 1
|
|
52
|
-
tile_id += 1
|
|
53
|
-
|
|
54
|
-
Global.tilemap.append(self)
|
|
55
|
-
|
|
56
|
-
def load_map_from_json(self, filePath: str):
|
|
57
|
-
with open(filePath, "r") as f:
|
|
58
|
-
data = json.load(f)
|
|
59
|
-
self.__private_loadData(filePath, data)
|
|
60
|
-
|
|
61
|
-
def __private_loadData(self, path: str, data: dict):
|
|
62
|
-
self.map = np.array(data["map"])
|
|
63
|
-
self.mapFile = path
|
|
64
|
-
self.collisionDict = data["collisions"]
|
|
65
|
-
|
|
66
|
-
def activate_editor(self, activation):
|
|
67
|
-
print(f"editor activated. press {activation} to toggle")
|
|
68
|
-
self.editor = _tilemapEditor(self, activation)
|
|
69
|
-
|
|
70
|
-
def update(self):
|
|
71
|
-
self.draw_tiles()
|
|
72
|
-
if self.editor is not None: self.editor._update()
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def draw_tiles(self):
|
|
76
|
-
for y in range(self.mapDim[1]):
|
|
77
|
-
for x in range(self.mapDim[0]):
|
|
78
|
-
if self.map[y][x] == 0:
|
|
79
|
-
continue
|
|
80
|
-
tile = self.tiles[self.map[y][x]]
|
|
81
|
-
mx = (x * self.tileDim[0]) - Global.cam.x
|
|
82
|
-
my = (y * self.tileDim[1]) - Global.cam.y
|
|
83
|
-
if mx < -self.tileDim[0] or mx > Global.screenDim[0] or my < -self.tileDim[1] or my > Global.screenDim[1]: continue
|
|
84
|
-
Global.screen.blit(tile, (mx, my))
|
|
85
|
-
|
|
86
|
-
def _quit(self):
|
|
87
|
-
#save map
|
|
88
|
-
if self.mapFile is not None:
|
|
89
|
-
print('tilemap saved')
|
|
90
|
-
with open(self.mapFile, "w") as f:
|
|
91
|
-
data = {}
|
|
92
|
-
data["map"] = self.map.tolist()
|
|
93
|
-
data["collisions"] = self.collisionDict
|
|
94
|
-
json.dump(data, f)
|
GameBox/ui/_basicUI.py
DELETED
|
@@ -1,36 +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
|
-
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)
|
gamebox-0.9.2.dist-info/RECORD
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
GameBox/__init__.py,sha256=HVJfnUcXHAjp4wIR_uz4u9lwLZpiChdvzf6y0aPvkj8,1025
|
|
2
|
-
GameBox/_game.py,sha256=cxlY7skQHK2OXnqgdusXwfc_0hDy7Hu3oq8o5iKzSLU,2252
|
|
3
|
-
GameBox/GameLevel_ui/_Animations.py,sha256=nza-F3Rii6VWAvIkSKNr1CpkJXxq4jLqZcYfb0Sk1hI,1051
|
|
4
|
-
GameBox/GameLevel_ui/_sprites.py,sha256=lRtMuGtd-5kfUPmJ_20j5fOmWdaIhKxfcCdVYM4oazc,5664
|
|
5
|
-
GameBox/basics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
GameBox/basics/_net.py,sha256=65qMVXyILKGE8VnJcW_jxmJ1UxmENktbHvRWaTq5U0A,839
|
|
7
|
-
GameBox/basics/_shapes.py,sha256=Rbkd0lrpxGvbVdwL98_iovFtqB1USI5Qk6umJPR0CIc,1314
|
|
8
|
-
GameBox/basics/cammera.py,sha256=eP7cNkTruZ9CDf94VGTsjgdI4NNnWjN-ilCHgGLYNSs,941
|
|
9
|
-
GameBox/basics/utils.py,sha256=w6H34MhxcNoX58iQtlvbT5-4GXefy3RIMTxZGP9fSxA,432
|
|
10
|
-
GameBox/helpers/_Conditions.py,sha256=FSqwJWL0QBvCQmSyzhL5LtudhP5c-tRzC_8xuQENsGw,1946
|
|
11
|
-
GameBox/helpers/_collisions.py,sha256=q29j6N1bNh7hp9OoX5ipODLf4n6FjPzGb8vNSZ_x4Oc,5692
|
|
12
|
-
GameBox/helpers/_input.py,sha256=97bPxM5dkonRywOhj11lgHVQVicuLAKYi_w8EPM0Af8,1963
|
|
13
|
-
GameBox/player/_player.py,sha256=HU7iOBoHj5oXJTA-lHmwPZbFt8CXm-IPzK3NWBGzRhM,1872
|
|
14
|
-
GameBox/player/_playerControler.py,sha256=XEb87RFlgLFoXnXqxIS4lpzHN0wywMNCX5y-NIhw0cs,1715
|
|
15
|
-
GameBox/player/_playerPhysics.py,sha256=-6u-TZH_i78bwFMZwCIHP0VnQA0nOlcQtkq07rxwKwg,2919
|
|
16
|
-
GameBox/player/_playerSprite.py,sha256=7j9hqesdOvyyP4jF83VJRbpno_oYgOt31rdYKezVknk,3519
|
|
17
|
-
GameBox/tilemap/_Editor.py,sha256=98JcwAvL6JgSG2S-V-527lwpfzbE-A-BbezCI9EfTyI,1027
|
|
18
|
-
GameBox/tilemap/_collisionDef.py,sha256=VxWcfz3nlhyYI_Hemp-LvC6IDC-YN6wIdRaU8AsgipU,1621
|
|
19
|
-
GameBox/tilemap/_editorBrushes.py,sha256=GFfRV0OB3t9sFb37eO3sB8Cmwyd5i_q64q5IjYlkx1k,7247
|
|
20
|
-
GameBox/tilemap/_tilemap.py,sha256=SEQlokpsUO9zQkLMF-j6amx1FqNeD2eM2CRFj3zCnZ8,3330
|
|
21
|
-
GameBox/ui/_basicUI.py,sha256=LnlQ-YNHFypohjal3eYRws9H52iCLUyRuZWg6n5Fg0o,1007
|
|
22
|
-
gamebox-0.9.2.dist-info/METADATA,sha256=8FWr5TfY0d3CxfiJlDUAPO1oq0AfDAmfqVyu8H7oir4,1059
|
|
23
|
-
gamebox-0.9.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
24
|
-
gamebox-0.9.2.dist-info/licenses/LICENSE,sha256=gcuuhKKc5-dwvyvHsXjlC9oM6N5gZ6umYbC8ewW1Yvg,35821
|
|
25
|
-
gamebox-0.9.2.dist-info/RECORD,,
|