The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'! https://forums.lestoria.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdventuresInLestoria/Adventures in Lestoria/AdventuresInLestoria.h

228 lines
8.6 KiB

#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions or derivations of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice. This list of conditions and the following disclaimer must be
reproduced in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2023 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#pragma once
#include "olcPixelGameEngine.h"
#include "Animation.h"
#include "olcUTIL_Animate2D.h"
#include "Monster.h"
#include "olcPGEX_TransformedView.h"
#include "Player.h"
#include "olcUTIL_Camera2D.h"
#include "Bullet.h"
#include "Effect.h"
#include "Map.h"
#include "TMXParser.h"
#include "olcUTIL_DataFile.h"
#include "Key.h"
#include "GameState.h"
#ifndef __EMSCRIPTEN__
#include "discord.h"
#endif
#include "Audio.h"
class AiL : public olc::PixelGameEngine
{
friend class GameState;
friend class State_GameRun;
friend class SaveFile;
friend class sig::Animation;
friend class Audio;
std::unique_ptr<Player>player;
public:
Pathfinding pathfinder;
static InputGroup KEY_CONFIRM;
static InputGroup KEY_ATTACK;
static InputGroup KEY_LEFT;
static InputGroup KEY_RIGHT;
static InputGroup KEY_UP;
static InputGroup KEY_DOWN;
static InputGroup KEY_MENU;
static float SIZE_CHANGE_SPEED;
double levelTime;
Camera2D camera;
std::map<MapName,Map>MAP_DATA;
private:
std::vector<std::unique_ptr<Effect>>foregroundEffects,backgroundEffects,foregroundEffectsToBeInserted,backgroundEffectsToBeInserted;
std::vector<TileRenderData*>tilePreparationList,tileForegroundList;
std::vector<int>dropsBeforeLower,dropsAfterLower,dropsBeforeUpper,dropsAfterUpper;
std::vector<ZoneData>endZones,upperEndZones;
std::vector<vf2d>circleCooldownPoints;
std::vector<vf2d>squareCircleCooldownPoints;
std::map<std::string,TilesetData>MAP_TILESETS;
vf2d worldShake={};
float worldShakeTime=0;
float lastWorldShakeAdjust=0;
vf2d worldShakeVel={};
const float WORLD_SHAKE_ADJUST_MAX_TIME=0.4f;
MapName currentLevel=MapName::CAMPAIGN_1_1;
std::vector<TileGroup>foregroundTileGroups;
std::vector<TileGroup>upperForegroundTileGroups;
int bridgeLayerIndex=-1;
float bridgeFadeFactor=0.f;
void InitializeClasses();
int DEBUG_PATHFINDING=0;
std::vector<Monster*>monstersBeforeLower,monstersAfterLower,monstersBeforeUpper,monstersAfterUpper;
std::vector<Bullet*>bulletsLower,bulletsUpper;
std::vector<Effect*>backgroundEffectsLower,backgroundEffectsUpper,foregroundEffectsLower,foregroundEffectsUpper;
float reflectionUpdateTimer=0;
float reflectionStepTime=0;
std::set<vi2d>visibleTiles;
float bossDisplayTimer=0;
std::string bossName;
int totalDamageDealt=0;
float encounterDuration=0;
bool encounterStarted=false;
int totalBossEncounterMobs=0;
int chapter=1; //We start at chapter 1.
std::array<std::shared_ptr<Item>,3>loadout;
float fadeOutDuration=0;
States::State transitionState=States::State::GAME_RUN;
bool gameEnd=false;
std::vector<Monster>monstersToBeSpawned;
time_t gameStarted;
std::function<void(std::string_view)>responseCallback;
float fadeInDuration=0;
float fadeOutTotalTime=0;
bool disableFadeIn=false;
void ValidateGameStatus();
#ifndef __EMSCRIPTEN__
::discord::Result SetupDiscord();
#endif
Audio audioEngine;
public:
AiL();
bool OnUserCreate() override;
bool OnUserUpdate(float fElapsedTime) override;
bool OnUserDestroy() override;
public:
geom2d::rect<int>NO_COLLISION={};
TileTransformedView view;
void InitializeLevel(std::string mapFile,MapName map);
void LoadLevel(MapName map);
void HandleUserInput(float fElapsedTime);
void UpdateCamera(float fElapsedTime);
void UpdateEffects(float fElapsedTime);
void UpdateBullets(float fElapsedTime);
void RenderWorld(float fElapsedTime);
void RenderHud();
void RenderMenu();
void AddEffect(std::unique_ptr<Effect>foreground,std::unique_ptr<Effect>background);
//If back is true, places the effect in the background
void AddEffect(std::unique_ptr<Effect>foreground,bool back=false);
void HurtEnemies(vf2d pos,float radius,int damage,bool upperLevel,float z);
vf2d GetWorldMousePos();
bool LeftHeld();
bool RightHeld();
bool UpHeld();
bool DownHeld();
bool LeftReleased();
bool RightReleased();
bool UpReleased();
bool DownReleased();
Player*GetPlayer();
void SetupWorldShake(float duration);
//tileID is the tile number from the tilesets.
bool IsForegroundTile(TilesheetData sheet,int tileID);
//tileID is the tile number from the tilesets.
bool IsUpperForegroundTile(int tileID);
//tileID is the tile number from the tilesets.
TilesheetData GetTileSheet(MapName map,int tileID);
//Gets the rectangle of the tile collision at this tile. If upperLevel is set to true, the collision tile must be in a Bridge class layer for the tile to hit. Also, zones containing LowerBridgeCollision will apply when upperLevel is set to false.
geom2d::rect<int>GetTileCollision(MapName map,vf2d pos,bool upperLevel=false);
//Checks if the point resides inside of a collision tile.
bool HasTileCollision(MapName map,vf2d pos,bool upperLevel=false);
const MapName&GetCurrentLevel()const;
bool IsBridgeLayer(LayerTag&layer);
std::map<std::string,std::vector<ZoneData>>&GetZoneData(MapName map);
void PopulateRenderLists();
void ChangePlayerClass(Class cl);
std::string GetString(std::string key);
datafilestringdata GetStringList(std::string key);
int GetInt(std::string key);
datafileintdata GetIntList(std::string key);
float GetFloat(std::string key);
datafilefloatdata GetFloatList(std::string key);
double GetDouble(std::string key);
datafiledoubledata GetDoubleList(std::string key);
static void OutputDebugInfo(const char*key,std::size_t len);
void InitializeLevels();
void RenderTile(vi2d pos,TilesheetData tileSheet,int tileSheetIndex,vi2d tileSheetPos);
void RenderTile(TileRenderData&tileSheet,Pixel col);
bool IsReflectiveTile(TilesheetData tileSheet,int tileID);
void SpawnMonster(vf2d pos,MonsterData&data,bool upperLevel=false,bool isBossSpawn=false); //Queues a monster for spawning on the next frame.
void DrawPie(vf2d center,float radius,float degreesCut,Pixel col);
void DrawSquarePie(vf2d center,float radius,float degreesCut,Pixel col);
void RenderCooldowns();
void InitializeDefaultKeybinds();
void SetBossNameDisplay(std::string name,float time=5);
bool InBossEncounter();
void StartBossEncounter();
void DisplayBossEncounterInfo();
void BossDamageDealt(int damage);
void ReduceBossEncounterMobCount();
void InitializeGraphics();
void RenderVersionInfo();
const Map&GetCurrentMap()const;
const MapTag&GetCurrentMapData()const;
const MapName&GetCurrentMapName()const;
int GetCurrentChapter();
void SetChapter(int chapter);
const std::weak_ptr<Item>GetLoadoutItem(int slot);
void SetLoadoutItem(int slot,std::string itemName);
//Returns true if the item can be used (we have >0 of it)
bool UseLoadoutItem(int slot);
//Blanks out this loadout item.
void ClearLoadoutItem(int slot);
void RenderFadeout();
bool GamePaused();
void EndGame();
void UpdateDiscordStatus(std::string levelName,std::string className);
void InitializePlayerLevelCap();
void ResetGame();
void OnRequestCompleted(const std::string_view receivedData)const override;
void DisableFadeIn(const bool disable);
struct TileGroupData{
vi2d tilePos;
int layer;
bool operator<(const TileGroupData&rhs)const{
return layer<rhs.layer||(layer==rhs.layer&&tilePos<rhs.tilePos);
}
};
};