Add 'rollinghitpoints.cpp'

main
sigonasr2 9 months ago
parent 4c0c6ddaf0
commit 5618096d66
  1. 202
      rollinghitpoints.cpp

@ -0,0 +1,202 @@
#include "TSXParser.h"
#include "olcPGEX_TransformedView.h"
#include "olcUTIL_Camera2D.h"
#include "olcPGEX_QuickGUI.h"
using namespace olc;
using namespace olc::utils;
const std::string TILESET_DIR="./Tiles/";
class TiledCollisionEditor : public olc::PixelGameEngine
{
std::unordered_map<std::string,Tileset>tilesets;
std::unordered_map<std::string,Renderable>images;
std::string activeTileset;
Quadrilateral*editingQuad=nullptr;
Quadrilateral originalQuad;
std::string selectedObj="";
int editingPoint=4; //Which point we are editing (0-3.)
TransformedView view;
public:
TiledCollisionEditor()
{
sAppName = "TiledCollisionEditor";
}
Renderable rollingCounter;
public:
bool OnUserCreate() override
{
SetFontSprite("font3.png");
std::string tilesetFilename=TILESET_DIR+"Basic Tileset.tsx";
Tileset&tileset=tilesets[tilesetFilename]=TSXParser{tilesetFilename}.GetData();
rollingCounter.Load("rollingcounter.png",nullptr,false,false);
Renderable&tilesetImg=images[tilesetFilename];
tilesetImg.Load(TILESET_DIR+tileset.filename);
if(tilesets.size()==1)activeTileset=tilesetFilename;
return true;
}
float hundredsDigit=0.f;
float tensDigit=0.f;
float onesDigit=0.f;
float currentHealth=0;
float targetHealth=60;
bool OnUserUpdate(float fElapsedTime) override
{
Clear(VERY_DARK_BLUE);
/*view.HandlePanAndZoom();
const Tileset&tileset=tilesets[activeTileset];
view.DrawDecal({0,0},images[activeTileset].Decal());
for(int y=0;y<tileset.tilecount/tileset.columns;y++){
for(int x=0;x<tileset.columns;x++){
view.DrawRectDecal(vf2d{float(x),float(y)}*tileset.tilewidth,vf2d{float(tileset.tilewidth),float(tileset.tileheight)},GREY);
}
}
if(editingQuad==nullptr){
std::string selectedObj="";
}
for(auto&[objName,obj]:tileset.objects){
view.DrawLineDecal(obj.bounds.pos,obj.bounds.pos+vf2d{0.f,float(obj.bounds.size.y)},YELLOW);
view.DrawLineDecal(obj.bounds.pos,obj.bounds.pos+vf2d{float(obj.bounds.size.x),0.f},YELLOW);
view.DrawLineDecal(obj.bounds.pos+obj.bounds.size,obj.bounds.pos+obj.bounds.size+vf2d{0.f,-float(obj.bounds.size.y)},YELLOW);
view.DrawLineDecal(obj.bounds.pos+obj.bounds.size,obj.bounds.pos+obj.bounds.size+vf2d{-float(obj.bounds.size.x),0.f},YELLOW);
vi2d nameTextSize=GetTextSizeProp(objName)*0.25f;
view.GradientFillRectDecal(obj.bounds.pos,nameTextSize+vf2d{2,2},RED,{255,0,0,64},{255,0,0,64},RED);
view.DrawStringPropDecal(obj.bounds.pos+vf2d{1.25f,1.25f},objName,BLACK,vf2d{0.25f,0.25f});
view.DrawStringPropDecal(obj.bounds.pos+vf2d{1,1},objName,WHITE,vf2d{0.25f,0.25f});
if(geom2d::contains(obj.bounds,view.ScreenToWorld(GetMousePos()))){
selectedObj=objName;
}
}
if(selectedObj.length()>0){
for(int y=0;y<tileset.tilecount/tileset.columns;y++){
for(int x=0;x<tileset.columns;x++){
if(!geom2d::contains(tileset.objects.at(selectedObj).bounds,vf2d{float(x*tileset.tilewidth)+tileset.tilewidth/2,float(y*tileset.tileheight)+tileset.tileheight/2})){
view.FillRectDecal(vf2d{float(x),float(y)}*tileset.tilewidth,vf2d{float(tileset.tilewidth),float(tileset.tileheight)},{0,0,0,128});
}
}
}
const TilesetObject&obj=tileset.objects.at(selectedObj);
const bool EditingQuad=editingPoint<4&&editingQuad!=nullptr;
if(EditingQuad){
(*editingQuad)[editingPoint]=view.ScreenToWorld(GetMousePos());
}
if(GetMouse(Mouse::LEFT).bPressed){
if(EditingQuad){
(*editingQuad)[editingPoint]=view.ScreenToWorld(GetMousePos());
editingPoint++;
}else{
if(obj.collisionTiles.size()==0){
Quadrilateral newQuad;
newQuad.fill(obj.bounds.middle());
tilesets[activeTileset].objects[selectedObj].collisionTiles.push_back(newQuad);
}
editingPoint=0;
editingQuad=const_cast<Quadrilateral*>(&obj.collisionTiles.back());
originalQuad=*editingQuad;
}
}
if(GetMouse(Mouse::RIGHT).bPressed||GetKey(ESCAPE).bPressed){
if(EditingQuad){
editingPoint=4;
*editingQuad=originalQuad;
editingQuad=nullptr;
}
}
for(const Quadrilateral&quad:obj.collisionTiles){
std::vector<vf2d>points;
std::vector<vf2d>uvs;
std::vector<Pixel>cols;
points.assign(quad.begin(),quad.end());
uvs.assign(4,{0.f,0.f});
cols.assign(4,{255,40,40,128});
view.DrawPolygonDecal(nullptr,points,uvs,cols);
}
}*/
FillRectDecal({64,64},{96,96});
FillRectDecal({96,72+8},{9,15},GREY);
FillRectDecal({96+9,72+8},{9,15},GREY);
FillRectDecal({96+18,72+8},{9,15},GREY);
DrawRectDecal({96,72+8},{9,15},BLACK);
DrawRectDecal({96+9,72+8},{9,15},BLACK);
DrawRectDecal({96+18,72+8},{9,15},BLACK);
int displayedHundredsDigit=hundredsDigit;
int displayedTensDigit=tensDigit;
int displayedOnesDigit=onesDigit;
int displayedNumber=hundredsDigit*100+displayedTensDigit*10+displayedOnesDigit;
if(displayedNumber<targetHealth){
currentHealth=std::min(targetHealth,currentHealth+fElapsedTime*10.f);
if(currentHealth>=targetHealth){
onesDigit=int(targetHealth)%10;
tensDigit=int(targetHealth/10)%10;
hundredsDigit=int(targetHealth/100);
}
onesDigit+=fElapsedTime*10.f;
if(onesDigit>9.f){
tensDigit+=fElapsedTime*10.f;
}
if(tensDigit>9.f){
hundredsDigit+=fElapsedTime*10.f;
}
if(onesDigit>10.f){
onesDigit=fmod(onesDigit,10.f);
}
if(tensDigit>10.f){
tensDigit=fmod(tensDigit,10.f);
}
if(hundredsDigit>10.f){
hundredsDigit=fmod(hundredsDigit,10.f);
}
}
DrawPartialDecal(vf2d{96,72+8}+vf2d{1,1},{7,13},rollingCounter.Decal(),{0,hundredsDigit*13},{7,13});
DrawPartialDecal(vf2d{96+9,72+8}+vf2d{1,1},{7,13},rollingCounter.Decal(),{0,tensDigit*13},{7,13});
DrawPartialDecal(vf2d{96+18,72+8}+vf2d{1,1},{7,13},rollingCounter.Decal(),{0,onesDigit*13},{7,13});
/* //Font test.
DrawStringDecal({0,0},"the quick brown fox jumps over the lazy dog 1234567890 !@#$%^&*()-=_+[]{}\\;':\",./<>?~`",WHITE,{1.5f,1.5f});
DrawStringDecal({0,18},"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 1234567890 !@#$%^&*()-=_+[]{}\\;':\",./<>?~`",WHITE,{1.5f,1.5f});
DrawStringPropDecal({0,36},"the quick brown fox jumps over the lazy dog 1234567890 !@#$%^&*()-=_+[]{}\\;':\",./<>?~`",WHITE,{1.5f,1.5f});
DrawStringPropDecal({0,54},"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 1234567890 !@#$%^&*()-=_+[]{}\\;':\",./<>?~`",WHITE,{1.5f,1.5f});
*/
return true;
}
};
int main()
{
TiledCollisionEditor demo;
if (demo.Construct(640, 180, 4, 4))
demo.Start();
return 0;
}
Loading…
Cancel
Save