collision
This commit is contained in:
parent
486a1cd17c
commit
34feb226e4
|
@ -14,7 +14,7 @@ class GridPoint:
|
|||
return f"<GridPoint {self.color}, {self.tilesprite}/{self.uisprite} {'W' if self.walkable else '-'}{'T' if self.transparent else '-'}{'V' if self.visible else '-'}{'D' if self.discovered else '-'} {self.color_overlay}/{self.tile_overlay}>"
|
||||
|
||||
class Grid:
|
||||
def __init__(self, title, gx, gy, gs, x, y, w, h):
|
||||
def __init__(self, title, gx, gy, gs, x, y, w, h, visible=False):
|
||||
self.title = title
|
||||
self.grid_x = gx
|
||||
self.grid_y = gy
|
||||
|
@ -23,8 +23,28 @@ class Grid:
|
|||
self.y = y
|
||||
self.w = w
|
||||
self.h = h
|
||||
self.visible = visible
|
||||
|
||||
self.points = []
|
||||
self.entities = []
|
||||
|
||||
def at(self, x, y):
|
||||
if not (x > 0 and y > 0 and x < self.grid_x and y < self.grid_y): return None
|
||||
return self.points[y * self.grid_y + x]
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Grid {self.grid_x}x{self.grid_y}, grid_size={self.grid_size}, (({self.x},{self.y}), ({self.w}, {self.h}))>"
|
||||
return f"<Grid {self.grid_x}x{self.grid_y}, grid_size={self.grid_size}, (({self.x},{self.y}), ({self.w}, {self.h})), visible={self.visible}>"
|
||||
|
||||
|
||||
# CGrid(Grid* _g, int _ti, int _si, int _x, int _y, bool _v)
|
||||
class Entity:
|
||||
def __init__(self, parent, tex_index, sprite_index, x, y, visible=True):
|
||||
self.parent = parent
|
||||
self.tex_index = tex_index
|
||||
self.sprite_index = sprite_index
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.visible = visible
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Entity on grid {repr(self.parent)}@({self.x},{self.y}), TI={self.tex_index}, SI={self.sprite_index}, visible={self.visible}>"
|
||||
|
|
|
@ -30,6 +30,12 @@ class TestEntity:
|
|||
def move(self, dx, dy):
|
||||
# select animation direction
|
||||
# prefer left or right for diagonals.
|
||||
grids = mcrfpy.listGrids()
|
||||
for g in grids:
|
||||
if g.title == self.grid:
|
||||
if not g.at(self.x + dx, self.y + dy).walkable:
|
||||
print("Blocked at target location.")
|
||||
return
|
||||
if (dx == 0 and dy == 0):
|
||||
direction = self.facing_direction # TODO, jump straight to computer turn
|
||||
elif (dx):
|
||||
|
@ -248,6 +254,8 @@ class TestScene:
|
|||
for p in self.grids[0].points:
|
||||
p.color = (randint(0, 255), randint(64, 192), 0)
|
||||
#print("[Python] Modifying:")
|
||||
self.grids[0].at(10, 10).color = (255, 255, 255)
|
||||
self.grids[0].at(10, 10).walkable = False
|
||||
self.grids[0].visible = True
|
||||
mcrfpy.modGrid(self.grids[0])
|
||||
print(f"Sent grid: {repr(self.grids[0])}")
|
||||
|
|
Loading…
Reference in New Issue