diff --git a/rollinghitpoints.cpp b/rollinghitpoints.cpp new file mode 100644 index 0000000..3c64a15 --- /dev/null +++ b/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_maptilesets; + std::unordered_mapimages; + 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;y0){ + for(int y=0;y(&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::vectorpoints; + std::vectoruvs; + std::vectorcols; + 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){ + 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; +}