Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define OLC_PGE_APPLICATION
- #include "Map.h"
- struct Node
- {
- bool Visited = false;
- bool bObstacle = false;
- int x;
- int y;
- float GlobalGoal;
- float LocalGoal;
- std::vector<Node*> Neighbours;
- Node* parent;
- };
- struct Adventurers
- {
- enum Gender
- {
- Male,
- Female
- };
- float px = 40;
- float py = 40;
- std::string name;
- int Gender = Male;
- int Level = 1;
- int Health = 0;
- int Strength = 1;
- int Endurance = 1;
- int Dexterity = 1;
- int Agility = 1;
- int Exhaustion = 0;
- };
- class Engine : public olc::PixelGameEngine
- {
- public:
- Engine()
- {
- sAppName = "MLaD";
- }
- Map *m_CurrentMap = nullptr;
- olc::Sprite* adhead = nullptr;
- std::string tempName;
- std::vector<Adventurers> advent;
- float Tick = 0;
- float TickTime = 20.f;
- int Day = 1;
- int Hour = 7;
- void DrawTileMap(Map* m_CurrentMap, std::vector<Tile> tiles)
- {
- for (size_t i = 0; i < tiles.size(); i++)
- {
- DrawPartialSprite(tiles[i].x, tiles[i].y, m_CurrentMap->mapsprite, tiles[i].sx * m_CurrentMap->TileWidth, tiles[i].sy * m_CurrentMap->TileHeight, m_CurrentMap->TileWidth, m_CurrentMap->TileHeight);
- }
- }
- void PopulateNext(std::vector<std::vector<float>>& Next)
- {
- for (int x = 0; x < m_CurrentMap->mWidth; x++)
- {
- for (int y = 0; y < m_CurrentMap->mHeight; y++)
- {
- if (m_CurrentMap->tiles[y * m_CurrentMap->mWidth + x].y > 0)
- {
- Next[y * m_CurrentMap->mWidth + x][(y - 1) * m_CurrentMap->mWidth + x] = (y - 1) * m_CurrentMap->mWidth + x;
- }
- if (m_CurrentMap->tiles[y * m_CurrentMap->mWidth + x].y < m_CurrentMap->mHeight - 1)
- {
- Next[y * m_CurrentMap->mWidth + x][(y + 1) * m_CurrentMap->mWidth + x] = (y + 1) * m_CurrentMap->mWidth + x;
- }
- if (m_CurrentMap->tiles[y * m_CurrentMap->mWidth + x].x > 0)
- {
- Next[y * m_CurrentMap->mWidth + x][y * m_CurrentMap->mWidth + (x - 1)] = y * m_CurrentMap->mWidth + (x - 1);
- }
- if (m_CurrentMap->tiles[y * m_CurrentMap->mWidth + x].x < m_CurrentMap->mWidth - 1)
- {
- Next[y * m_CurrentMap->mWidth + x][y * m_CurrentMap->mWidth + (x + 1)] = y * m_CurrentMap->mWidth + (x + 1);
- }
- }
- }
- }
- void PopulateDist(std::vector<std::vector<float>>& Dist)
- {
- for (int x = 0; x < m_CurrentMap->mWidth; x++)
- {
- for (int y = 0; y < m_CurrentMap->mHeight; y++)
- {
- if (m_CurrentMap->tiles[y * m_CurrentMap->mWidth + x].y > 0)
- {
- Dist[y * m_CurrentMap->mWidth + x][(y - 1) * m_CurrentMap->mWidth + x] = 1;
- }
- if (m_CurrentMap->tiles[y * m_CurrentMap->mWidth + x].y < m_CurrentMap->mHeight - 1)
- {
- Dist[y * m_CurrentMap->mWidth + x][(y + 1) * m_CurrentMap->mWidth + x] = 1;
- }
- if (m_CurrentMap->tiles[y * m_CurrentMap->mWidth + x].x > 0)
- {
- Dist[y * m_CurrentMap->mWidth + x][y * m_CurrentMap->mWidth + (x - 1)] = 1;
- }
- if (m_CurrentMap->tiles[y * m_CurrentMap->mWidth + x].x < m_CurrentMap->mWidth - 1)
- {
- Dist[y * m_CurrentMap->mWidth + x][y * m_CurrentMap->mWidth + (x + 1)] = 1;
- }
- }
- }
- }
- void FWAlg(std::vector<std::vector<float>>& Next, std::vector<std::vector<float>>& Dist)
- {
- for (size_t k = 0; k < m_CurrentMap->tiles.size(); k++)
- {
- for (size_t i = 0; i < Dist.size(); i++)
- {
- for (size_t j = 0; j < Next.size(); j++)
- {
- if (Dist[i][j] > Dist[i][k] + Dist[k][j])
- {
- Dist[i][j] = Dist[i][k] + Dist[k][j];
- Next[i][j] = Next[i][k];
- }
- }
- }
- }
- }
- /*void Collision()
- {
- for (int i = 0; i < m_CurrentMap->mWidth; i++)
- {
- for (int j = 0; j < m_CurrentMap->mHeight; j++)
- {
- if ()
- }
- }
- }*/
- void EndofDay(int& Day, int& Hour)
- {
- Day++;
- Hour = 7;
- }
- void GameTime(float& Tick, float fElapsedTime, float TickTime, int& Hour)
- {
- Tick += fElapsedTime;
- if (Tick >= TickTime)
- {
- Hour++;
- if (Hour == 19)
- {
- EndofDay(Day, Hour);
- }
- Tick = 0;
- }
- }
- void DisplayTime(int Day, int Hour)
- {
- DrawString(50, ScreenHeight() - 80, "Day : " + std::to_string(Day), olc::GREEN, 2U);
- DrawString(50, ScreenHeight() - 40, "Time : " + std::to_string(Hour) + ":00", olc::GREEN, 2U);
- }
- void DisplayNumAdvent(std::vector<Adventurers> advent)
- {
- DrawString(ScreenWidth() - 280, ScreenHeight() - 680, "Adventurers : " + std::to_string(advent.size()), olc::GREEN, 2U);
- }
- std::string RandNameMale()
- {
- tempName = std::vector<std::string>{"Tom", "Dick", "Harry", "Jeff", "David", "Sebastien", "Murdoc", "Judd", "Phil", "Mike"}[rand()% 10];
- return tempName;
- }
- std::string RandNameFemale()
- {
- tempName = std::vector<std::string>{"Maureen", "Delilah", "Florence", "Isabelle", "Tamatha", "Susan", "Geraldine", "Rose", "Christine", "Holly"}[rand()% 10];
- return tempName;
- }
- void addAdventurer(std::vector<Adventurers>& advent, std::string& tempName, Map* m_CurrentMap)
- {
- if (advent.size() < 20)
- {
- Adventurers ad;
- int GenderDec;
- GenderDec = rand() % 10;
- if (GenderDec < 5)
- {
- ad.Gender = ad.Male;
- ad.name = RandNameMale();
- }
- else if (GenderDec > 5)
- {
- ad.Gender = ad.Female;
- ad.name = RandNameFemale();
- }
- ad.px = rand() % m_CurrentMap->mWidth * m_CurrentMap->TileWidth;
- ad.py = rand() % m_CurrentMap->mHeight * m_CurrentMap->TileHeight;
- ad.Health = rand() % 50 + 15;
- ad.Strength = rand() % 10;
- ad.Endurance = rand() % 10;
- ad.Dexterity = rand() % 10;
- ad.Endurance = rand() % 10;
- ad.Exhaustion = 0;
- advent.emplace_back(ad);
- }
- else
- {
- return;
- }
- }
- void MoveAdventurer(std::vector<Adventurers> advent, std::vector<std::vector<float>> Next)
- {
- if (advent.size() > 0)
- {
- int destination = m_CurrentMap->GetIndex(m_CurrentMap->mWidth / 2, m_CurrentMap->mHeight / 2);
- Next[m_CurrentMap->GetIndex(advent[0].px, advent[0].py)][destination];
- }
- }
- /*void testcharvect(std::vector<Adventurers> advent)
- {
- for (int i = 0; i < advent.size(); i++)
- {
- std::cout << "Name : " << advent[i].name << " " << "Health : " << advent[i].Health << std::endl;
- if (advent[i].Gender == 0)
- {
- std::cout << "Gender : " << " Male " << std::endl;
- }
- else if (advent[i].Gender == 1)
- {
- std::cout << "Gender : " << " Female " << std::endl;
- }
- }
- }*/
- void Input(std::vector<Adventurers>& advent)
- {
- if (GetKey(olc::SPACE).bPressed)
- {
- addAdventurer(advent, tempName, m_CurrentMap);
- }
- /*else if ()
- {
- }
- /*else if (GetKey(olc::).bPressed)
- {
- }
- else if (GetKey(olc::).bPressed)
- {
- }
- else if (GetKey(olc::).bPressed)
- {
- }*/
- }
- void DrawHead(olc::Sprite& adhead, std::vector<Adventurers> advent)
- {
- for (size_t i = 0; i < advent.size(); i++)
- {
- DrawPartialSprite(advent[i].px, advent[i].py, &adhead, 0, 0, 32, 30, 1U);
- }
- }
- bool OnUserCreate()
- {
- srand(time(NULL));
- adhead = new olc::Sprite("AdventurerHead.png");
- m_CurrentMap = new mMap1();
- m_CurrentMap->AddTiles(m_CurrentMap->tiles, m_CurrentMap);
- /*PopulateDist(Dist);
- PopulateNext(Next);*/
- return true;
- }
- bool OnUserUpdate(float fElapsedTime)
- {
- Clear(olc::Pixel(154, 43, 7));
- DrawTileMap(m_CurrentMap, m_CurrentMap->tiles);
- GameTime(Tick, fElapsedTime, TickTime, Hour);
- Input(advent);
- SetPixelMode(olc::Pixel::ALPHA);
- DrawHead(*adhead, advent);
- MoveAdventurer(advent, Next);
- SetPixelMode(olc::Pixel::NORMAL);
- DisplayTime(Day, Hour);
- DisplayNumAdvent(advent);
- return true;
- }
- };
- int main()
- {
- const int width = 1200;
- const int height = 750;
- Engine engine;
- engine.Construct(width, height, 1, 1, false);
- engine.Start();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement