27 lines
478 B
C++
27 lines
478 B
C++
#include <cstdint>
|
|
#include "PlayerMove.h"
|
|
#include "pc/commcode.h"
|
|
|
|
bool PlayerMove::isValid(pos_t w, pos_t h) const {
|
|
if (x < 0 || x >= h || y < 0 || y >= w)
|
|
return false;
|
|
|
|
if ((int)dir >= 4)
|
|
return false;
|
|
|
|
auto xx = tx(), yy = ty();
|
|
if (xx < 0 || xx >= h || yy < 0 || yy >= w)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
pos_t PlayerMove::tx() const {
|
|
return x + direction_dx[(std::size_t)dir];
|
|
}
|
|
|
|
pos_t PlayerMove::ty() const {
|
|
return y + direction_dy[(std::size_t)dir];
|
|
}
|
|
|