GameBox 0.1.3__py3-none-any.whl → 0.2.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/_game.py +2 -1
- GameBox/basics/_net.py +2 -1
- GameBox/helpers/_collisions.py +110 -0
- GameBox/helpers/_input.py +6 -1
- GameBox/player/_playerPhysics.py +4 -112
- GameBox/tilemap/_Editor.py +101 -0
- GameBox/tilemap/_tilemap.py +27 -10
- {gamebox-0.1.3.dist-info → gamebox-0.2.0.dist-info}/METADATA +2 -2
- gamebox-0.2.0.dist-info/RECORD +19 -0
- gamebox-0.1.3.dist-info/RECORD +0 -17
- {gamebox-0.1.3.dist-info → gamebox-0.2.0.dist-info}/WHEEL +0 -0
- {gamebox-0.1.3.dist-info → gamebox-0.2.0.dist-info}/licenses/LICENSE +0 -0
GameBox/_game.py
CHANGED
GameBox/basics/_net.py
CHANGED
|
@@ -14,12 +14,13 @@ class _global_:
|
|
|
14
14
|
#--game and cam
|
|
15
15
|
self.game: object = None
|
|
16
16
|
self.cam: object = None
|
|
17
|
+
self.event: pygame.event = None
|
|
17
18
|
#-collisions
|
|
18
19
|
self.collisions: list[pygame.Rect] = []
|
|
19
20
|
|
|
20
21
|
#objects
|
|
21
22
|
self.player = self._player()
|
|
22
|
-
self.tilemap
|
|
23
|
+
self.tilemap = []
|
|
23
24
|
|
|
24
25
|
class _player:
|
|
25
26
|
def __init__(self):
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from ..basics._net import Global
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def CheckCollisions(x, y, vx, vy, dim, sample, obj):
|
|
8
|
+
x, y = x + vx, y + vy
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
#basic object collisions
|
|
12
|
+
x, y, vx, vy = _mainCollisionLogic(Global.collisions, x, y, vx, vy, dim)
|
|
13
|
+
x, y, vx, vy = _checkTilemapCollisions(x, y, vx, vy, dim, sample, obj)
|
|
14
|
+
|
|
15
|
+
return x, y, vx, vy
|
|
16
|
+
|
|
17
|
+
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
|
+
# Y-axis collisions
|
|
29
|
+
new_rect = pygame.Rect((x, y), dim)
|
|
30
|
+
for collision in collisions:
|
|
31
|
+
#pygame.draw.rect(Global.screen, (255, 0, 0), collision, 1)
|
|
32
|
+
if collision.colliderect(new_rect):
|
|
33
|
+
if vy > 0: # falling
|
|
34
|
+
y = collision.top - dim[1]
|
|
35
|
+
vy = 0
|
|
36
|
+
elif vy < 0: # jumping
|
|
37
|
+
y = collision.bottom
|
|
38
|
+
vy = 0
|
|
39
|
+
|
|
40
|
+
return x, y, vx, vy
|
|
41
|
+
|
|
42
|
+
def _checkTilemapCollisions(x, y, vx, vy, dim, sample, obj):
|
|
43
|
+
if len(Global.tilemap) == 0:
|
|
44
|
+
return x, y, vx, vy
|
|
45
|
+
|
|
46
|
+
for tilemap in Global.tilemap:
|
|
47
|
+
|
|
48
|
+
#get player reletive tilemap pos
|
|
49
|
+
prect = pygame.Rect(x, y, dim[0], dim[1])
|
|
50
|
+
prx, pry = prect.center
|
|
51
|
+
if Global.cam.follow != obj:
|
|
52
|
+
if Global.cam.x != 0 or Global.cam.y != 0:
|
|
53
|
+
px = int((prx) - Global.cam.x)
|
|
54
|
+
py = int((pry) - Global.cam.y)
|
|
55
|
+
px = int(px // tilemap.tileDim[0])
|
|
56
|
+
py = int(py // tilemap.tileDim[1])
|
|
57
|
+
else:
|
|
58
|
+
px = int((x) / tilemap.tileDim[0])
|
|
59
|
+
py = int((y ) / tilemap.tileDim[1])
|
|
60
|
+
else:
|
|
61
|
+
if Global.cam.x != 0 or Global.cam.y != 0:
|
|
62
|
+
px = int(((prx + Global.cam.x)) // tilemap.tileDim[0])
|
|
63
|
+
py = int(((pry + Global.cam.y)) // tilemap.tileDim[1])
|
|
64
|
+
else:
|
|
65
|
+
px = int((x) / tilemap.tileDim[0])
|
|
66
|
+
py = int((y) / tilemap.tileDim[1])
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
#check if player is on tilemap
|
|
70
|
+
if px < 0 or px >= tilemap.mapDim[0] or py < 0 or py >= tilemap.mapDim[1]:
|
|
71
|
+
return x, y, vx, vy
|
|
72
|
+
#get collision rects around player
|
|
73
|
+
collisions: list[pygame.Rect] = []
|
|
74
|
+
for tx in range(px - sample, px + sample):
|
|
75
|
+
for ty in range(py - sample, py + sample):
|
|
76
|
+
nx = int(px + tx)
|
|
77
|
+
ny = int(py + ty)
|
|
78
|
+
#if tile is on map
|
|
79
|
+
if nx < 0 or nx >= tilemap.mapDim[0] or ny < 0 or ny >= tilemap.mapDim[1]:
|
|
80
|
+
continue
|
|
81
|
+
#if tile has defined collision shape
|
|
82
|
+
tile = str(tilemap.map[ny][nx])
|
|
83
|
+
if tile not in tilemap.collisionDict: continue
|
|
84
|
+
|
|
85
|
+
#get collision shape
|
|
86
|
+
rectshape = tilemap.collisionDict[str(tile)]
|
|
87
|
+
rect = getattr(tilemap.collisionShapes, rectshape).copy()
|
|
88
|
+
|
|
89
|
+
# Position rect correctly in the world
|
|
90
|
+
if Global.cam.follow != obj:
|
|
91
|
+
if Global.cam.x != 0 or Global.cam.y != 0:
|
|
92
|
+
rect.x = ((nx * tilemap.tileDim[0])) - Global.cam.x
|
|
93
|
+
rect.y = ((ny * tilemap.tileDim[1])) - Global.cam.y
|
|
94
|
+
else:
|
|
95
|
+
rect.x += (nx * tilemap.tileDim[0]) - Global.cam.x
|
|
96
|
+
rect.y += (ny * tilemap.tileDim[1]) - Global.cam.y
|
|
97
|
+
else:
|
|
98
|
+
if Global.cam.x != 0 or Global.cam.y != 0:
|
|
99
|
+
rect.x += ((nx * tilemap.tileDim[0])) - Global.cam.x
|
|
100
|
+
rect.y += ((ny * tilemap.tileDim[1])) - Global.cam.y
|
|
101
|
+
else:
|
|
102
|
+
rect.x += (nx * tilemap.tileDim[0]) - Global.cam.x
|
|
103
|
+
rect.y += (ny * tilemap.tileDim[1]) - Global.cam.y
|
|
104
|
+
collisions.append(rect)
|
|
105
|
+
|
|
106
|
+
#check collisions
|
|
107
|
+
x, y, vx, vy = _mainCollisionLogic(collisions, x, y, vx, vy, dim)
|
|
108
|
+
|
|
109
|
+
return x, y, vx, vy
|
|
110
|
+
|
GameBox/helpers/_input.py
CHANGED
|
@@ -51,6 +51,7 @@ class _keys:
|
|
|
51
51
|
self.escape = pygame.K_ESCAPE
|
|
52
52
|
self.space = pygame.K_SPACE
|
|
53
53
|
self.backspace = pygame.K_BACKSPACE
|
|
54
|
+
self.tab = pygame.K_TAB
|
|
54
55
|
|
|
55
56
|
#arrow keys
|
|
56
57
|
self.up = pygame.K_UP
|
|
@@ -62,7 +63,11 @@ class _keys:
|
|
|
62
63
|
self.mouse_x, self.mouse_y = 0, 0
|
|
63
64
|
def init(self): Global.game.objs.append(self)
|
|
64
65
|
|
|
65
|
-
def is_pressed(self, key):
|
|
66
|
+
def is_pressed(self, key):
|
|
67
|
+
for event in Global.event:
|
|
68
|
+
if event.type == pygame.KEYDOWN:
|
|
69
|
+
if event.key == key: return True
|
|
70
|
+
return False
|
|
66
71
|
|
|
67
72
|
def update(self): self.mouse_x, self.mouse_y = pygame.mouse.get_pos()
|
|
68
73
|
|
GameBox/player/_playerPhysics.py
CHANGED
|
@@ -3,6 +3,7 @@ import numpy as np
|
|
|
3
3
|
|
|
4
4
|
from ..basics._net import Global
|
|
5
5
|
from ..basics.utils import clamp, moveTward, zeroOut
|
|
6
|
+
from ..helpers._collisions import CheckCollisions
|
|
6
7
|
|
|
7
8
|
class _playerPhysics:
|
|
8
9
|
def __init__(self, player, speed: float = 1.0, gravity: float = 0.0, jump: float = 0.0, maxV: float = 10.0, airRes: float = 0.2):
|
|
@@ -24,7 +25,9 @@ class _playerPhysics:
|
|
|
24
25
|
|
|
25
26
|
def update(self):
|
|
26
27
|
self.ckeck_is_on_ground()
|
|
27
|
-
x, y = self.
|
|
28
|
+
x, y, self.vx, self.vy = CheckCollisions(self.player.x, self.player.y,
|
|
29
|
+
self.vx, self.vy, self.player.dim,
|
|
30
|
+
self.sample,self.player)
|
|
28
31
|
if (Global.cam.follow) != (self.player):
|
|
29
32
|
self.player.x = x
|
|
30
33
|
self.player.y = y
|
|
@@ -32,117 +35,6 @@ class _playerPhysics:
|
|
|
32
35
|
dx = -(self.player.x - x)
|
|
33
36
|
dy = -(self.player.y - y)
|
|
34
37
|
Global.cam.move(self.vx, self.vy)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def check_collisions(self):
|
|
38
|
-
x, y = self.player.x + self.vx, self.player.y + self.vy
|
|
39
|
-
|
|
40
|
-
#basic object collisions
|
|
41
|
-
x, y = self.collisionLogic(Global.collisions, x, y)
|
|
42
|
-
x, y = self.tilemap_collisions(x, y)
|
|
43
|
-
|
|
44
|
-
return x, y
|
|
45
|
-
|
|
46
|
-
def collisionLogic(self, collisions, x, y):
|
|
47
|
-
new_rect = pygame.Rect((x, self.player.y), self.player.dim)
|
|
48
|
-
for collision in collisions:
|
|
49
|
-
#pygame.draw.rect(Global.screen, (255, 0, 0), collision, 1)
|
|
50
|
-
if collision.colliderect(new_rect):
|
|
51
|
-
if self.vx > 0:
|
|
52
|
-
x = collision.left - self.player.dim[0]
|
|
53
|
-
elif self.vx < 0:
|
|
54
|
-
x = collision.right
|
|
55
|
-
self.vx = 0
|
|
56
|
-
|
|
57
|
-
# Y-axis collisions
|
|
58
|
-
new_rect = pygame.Rect((x, y), self.player.dim)
|
|
59
|
-
for collision in collisions:
|
|
60
|
-
#pygame.draw.rect(Global.screen, (255, 0, 0), collision, 1)
|
|
61
|
-
if collision.colliderect(new_rect):
|
|
62
|
-
if self.vy > 0: # falling
|
|
63
|
-
y = collision.top - self.player.dim[1]
|
|
64
|
-
self.vy = 0
|
|
65
|
-
elif self.vy < 0: # jumping
|
|
66
|
-
y = collision.bottom
|
|
67
|
-
self.vy = 0
|
|
68
|
-
|
|
69
|
-
return x, y
|
|
70
|
-
|
|
71
|
-
def tilemap_collisions(self, x, y):
|
|
72
|
-
sample = self.sample
|
|
73
|
-
if Global.tilemap is None:
|
|
74
|
-
return x, y
|
|
75
|
-
|
|
76
|
-
#get player reletive tilemap pos
|
|
77
|
-
prect = pygame.Rect(x, y, self.player.dim[0], self.player.dim[1])
|
|
78
|
-
prx, pry = prect.center
|
|
79
|
-
if Global.cam.follow != self.player:
|
|
80
|
-
if Global.cam.x != 0 or Global.cam.y != 0:
|
|
81
|
-
px = int((prx - Global.tilemap.offset[0]) - Global.cam.x)
|
|
82
|
-
py = int((pry - Global.tilemap.offset[1]) - Global.cam.y)
|
|
83
|
-
px = int(px // Global.tilemap.tileDim[0])
|
|
84
|
-
py = int(py // Global.tilemap.tileDim[1])
|
|
85
|
-
else:
|
|
86
|
-
px = int((x - Global.tilemap.offset[0]) / Global.tilemap.tileDim[0])
|
|
87
|
-
py = int((y - Global.tilemap.offset[1]) / Global.tilemap.tileDim[1])
|
|
88
|
-
else:
|
|
89
|
-
if Global.cam.x != 0 or Global.cam.y != 0:
|
|
90
|
-
px = int(((prx + Global.cam.x)-Global.tilemap.offset[0]) // Global.tilemap.tileDim[0])
|
|
91
|
-
py = int(((pry + Global.cam.y)-Global.tilemap.offset[1]) // Global.tilemap.tileDim[1])
|
|
92
|
-
else:
|
|
93
|
-
px = int((x - Global.tilemap.offset[0]) / Global.tilemap.tileDim[0])
|
|
94
|
-
py = int((y - Global.tilemap.offset[1]) / Global.tilemap.tileDim[1])
|
|
95
|
-
|
|
96
|
-
#draw collision rect
|
|
97
|
-
#print(f"px: {px}, py: {py} | cam.x: {Global.cam.x}, cam.y: {Global.cam.y} | x: {x}, y: {y}")
|
|
98
|
-
#rect = pygame.Rect(px , py, self.player.dim[0], self.player.dim[1])
|
|
99
|
-
#pygame.draw.rect(Global.screen, "red", rect)
|
|
100
|
-
#rect.x *= Global.tilemap.tileDim[0]
|
|
101
|
-
#rect.y *= Global.tilemap.tileDim[1]
|
|
102
|
-
#pygame.draw.rect(Global.screen, "yellow", rect, 1)
|
|
103
|
-
#pygame.display.update(rect)
|
|
104
|
-
|
|
105
|
-
#check if player is on tilemap
|
|
106
|
-
if px < 0 or px >= Global.tilemap.mapDim[0] or py < 0 or py >= Global.tilemap.mapDim[1]:
|
|
107
|
-
return x, y
|
|
108
|
-
#get collision rects around player
|
|
109
|
-
collisions: list[pygame.Rect] = []
|
|
110
|
-
for tx in range(px - sample, px + sample):
|
|
111
|
-
for ty in range(py - sample, py + sample):
|
|
112
|
-
nx = int(px + tx)
|
|
113
|
-
ny = int(py + ty)
|
|
114
|
-
#if tile is on map
|
|
115
|
-
if nx < 0 or nx >= Global.tilemap.mapDim[0] or ny < 0 or ny >= Global.tilemap.mapDim[1]:
|
|
116
|
-
continue
|
|
117
|
-
#if tile has defined collision shape
|
|
118
|
-
tile = str(Global.tilemap.map[ny][nx])
|
|
119
|
-
if tile not in Global.tilemap.collisionDict: continue
|
|
120
|
-
|
|
121
|
-
#get collision shape
|
|
122
|
-
rectshape = Global.tilemap.collisionDict[str(tile)]
|
|
123
|
-
rect = getattr(Global.tilemap.collisionShapes, rectshape).copy()
|
|
124
|
-
|
|
125
|
-
# Position rect correctly in the world
|
|
126
|
-
if Global.cam.follow != self.player:
|
|
127
|
-
if Global.cam.x != 0 or Global.cam.y != 0:
|
|
128
|
-
rect.x = ((nx * Global.tilemap.tileDim[0]) + Global.tilemap.offset[0]) - Global.cam.x
|
|
129
|
-
rect.y = ((ny * Global.tilemap.tileDim[1]) + Global.tilemap.offset[1]) - Global.cam.y
|
|
130
|
-
else:
|
|
131
|
-
rect.x += (nx * Global.tilemap.tileDim[0] + Global.tilemap.offset[0]) - Global.cam.x
|
|
132
|
-
rect.y += (ny * Global.tilemap.tileDim[1] + Global.tilemap.offset[1]) - Global.cam.y
|
|
133
|
-
else:
|
|
134
|
-
if Global.cam.x != 0 or Global.cam.y != 0:
|
|
135
|
-
rect.x += ((nx * Global.tilemap.tileDim[0]) + Global.tilemap.offset[0]) - Global.cam.x
|
|
136
|
-
rect.y += ((ny * Global.tilemap.tileDim[1]) + Global.tilemap.offset[1]) - Global.cam.y
|
|
137
|
-
else:
|
|
138
|
-
rect.x += (nx * Global.tilemap.tileDim[0] + Global.tilemap.offset[0]) - Global.cam.x
|
|
139
|
-
rect.y += (ny * Global.tilemap.tileDim[1] + Global.tilemap.offset[1]) - Global.cam.y
|
|
140
|
-
collisions.append(rect)
|
|
141
|
-
|
|
142
|
-
#check collisions
|
|
143
|
-
x, y = self.collisionLogic(collisions, x, y)
|
|
144
|
-
|
|
145
|
-
return x, y
|
|
146
38
|
|
|
147
39
|
|
|
148
40
|
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from..helpers._input import Keys
|
|
5
|
+
from ..basics._net import Global
|
|
6
|
+
|
|
7
|
+
class _tilemapEditor:
|
|
8
|
+
def __init__(self, tilemap, activation):
|
|
9
|
+
self.tilemap = tilemap
|
|
10
|
+
self.activation = activation
|
|
11
|
+
self.active = False
|
|
12
|
+
|
|
13
|
+
self.selectedTile = 1
|
|
14
|
+
self.mx, self.my = Keys.mouse_x, Keys.mouse_y
|
|
15
|
+
|
|
16
|
+
self.mode = "paint"
|
|
17
|
+
|
|
18
|
+
def _update(self):
|
|
19
|
+
if self.active:
|
|
20
|
+
#update mouse pos
|
|
21
|
+
self.mx, self.my = Keys.mouse_x, Keys.mouse_y
|
|
22
|
+
self.mx += Global.cam.x
|
|
23
|
+
self.my += Global.cam.y
|
|
24
|
+
self.mx = self.mx // self.tilemap.tileDim[0] * self.tilemap.tileDim[0]
|
|
25
|
+
self.my = self.my // self.tilemap.tileDim[1] * self.tilemap.tileDim[1]
|
|
26
|
+
|
|
27
|
+
self._mode_()
|
|
28
|
+
self.moveSelectionByArrowKeys()
|
|
29
|
+
self.ui()
|
|
30
|
+
|
|
31
|
+
#toggle
|
|
32
|
+
if Keys.is_pressed(self.activation): self.active = not self.active
|
|
33
|
+
|
|
34
|
+
def _mode_(self):
|
|
35
|
+
x, y = Keys.mouse_x, Keys.mouse_y
|
|
36
|
+
if x > self.tilemap.tileset.get_size()[0] * self.tilemap.tilescale / 2 or y > self.tilemap.tileset.get_size()[1] * self.tilemap.tilescale / 2:
|
|
37
|
+
self.mode = "paint"
|
|
38
|
+
#more parrimeters will be placed as needed
|
|
39
|
+
else:
|
|
40
|
+
self.mode = "select"
|
|
41
|
+
|
|
42
|
+
def ui(self):
|
|
43
|
+
tile = self.tilemap.tiles[self.selectedTile]
|
|
44
|
+
image = pygame.transform.scale_by(self.tilemap.tileset, self.tilemap.tilescale / 2)
|
|
45
|
+
Global.screen.blit(image, (0, 0))
|
|
46
|
+
#show outlined sellected tile
|
|
47
|
+
x, y = self.tilemap.tilePosInImage[self.selectedTile]
|
|
48
|
+
x *= self.tilemap.tilescale / 2
|
|
49
|
+
y *= self.tilemap.tilescale / 2
|
|
50
|
+
width = self.tilemap.orginDim[0] * self.tilemap.tilescale / 2
|
|
51
|
+
height = self.tilemap.orginDim[1] * self.tilemap.tilescale / 2
|
|
52
|
+
outline = pygame.Rect(x, y, width, height)
|
|
53
|
+
pygame.draw.rect(Global.screen, "white", outline, 2)
|
|
54
|
+
#other stuff
|
|
55
|
+
if self.mode == "paint":
|
|
56
|
+
#show selected tile
|
|
57
|
+
#--outline on tileset
|
|
58
|
+
#--show beside mouse
|
|
59
|
+
x = self.mx
|
|
60
|
+
y = self.my
|
|
61
|
+
|
|
62
|
+
x -= Global.cam.x
|
|
63
|
+
y -= Global.cam.y
|
|
64
|
+
Global.screen.blit(tile, (x, y))
|
|
65
|
+
if pygame.mouse.get_pressed()[0]:
|
|
66
|
+
#check if mouse is on tilemap
|
|
67
|
+
x, y = self.mx // self.tilemap.tileDim[0], self.my // self.tilemap.tileDim[1]
|
|
68
|
+
if x >= 0 and x < self.tilemap.mapDim[0] and y >= 0 and y < self.tilemap.mapDim[1]:
|
|
69
|
+
self.tilemap.map[int(y)][int(x)] = self.selectedTile
|
|
70
|
+
if pygame.mouse.get_pressed()[2]:
|
|
71
|
+
x, y = self.mx // self.tilemap.tileDim[0], self.my // self.tilemap.tileDim[1]
|
|
72
|
+
if x >= 0 and x < self.tilemap.mapDim[0] and y >= 0 and y < self.tilemap.mapDim[1]:
|
|
73
|
+
self.tilemap.map[int(y)][int(x)] = 0
|
|
74
|
+
elif self.mode == "select":
|
|
75
|
+
#paint mouse hovered tile
|
|
76
|
+
x, y = Keys.mouse_x, Keys.mouse_y
|
|
77
|
+
x = (x // width)
|
|
78
|
+
y = (y // height)
|
|
79
|
+
outline = pygame.Rect(x * width, y * width, width, height)
|
|
80
|
+
pygame.draw.rect(Global.screen, "black", outline, 2)
|
|
81
|
+
if pygame.mouse.get_pressed()[0]:
|
|
82
|
+
x *= self.tilemap.orginDim[0]
|
|
83
|
+
y *= self.tilemap.orginDim[1]
|
|
84
|
+
self.selectedTile = self.tilemap.posToTile[(int(x), int(y))]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def moveSelectionByArrowKeys(self):
|
|
88
|
+
x, y = self.tilemap.tilePosInImage[self.selectedTile]
|
|
89
|
+
|
|
90
|
+
width = 16
|
|
91
|
+
height = 16
|
|
92
|
+
|
|
93
|
+
if Keys.is_pressed(Keys.left): x -= width
|
|
94
|
+
if Keys.is_pressed(Keys.right): x += width
|
|
95
|
+
if Keys.is_pressed(Keys.up): y -= height
|
|
96
|
+
if Keys.is_pressed(Keys.down): y += height
|
|
97
|
+
|
|
98
|
+
if (int(x), int(y)) in self.tilemap.posToTile:
|
|
99
|
+
self.selectedTile = self.tilemap.posToTile[(int(x), int(y))]
|
|
100
|
+
|
|
101
|
+
|
GameBox/tilemap/_tilemap.py
CHANGED
|
@@ -5,33 +5,38 @@ import json
|
|
|
5
5
|
from ..basics._net import Global
|
|
6
6
|
|
|
7
7
|
from ._collisionDef import _tileCollisionDefs
|
|
8
|
+
from ._Editor import _tilemapEditor
|
|
8
9
|
|
|
9
10
|
class TileMap:
|
|
10
|
-
def __init__(self, tileSet: str, tileDim: tuple, tileScale: float, mapDim: tuple, mapFill: int,
|
|
11
|
+
def __init__(self, tileSet: str, tileDim: tuple, tileScale: float, mapDim: tuple, mapFill: int, saveFile = None):
|
|
11
12
|
self.tilesetFile = tileSet
|
|
12
|
-
self.mapFile =
|
|
13
|
+
self.mapFile = saveFile
|
|
13
14
|
self.tileDim = (tileDim[0] * tileScale, tileDim[1] * tileScale)
|
|
14
15
|
self.tileDim = (self.tileDim[0] * Global.cam.scale, self.tileDim[1] * Global.cam.scale)
|
|
15
16
|
self.mapDim = mapDim
|
|
16
|
-
self.offset = offset
|
|
17
17
|
self.tilescale = tileScale
|
|
18
18
|
self.orginDim = tileDim
|
|
19
19
|
|
|
20
|
+
self.editor = None
|
|
21
|
+
|
|
20
22
|
Global.game.objs.append(self)
|
|
21
|
-
Global.tilemap = self
|
|
22
23
|
|
|
23
24
|
self.collisionShapes = _tileCollisionDefs(self.tileDim)
|
|
24
25
|
|
|
25
26
|
self.collisionDict = {}
|
|
26
27
|
|
|
28
|
+
self.tilePosInImage = {}
|
|
29
|
+
self.posToTile = {}
|
|
30
|
+
|
|
27
31
|
#map, tile splitting, ect
|
|
28
32
|
#--create map
|
|
29
33
|
self.map = np.full(self.mapDim, mapFill)
|
|
30
34
|
#--split map into tiles
|
|
31
35
|
self.tiles = {}
|
|
32
36
|
tileset = pygame.image.load(tileSet).convert_alpha()
|
|
37
|
+
self.tileset = tileset
|
|
33
38
|
tile_w, tile_h = tileDim
|
|
34
|
-
tile_id =
|
|
39
|
+
tile_id = 1
|
|
35
40
|
tileset_w, tileset_h = tileset.get_size()
|
|
36
41
|
|
|
37
42
|
for y in range(0, tileset_h, tile_h):
|
|
@@ -39,10 +44,12 @@ class TileMap:
|
|
|
39
44
|
tile = pygame.Surface(tileDim, pygame.SRCALPHA)
|
|
40
45
|
tile.blit(tileset, (0, 0), (x, y, tile_w, tile_h))
|
|
41
46
|
self.tiles[tile_id] = pygame.transform.scale(tile, self.tileDim)
|
|
47
|
+
self.tilePosInImage[tile_id] = (x, y)
|
|
48
|
+
self.posToTile[(x, y)] = tile_id
|
|
42
49
|
tile_id += 1
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
Global.tilemap.append(self)
|
|
52
|
+
print(self.posToTile)
|
|
46
53
|
|
|
47
54
|
def load_map_from_json(self, filePath: str):
|
|
48
55
|
with open(filePath, "r") as f:
|
|
@@ -54,16 +61,23 @@ class TileMap:
|
|
|
54
61
|
self.mapFile = path
|
|
55
62
|
self.collisionDict = data["collisions"]
|
|
56
63
|
|
|
64
|
+
def activate_editor(self, activation):
|
|
65
|
+
print(f"editor activated. press {activation} to toggle")
|
|
66
|
+
self.editor = _tilemapEditor(self, activation)
|
|
67
|
+
|
|
57
68
|
def update(self):
|
|
58
69
|
self.draw_tiles()
|
|
70
|
+
if self.editor is not None: self.editor._update()
|
|
59
71
|
|
|
60
72
|
|
|
61
73
|
def draw_tiles(self):
|
|
62
74
|
for y in range(self.mapDim[1]):
|
|
63
75
|
for x in range(self.mapDim[0]):
|
|
76
|
+
if self.map[y][x] == 0:
|
|
77
|
+
continue
|
|
64
78
|
tile = self.tiles[self.map[y][x]]
|
|
65
|
-
mx = (x * self.tileDim[0]
|
|
66
|
-
my = (y * self.tileDim[1]
|
|
79
|
+
mx = (x * self.tileDim[0]) - Global.cam.x
|
|
80
|
+
my = (y * self.tileDim[1]) - Global.cam.y
|
|
67
81
|
if mx < -self.tileDim[0] or mx > Global.screenDim[0] or my < -self.tileDim[1] or my > Global.screenDim[1]: continue
|
|
68
82
|
Global.screen.blit(tile, (mx, my))
|
|
69
83
|
|
|
@@ -72,4 +86,7 @@ class TileMap:
|
|
|
72
86
|
if self.mapFile is not None:
|
|
73
87
|
print('tilemap saved')
|
|
74
88
|
with open(self.mapFile, "w") as f:
|
|
75
|
-
|
|
89
|
+
data = {}
|
|
90
|
+
data["map"] = self.map.tolist()
|
|
91
|
+
data["collisions"] = self.collisionDict
|
|
92
|
+
json.dump(data, f)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: GameBox
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.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
|
|
@@ -14,7 +14,7 @@ GameBox is a lightweight 2D game framework built on pygame.
|
|
|
14
14
|
This is an early technical preview of a full engine rewrite.
|
|
15
15
|
APIs may change frequently.
|
|
16
16
|
|
|
17
|
-
github:
|
|
17
|
+
github: https://github.com/sfertig/GameBox
|
|
18
18
|
|
|
19
19
|
Versioning
|
|
20
20
|
GameBox follows a modified semantic versioning scheme.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
GameBox/__init__.py,sha256=jU3a32yFDiWvSHanU2_xJHNi3Ngcqrvjn190SyKlNwE,727
|
|
2
|
+
GameBox/_game.py,sha256=QqfWQRLIiKQ-QjEGQYFLpsjEtPNuhxMqiCnPmXFyq3M,1548
|
|
3
|
+
GameBox/basics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
GameBox/basics/_net.py,sha256=tZsfUc-rOsbRPxgjzR95gY6vKa8CxM8TJhCBtDnVhtg,766
|
|
5
|
+
GameBox/basics/_shapes.py,sha256=7k5Mxnm_NdFssW6Zao8DSJAHJQM3pVWx2xZ4QDyF6lQ,1035
|
|
6
|
+
GameBox/basics/cammera.py,sha256=qo20hc5f3FLiBpFeWgBObj-EQ93Hg4RgEUtIwPIylOI,930
|
|
7
|
+
GameBox/basics/utils.py,sha256=w6H34MhxcNoX58iQtlvbT5-4GXefy3RIMTxZGP9fSxA,432
|
|
8
|
+
GameBox/helpers/_collisions.py,sha256=f19oIYsyY3G9-5J-nUVBvbuFT1EPeDwcbycIP0TLGms,4336
|
|
9
|
+
GameBox/helpers/_input.py,sha256=97bPxM5dkonRywOhj11lgHVQVicuLAKYi_w8EPM0Af8,1963
|
|
10
|
+
GameBox/player/_player.py,sha256=R0vH1mZhl6RENiQl3Vg4ACF9agR5OP50MenvhgFBYOk,1769
|
|
11
|
+
GameBox/player/_playerControler.py,sha256=XEb87RFlgLFoXnXqxIS4lpzHN0wywMNCX5y-NIhw0cs,1715
|
|
12
|
+
GameBox/player/_playerPhysics.py,sha256=XqgEC5FB5mrnlalY3M5TLScw40mSvNAc0AE9g3amEr0,2918
|
|
13
|
+
GameBox/tilemap/_Editor.py,sha256=Xed3Q33WEAKyLiTieTWDFeiTMMQm8m7cY2Bv7JzJr0o,4010
|
|
14
|
+
GameBox/tilemap/_collisionDef.py,sha256=lZCmSwIsLgxvEB3X30re_izg1DHY83IWp84NcM1cIkM,1393
|
|
15
|
+
GameBox/tilemap/_tilemap.py,sha256=fIBaAAu1Rg1iI4xEUk3Xkpe4MllpnkLzNfInj0468cw,3292
|
|
16
|
+
gamebox-0.2.0.dist-info/METADATA,sha256=2nL3q0Sg_b_tyg-shYRDrlpNAXJ0MzsZy_5tmWhdKcg,1059
|
|
17
|
+
gamebox-0.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
18
|
+
gamebox-0.2.0.dist-info/licenses/LICENSE,sha256=gcuuhKKc5-dwvyvHsXjlC9oM6N5gZ6umYbC8ewW1Yvg,35821
|
|
19
|
+
gamebox-0.2.0.dist-info/RECORD,,
|
gamebox-0.1.3.dist-info/RECORD
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
GameBox/__init__.py,sha256=jU3a32yFDiWvSHanU2_xJHNi3Ngcqrvjn190SyKlNwE,727
|
|
2
|
-
GameBox/_game.py,sha256=eG_rCsLwDhkY4AdjvnO80efswhyRrqPPxNsTSR8uIaY,1498
|
|
3
|
-
GameBox/basics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
GameBox/basics/_net.py,sha256=PWt57uI51seDLszyQBXriFEiLVNiVCBj3zpiDR9k0B4,735
|
|
5
|
-
GameBox/basics/_shapes.py,sha256=7k5Mxnm_NdFssW6Zao8DSJAHJQM3pVWx2xZ4QDyF6lQ,1035
|
|
6
|
-
GameBox/basics/cammera.py,sha256=qo20hc5f3FLiBpFeWgBObj-EQ93Hg4RgEUtIwPIylOI,930
|
|
7
|
-
GameBox/basics/utils.py,sha256=w6H34MhxcNoX58iQtlvbT5-4GXefy3RIMTxZGP9fSxA,432
|
|
8
|
-
GameBox/helpers/_input.py,sha256=XzlrMmhomNwR6XoaKsOq5nDiNPAdK-vRCQEuayCHGHA,1812
|
|
9
|
-
GameBox/player/_player.py,sha256=R0vH1mZhl6RENiQl3Vg4ACF9agR5OP50MenvhgFBYOk,1769
|
|
10
|
-
GameBox/player/_playerControler.py,sha256=XEb87RFlgLFoXnXqxIS4lpzHN0wywMNCX5y-NIhw0cs,1715
|
|
11
|
-
GameBox/player/_playerPhysics.py,sha256=m_W2SrTFscIFG70v8gj0G2grLnEM2IeyPIhgMXA48yI,8115
|
|
12
|
-
GameBox/tilemap/_collisionDef.py,sha256=lZCmSwIsLgxvEB3X30re_izg1DHY83IWp84NcM1cIkM,1393
|
|
13
|
-
GameBox/tilemap/_tilemap.py,sha256=YrDMv7h2B_awe_J9LCW1JaGXHGve2mqfgLQk4-tvxsE,2695
|
|
14
|
-
gamebox-0.1.3.dist-info/METADATA,sha256=3oHumIWtO2w1051z48ltCg6ujYfxtakvL_dDD4RfXso,1061
|
|
15
|
-
gamebox-0.1.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
16
|
-
gamebox-0.1.3.dist-info/licenses/LICENSE,sha256=gcuuhKKc5-dwvyvHsXjlC9oM6N5gZ6umYbC8ewW1Yvg,35821
|
|
17
|
-
gamebox-0.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|