mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-06 06:26:13 +00:00
added through breakable
This commit is contained in:
@@ -58,7 +58,7 @@ LastTarget = nil
|
||||
math.randomseed(os.time())
|
||||
function Update()
|
||||
log("NEW FRAME")
|
||||
--local path = getPath(0, 0, 16, 16);
|
||||
local path = getPath(0, 0, 16, 16, true);
|
||||
|
||||
local player = getPlayer()
|
||||
if LastTarget ~= nil then
|
||||
|
||||
@@ -70,6 +70,11 @@ namespace LuaG
|
||||
return res;
|
||||
}
|
||||
|
||||
bool State::getBool(int idx)
|
||||
{
|
||||
return lua_toboolean(_state, idx);
|
||||
}
|
||||
|
||||
float State::getNumber(int idx)
|
||||
{
|
||||
return lua_tonumber(_state, idx);
|
||||
|
||||
@@ -52,6 +52,9 @@ namespace LuaG
|
||||
//! @brief Get return Number
|
||||
bool getReturnBool(void);
|
||||
|
||||
//! @brief Get bool at index in the stack
|
||||
bool getBool(int index);
|
||||
|
||||
//! @brief Get Number at index in the stack
|
||||
float getNumber(int index);
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace BBM
|
||||
return path;
|
||||
}
|
||||
|
||||
std::vector<Vector2f> LuaMap::getNeighbors(Vector2f node) const
|
||||
std::vector<Vector2f> LuaMap::getNeighbors(Vector2f node, bool throughBreakable) const
|
||||
{
|
||||
std::vector<Vector2f> neighbors;
|
||||
for (auto &dir : _dirs) {
|
||||
@@ -65,7 +65,8 @@ namespace BBM
|
||||
continue;
|
||||
if (neighbor.y >= 17 || neighbor.x >= 17)
|
||||
continue;
|
||||
if (_map[neighbor.y][neighbor.x] == 0 &&
|
||||
if ((_map[neighbor.y][neighbor.x] == 0 ||
|
||||
_map[neighbor.y][neighbor.x] == throughBreakable) &&
|
||||
_danger[neighbor.y][neighbor.x] != 1)
|
||||
neighbors.push_back(neighbor);
|
||||
}
|
||||
@@ -83,7 +84,7 @@ namespace BBM
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
std::vector<Vector2f> LuaMap::pathfind(Vector2f root, Vector2f target) const
|
||||
std::vector<Vector2f> LuaMap::pathfind(Vector2f root, Vector2f target, bool throughBreakable) const
|
||||
{
|
||||
std::vector<Vector2f> closed;
|
||||
std::vector<Vector2f> open;
|
||||
@@ -117,7 +118,7 @@ namespace BBM
|
||||
}
|
||||
open.erase(std::remove(open.begin(), open.end(), current), open.end());
|
||||
closed.push_back(current);
|
||||
auto neighbors = getNeighbors(current);
|
||||
auto neighbors = getNeighbors(current, throughBreakable);
|
||||
for (auto &neighbor : neighbors) {
|
||||
if (std::find(closed.begin(), closed.end(), neighbor) != closed.end())
|
||||
continue;
|
||||
@@ -224,14 +225,16 @@ namespace BBM
|
||||
int LuaMap::getPath(lua_State *L)
|
||||
{
|
||||
LuaG::State state(L);
|
||||
auto y2 = state.getNumber(-1);
|
||||
auto x2 = state.getNumber(-2);
|
||||
auto y1 = state.getNumber(-3);
|
||||
auto x1 = state.getNumber(-4);
|
||||
const LuaMap *map = reinterpret_cast<const LuaMap *>(state.getPointer(state.getFirstUpValueIdx()));
|
||||
auto throughBreakable = state.getBool(-1);
|
||||
auto y2 = state.getNumber(-2);
|
||||
auto x2 = state.getNumber(-3);
|
||||
auto y1 = state.getNumber(-4);
|
||||
auto x1 = state.getNumber(-5);
|
||||
|
||||
const LuaMap *map = reinterpret_cast<const LuaMap *>(state.getPointer(state.getFirstUpValueIdx()));
|
||||
Vector2f fst(x1, y1);
|
||||
Vector2f snd(x2, y2);
|
||||
auto path = map->pathfind(fst, snd);
|
||||
auto path = map->pathfind(fst, snd, throughBreakable);
|
||||
int index = 1;
|
||||
state.newTable();
|
||||
for (auto &r : path) {
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace BBM
|
||||
void setPlayer(Vector3f pos);
|
||||
|
||||
//! @brief A star pathfinding between two points
|
||||
std::vector<Vector2f> pathfind(Vector2f, Vector2f) const;
|
||||
std::vector<Vector2f> pathfind(Vector2f root, Vector2f target, bool throughBreakable) const;
|
||||
|
||||
//! @brief find a safe space for current player
|
||||
Vector2f findSafeSpace(const std::vector<std::vector<int>> &dangerMap) const;
|
||||
@@ -95,7 +95,7 @@ namespace BBM
|
||||
std::unordered_map<Vector2f, Vector2f> &cameFrom, Vector2f node) const;
|
||||
|
||||
//! @brief get neighbors of node for a_star
|
||||
std::vector<Vector2f> getNeighbors(Vector2f node) const;
|
||||
std::vector<Vector2f> getNeighbors(Vector2f node, bool throughBreakable) const;
|
||||
|
||||
std::vector<Vector2f> _dirs = {
|
||||
Vector2f(1, 0), Vector2f(-1, 0), Vector2f(0, 1), Vector2f(0, -1)
|
||||
|
||||
Reference in New Issue
Block a user