|
|
@ -40,8 +40,8 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
Manager gui; |
|
|
|
Manager gui; |
|
|
|
|
|
|
|
|
|
|
|
ImageCheckBox*createNewButton; |
|
|
|
ImageCheckBox*createNewButton=nullptr; |
|
|
|
ImageCheckBox*editButton; |
|
|
|
ImageCheckBox*editButton=nullptr; |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
bool OnUserCreate() override |
|
|
|
bool OnUserCreate() override |
|
|
@ -73,13 +73,6 @@ public: |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float hundredsDigit=0.f; |
|
|
|
|
|
|
|
float tensDigit=0.f; |
|
|
|
|
|
|
|
float onesDigit=0.f; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float currentHealth=0; |
|
|
|
|
|
|
|
float targetHealth=60; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Update(){ |
|
|
|
void Update(){ |
|
|
|
const Tileset&tileset=tilesets[activeTileset]; |
|
|
|
const Tileset&tileset=tilesets[activeTileset]; |
|
|
|
|
|
|
|
|
|
|
@ -145,7 +138,7 @@ public: |
|
|
|
geom2d::triangle<float>{quad[0],quad[2],quad[3]}, |
|
|
|
geom2d::triangle<float>{quad[0],quad[2],quad[3]}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
for(geom2d::triangle<float>&tri:collisionTris){ |
|
|
|
for(geom2d::triangle<float>&tri:collisionTris){ |
|
|
|
if(geom2d::contains(tri,view.ScreenToWorld(GetMousePos()))){ |
|
|
|
if(geom2d::overlaps(tri,geom2d::circle<float>(view.ScreenToWorld(GetMousePos()),3.f))){ |
|
|
|
dragTranslate=true; |
|
|
|
dragTranslate=true; |
|
|
|
editingQuad=const_cast<Quadrilateral*>(&quad); |
|
|
|
editingQuad=const_cast<Quadrilateral*>(&quad); |
|
|
|
upperLeftDragOffset=GetSnapPoint()-quad[0]; |
|
|
|
upperLeftDragOffset=GetSnapPoint()-quad[0]; |
|
|
@ -188,7 +181,7 @@ public: |
|
|
|
geom2d::triangle<float>{quad[0],quad[2],quad[3]}, |
|
|
|
geom2d::triangle<float>{quad[0],quad[2],quad[3]}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
for(geom2d::triangle<float>&tri:collisionTris){ |
|
|
|
for(geom2d::triangle<float>&tri:collisionTris){ |
|
|
|
if(geom2d::contains(tri,view.ScreenToWorld(GetMousePos()))){ |
|
|
|
if(geom2d::overlaps(tri,geom2d::circle<float>(view.ScreenToWorld(GetMousePos()),3.f))){ |
|
|
|
//Delete this quad, the mouse is overlapping it!
|
|
|
|
//Delete this quad, the mouse is overlapping it!
|
|
|
|
quadsToBeRemoved.push_back(const_cast<Quadrilateral*>(&quad)); |
|
|
|
quadsToBeRemoved.push_back(const_cast<Quadrilateral*>(&quad)); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -215,25 +208,50 @@ public: |
|
|
|
editingPoint=4; |
|
|
|
editingPoint=4; |
|
|
|
} |
|
|
|
} |
|
|
|
dragTranslate=false; |
|
|
|
dragTranslate=false; |
|
|
|
|
|
|
|
editingQuad=nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NewObjectUpdate(){ |
|
|
|
void NewObjectUpdate(){ |
|
|
|
|
|
|
|
const Tileset&tileset=tilesets[activeTileset]; |
|
|
|
if(GetMouse(Mouse::LEFT).bPressed){ |
|
|
|
if(GetMouse(Mouse::LEFT).bPressed){ |
|
|
|
const Tileset&tileset=tilesets[activeTileset]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vf2d worldCoords=view.ScreenToWorld(GetMousePos()); |
|
|
|
vf2d worldCoords=view.ScreenToWorld(GetMousePos()); |
|
|
|
upperLeftObjTile=vf2d{round(worldCoords.x/tileset.tilewidth)*tileset.tilewidth,round(worldCoords.y/tileset.tileheight)*tileset.tileheight}; |
|
|
|
upperLeftObjTile=vi2d{int(round(worldCoords.x/tileset.tilewidth)*tileset.tilewidth),int(round(worldCoords.y/tileset.tileheight)*tileset.tileheight)}; |
|
|
|
dragNewObj=true; |
|
|
|
dragNewObj=true; |
|
|
|
} |
|
|
|
} |
|
|
|
if(GetMouse(Mouse::LEFT).bReleased){ |
|
|
|
if(GetMouse(Mouse::LEFT).bReleased){ |
|
|
|
dragNewObj=false; |
|
|
|
dragNewObj=false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vf2d worldCoords=view.ScreenToWorld(GetMousePos()); |
|
|
|
|
|
|
|
vi2d lowerRightObjTile=vi2d{int(round(worldCoords.x/tileset.tilewidth)*tileset.tilewidth),int(round(worldCoords.y/tileset.tileheight)*tileset.tileheight)}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
geom2d::rect<int>newObjRect{upperLeftObjTile,lowerRightObjTile-upperLeftObjTile}; |
|
|
|
|
|
|
|
|
|
|
|
const Tileset&tileset=tilesets[activeTileset]; |
|
|
|
const Tileset&tileset=tilesets[activeTileset]; |
|
|
|
//Check for intersection with other objects, if found then we deny creating this object this way.
|
|
|
|
//Check for intersection with other objects, if found then we deny creating this object this way.
|
|
|
|
|
|
|
|
bool intersectionFound=false; |
|
|
|
for(auto&[name,obj]:tileset.objects){ |
|
|
|
for(auto&[name,obj]:tileset.objects){ |
|
|
|
|
|
|
|
geom2d::rect<float>offsetBounds{obj.bounds.pos+vf2d{0.5f,0.5f},obj.bounds.size-vf2d{1.f,1.f}}; |
|
|
|
|
|
|
|
if(geom2d::overlaps(offsetBounds,newObjRect)){ |
|
|
|
|
|
|
|
intersectionFound=true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!intersectionFound){ |
|
|
|
|
|
|
|
std::string objName=std::format("Object{}",tilesets[activeTileset].objects.size()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TilesetObject&newObj=tilesets[activeTileset].objects[objName]; |
|
|
|
|
|
|
|
newObj.name=objName; |
|
|
|
|
|
|
|
for(int y=0;y<newObjRect.size.y;y++){ |
|
|
|
|
|
|
|
for(int x=0;x<newObjRect.size.x;x++){ |
|
|
|
|
|
|
|
int tileX=upperLeftObjTile.x/tileset.tilewidth+x; |
|
|
|
|
|
|
|
int tileY=upperLeftObjTile.y/tileset.tileheight+y; |
|
|
|
|
|
|
|
int tileID=tileY*tileset.columns+tileX; |
|
|
|
|
|
|
|
newObj.AddTile(tileset,tileID); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
|
|
|
} |
|
|
@ -261,7 +279,13 @@ public: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(editingQuad==nullptr){ |
|
|
|
if(editingQuad==nullptr){ |
|
|
|
std::string selectedObj=""; |
|
|
|
selectedObj=""; |
|
|
|
|
|
|
|
for(auto&[objName,obj]:tileset.objects){ |
|
|
|
|
|
|
|
if(geom2d::contains(obj.bounds,view.ScreenToWorld(GetMousePos()))){ |
|
|
|
|
|
|
|
selectedObj=objName; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(createNewButton->bPressed)editButton->bChecked=false; |
|
|
|
if(createNewButton->bPressed)editButton->bChecked=false; |
|
|
@ -291,7 +315,7 @@ public: |
|
|
|
geom2d::triangle<float>{quad[0],quad[2],quad[3]}, |
|
|
|
geom2d::triangle<float>{quad[0],quad[2],quad[3]}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
for(geom2d::triangle<float>&tri:collisionTris){ |
|
|
|
for(geom2d::triangle<float>&tri:collisionTris){ |
|
|
|
if(geom2d::contains(tri,view.ScreenToWorld(GetMousePos()))){ |
|
|
|
if(geom2d::overlaps(tri,geom2d::circle<float>(view.ScreenToWorld(GetMousePos()),3.f))){ |
|
|
|
highlightedQuad=const_cast<Quadrilateral*>(&quad); |
|
|
|
highlightedQuad=const_cast<Quadrilateral*>(&quad); |
|
|
|
goto renderQuads; |
|
|
|
goto renderQuads; |
|
|
|
} |
|
|
|
} |
|
|
@ -308,17 +332,36 @@ public: |
|
|
|
view.DrawPolygonDecal(nullptr,points,uvs,cols); |
|
|
|
view.DrawPolygonDecal(nullptr,points,uvs,cols); |
|
|
|
|
|
|
|
|
|
|
|
for(bool highlighted=false;const vf2d&point:quad){ |
|
|
|
for(bool highlighted=false;const vf2d&point:quad){ |
|
|
|
if(geom2d::line<float>(point,view.ScreenToWorld(GetMousePos())).length()<4&&!highlighted){ |
|
|
|
if(highlightedQuad==&quad){ |
|
|
|
view.DrawRotatedDecal(point,circle.Decal(),0.f,circle.Sprite()->Size()/2,{1.f,1.f},YELLOW); |
|
|
|
if(geom2d::line<float>(point,view.ScreenToWorld(GetMousePos())).length()<4&&!highlighted){ |
|
|
|
highlighted=true; |
|
|
|
view.DrawRotatedDecal(point,circle.Decal(),0.f,circle.Sprite()->Size()/2,{1.f,1.f},YELLOW); |
|
|
|
|
|
|
|
highlighted=true; |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
view.DrawRotatedDecal(point,circle.Decal(),0.f,circle.Sprite()->Size()/2,{1.f,1.f},RED); |
|
|
|
|
|
|
|
} |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
view.DrawRotatedDecal(point,circle.Decal(),0.f,circle.Sprite()->Size()/2,{1.f,1.f},RED); |
|
|
|
view.DrawRotatedDecal(point,circle.Decal(),0.f,circle.Sprite()->Size()/2,{0.25f,0.25f},DARK_GREY); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}else |
|
|
|
}else |
|
|
|
if(dragNewObj){ |
|
|
|
if(dragNewObj){ |
|
|
|
|
|
|
|
vf2d worldCoords=view.ScreenToWorld(GetMousePos()); |
|
|
|
|
|
|
|
vi2d lowerRightObjTile=vi2d{int(round(worldCoords.x/tileset.tilewidth)*tileset.tilewidth),int(round(worldCoords.y/tileset.tileheight)*tileset.tileheight)}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pixel overlayCol={0,0,255,160}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
geom2d::rect<int>newObjRect{upperLeftObjTile,lowerRightObjTile-upperLeftObjTile}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(auto&[name,obj]:tileset.objects){ |
|
|
|
|
|
|
|
geom2d::rect<float>offsetBounds{obj.bounds.pos+vf2d{0.5f,0.5f},obj.bounds.size-vf2d{1.f,1.f}}; |
|
|
|
|
|
|
|
if(geom2d::overlaps(offsetBounds,newObjRect)){ |
|
|
|
|
|
|
|
overlayCol={255,0,0,160}; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
view.FillRectDecal(upperLeftObjTile,lowerRightObjTile-upperLeftObjTile,overlayCol); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(auto&[objName,obj]:tileset.objects){ |
|
|
|
for(auto&[objName,obj]:tileset.objects){ |
|
|
|