Add line collision checking to geom2d functions.
This commit is contained in:
parent
60c8317b20
commit
5a8527f51b
@ -831,13 +831,10 @@ void Crawler::LoadLevel(MapName map){
|
|||||||
int tileSheetY=tileSheetIndex/tileSheetWidth;
|
int tileSheetY=tileSheetIndex/tileSheetWidth;
|
||||||
if(IsForegroundTile(tileSheet,tileSheetIndex)){
|
if(IsForegroundTile(tileSheet,tileSheetIndex)){
|
||||||
TileRenderData tile={tileSheet.tileset.tileset->Decal(),vi2d{x,y}*24,vi2d{tileSheetX,tileSheetY}*24};
|
TileRenderData tile={tileSheet.tileset.tileset->Decal(),vi2d{x,y}*24,vi2d{tileSheetX,tileSheetY}*24};
|
||||||
std::cout<<"Tile "<<vi2d{x,y}<<" w/Tile ID "<<tileSheetIndex<<" is foreground tile."<<std::endl;
|
|
||||||
bool foundGroup=false;
|
bool foundGroup=false;
|
||||||
for(TileGroup&group:foregroundTileGroups){
|
for(TileGroup&group:foregroundTileGroups){
|
||||||
if(geom2d::overlaps(geom2d::rect<int>{vi2d{x,y}*24-vi2d{1,1},{26,26}},group.GetRange())){
|
if(geom2d::overlaps(geom2d::rect<int>{vi2d{x,y}*24-vi2d{1,1},{26,26}},group.GetRange())){
|
||||||
std::cout<<" Group found: "<<group.GetRange().pos<<"/"<<group.GetRange().size<<std::endl;
|
|
||||||
group.InsertTile(tile);
|
group.InsertTile(tile);
|
||||||
std::cout<<" After: "<<group.GetRange().pos<<"/"<<group.GetRange().size<<std::endl;
|
|
||||||
foundGroup=true;
|
foundGroup=true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -845,7 +842,6 @@ void Crawler::LoadLevel(MapName map){
|
|||||||
if(!foundGroup){
|
if(!foundGroup){
|
||||||
TileGroup group;
|
TileGroup group;
|
||||||
group.InsertTile(tile);
|
group.InsertTile(tile);
|
||||||
std::cout<<" No Group found. New group: "<<group.GetRange().pos<<"/"<<group.GetRange().size<<std::endl;
|
|
||||||
foregroundTileGroups.push_back(group);
|
foregroundTileGroups.push_back(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,9 @@ void Monster::PerformJumpAnimation(){
|
|||||||
case SLIME_RED:{
|
case SLIME_RED:{
|
||||||
animation.ChangeState(internal_animState,AnimationState::RED_SLIME_JUMP);
|
animation.ChangeState(internal_animState,AnimationState::RED_SLIME_JUMP);
|
||||||
}break;
|
}break;
|
||||||
|
case SLIME_YELLOW:{
|
||||||
|
animation.ChangeState(internal_animState,AnimationState::YELLOW_SLIME_JUMP);
|
||||||
|
}break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Monster::PerformShootAnimation(){
|
void Monster::PerformShootAnimation(){
|
||||||
@ -103,6 +106,9 @@ void Monster::PerformShootAnimation(){
|
|||||||
case SLIME_RED:{
|
case SLIME_RED:{
|
||||||
animation.ChangeState(internal_animState,AnimationState::RED_SLIME_SPIT);
|
animation.ChangeState(internal_animState,AnimationState::RED_SLIME_SPIT);
|
||||||
}break;
|
}break;
|
||||||
|
case SLIME_YELLOW:{
|
||||||
|
animation.ChangeState(internal_animState,AnimationState::YELLOW_SLIME_SPIT);
|
||||||
|
}break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Monster::SetX(float x){
|
void Monster::SetX(float x){
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 0
|
#define VERSION_PATCH 0
|
||||||
#define VERSION_BUILD 217
|
#define VERSION_BUILD 221
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
@ -585,8 +585,9 @@ namespace olc::utils::geom2d
|
|||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
inline constexpr bool overlaps(const line<T1>& l1, const line<T2>& l2)
|
inline constexpr bool overlaps(const line<T1>& l1, const line<T2>& l2)
|
||||||
{
|
{
|
||||||
// TODO:
|
float uA = ((l2.end.x-l2.start.x)*(l1.start.y-l2.start.y) - (l2.end.y-l2.start.y)*(l1.start.x-l2.start.x)) / ((l2.end.y-l2.start.y)*(l1.end.x-l1.start.x) - (l2.end.x-l2.start.x)*(l1.end.y-l1.start.y));
|
||||||
return false;
|
float uB = ((l1.end.x-l1.start.x)*(l1.start.y-l2.start.y) - (l1.end.y-l1.start.y)*(l1.start.x-l2.start.x)) / ((l2.end.y-l2.start.y)*(l1.end.x-l1.start.x) - (l2.end.x-l2.start.x)*(l1.end.y-l1.start.y));
|
||||||
|
return uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if rectangle overlaps line segment
|
// Check if rectangle overlaps line segment
|
||||||
@ -633,7 +634,14 @@ namespace olc::utils::geom2d
|
|||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
inline std::vector<olc::v2d_generic<T2>> intersects(const line<T1>& l1, const line<T2>& l2)
|
inline std::vector<olc::v2d_generic<T2>> intersects(const line<T1>& l1, const line<T2>& l2)
|
||||||
{
|
{
|
||||||
// TODO:
|
float uA = ((l2.end.x-l2.start.x)*(l1.start.y-l2.start.y) - (l2.end.y-l2.start.y)*(l1.start.x-l2.start.x)) / ((l2.end.y-l2.start.y)*(l1.end.x-l1.start.x) - (l2.end.x-l2.start.x)*(l1.end.y-l1.start.y));
|
||||||
|
float uB = ((l1.end.x-l1.start.x)*(l1.start.y-l2.start.y) - (l1.end.y-l1.start.y)*(l1.start.x-l2.start.x)) / ((l2.end.y-l2.start.y)*(l1.end.x-l1.start.x) - (l2.end.x-l2.start.x)*(l1.end.y-l1.start.y));
|
||||||
|
|
||||||
|
if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) {
|
||||||
|
float intersectionX = l1.start.x + (uA * (l1.end.x-l1.start.x));
|
||||||
|
float intersectionY = l1.start.y + (uA * (l1.end.y-l1.start.y));
|
||||||
|
return {{intersectionX,intersectionY}};
|
||||||
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2289
Crawler/pge.data
2289
Crawler/pge.data
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
BIN
Crawler/pge.wasm
BIN
Crawler/pge.wasm
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user