From 1bf30f439248d0eb02e3bb6407ada1b44b6a3f54 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 13 Nov 2023 21:26:34 -0600 Subject: [PATCH] Added ability to select a loadout item from the inventory menu screen. --- Crawler/Arrow.cpp | 2 +- Crawler/Attributable.h | 2 +- Crawler/CharacterAbilityPreviewComponent.h | 2 +- Crawler/ChargedArrow.cpp | 2 +- Crawler/Crawler.cpp | 2 +- Crawler/Crawler.vcxproj | 6 +- Crawler/Crawler.vcxproj.filters | 36 +++-- Crawler/EnergyBolt.cpp | 2 +- Crawler/FireBolt.cpp | 2 +- Crawler/InventoryScrollableWindowComponent.h | 17 ++- Crawler/InventoryWindow.cpp | 2 + Crawler/Item.h | 2 +- Crawler/LightningBolt.cpp | 2 +- Crawler/LightningBoltEmitter.cpp | 2 +- Crawler/Menu.h | 2 +- Crawler/MenuItemButton.h | 20 ++- Crawler/MenuLabel.h | 2 +- Crawler/Meteor.cpp | 2 +- Crawler/Monster.cpp | 2 +- Crawler/MonsterAttribute.h | 2 + Crawler/Player.cpp | 8 +- Crawler/Player.h | 3 + Crawler/PulsatingFire.cpp | 2 +- Crawler/Ranger.cpp | 2 +- Crawler/SlimeKing.cpp | 2 +- Crawler/SpawnEncounterLabel.h | 2 +- Crawler/State_OverworldMap.cpp | 35 +---- Crawler/Turret.cpp | 2 +- Crawler/Version.h | 2 +- Crawler/Wizard.cpp | 2 +- Crawler/drawutil.cpp | 137 +++++++++++++++++++ Crawler/drawutil.h | 11 ++ Crawler/{utils.cpp => util.cpp} | 2 +- Crawler/{utils.h => util.h} | 0 34 files changed, 245 insertions(+), 76 deletions(-) create mode 100644 Crawler/drawutil.cpp create mode 100644 Crawler/drawutil.h rename Crawler/{utils.cpp => util.cpp} (98%) rename Crawler/{utils.h => util.h} (100%) diff --git a/Crawler/Arrow.cpp b/Crawler/Arrow.cpp index 455b3862..d2291035 100644 --- a/Crawler/Arrow.cpp +++ b/Crawler/Arrow.cpp @@ -2,7 +2,7 @@ #include "Effect.h" #include "Crawler.h" #include "DEFINES.h" -#include "utils.h" +#include "util.h" #include "olcUTIL_Geometry2D.h" INCLUDE_game diff --git a/Crawler/Attributable.h b/Crawler/Attributable.h index 7f2b344b..62e0618f 100644 --- a/Crawler/Attributable.h +++ b/Crawler/Attributable.h @@ -5,7 +5,7 @@ #include class IAttributable{ -protected: +public: inline virtual ~IAttributable(){}; std::map>attributes; inline float&GetFloat(Attribute a){ diff --git a/Crawler/CharacterAbilityPreviewComponent.h b/Crawler/CharacterAbilityPreviewComponent.h index dcc5bf64..eaf5077d 100644 --- a/Crawler/CharacterAbilityPreviewComponent.h +++ b/Crawler/CharacterAbilityPreviewComponent.h @@ -2,7 +2,7 @@ #include "MenuLabel.h" #include "DEFINES.h" #include "Crawler.h" -#include "utils.h" +#include "util.h" #include "Ability.h" INCLUDE_game diff --git a/Crawler/ChargedArrow.cpp b/Crawler/ChargedArrow.cpp index dcc31f7e..be19c252 100644 --- a/Crawler/ChargedArrow.cpp +++ b/Crawler/ChargedArrow.cpp @@ -2,7 +2,7 @@ #include "Effect.h" #include "Crawler.h" #include "DEFINES.h" -#include "utils.h" +#include "util.h" #include "olcUTIL_Geometry2D.h" INCLUDE_game diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index f23e5b9b..01716e5c 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -10,7 +10,7 @@ #include "TSXParser.h" #include "Map.h" #include "DEFINES.h" -#include "utils.h" +#include "util.h" #include #include #include "Emitter.h" diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index aec67cdc..120c1319 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -273,6 +273,7 @@ + @@ -314,7 +315,7 @@ - + @@ -328,6 +329,7 @@ + @@ -368,7 +370,7 @@ - + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index bde5929c..8c94437a 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -61,6 +61,12 @@ {948a122a-3110-45f6-82d5-9b6bc499e3d2} + + {2c68f315-9f2b-46c7-abca-cc97b5e0e515} + + + {7d5c4dfd-a5a1-4a3d-8231-ace70551db5a} + @@ -135,9 +141,6 @@ Header Files - - Header Files - Header Files @@ -171,9 +174,6 @@ Header Files\Interface - - Source Files - Header Files\Game States @@ -228,15 +228,24 @@ Header Files - - Header Files - Header Files Header Files\Interface + + Header Files\Utils + + + Header Files\Utils + + + Header Files + + + Header Files + @@ -278,9 +287,6 @@ Source Files\Bullet Types - - Source Files - Source Files @@ -398,6 +404,12 @@ Source Files + + Source Files\Utils + + + Source Files\Utils + diff --git a/Crawler/EnergyBolt.cpp b/Crawler/EnergyBolt.cpp index baf1774f..e710a5a2 100644 --- a/Crawler/EnergyBolt.cpp +++ b/Crawler/EnergyBolt.cpp @@ -2,7 +2,7 @@ #include "Effect.h" #include "Crawler.h" #include "DEFINES.h" -#include "utils.h" +#include "util.h" INCLUDE_game diff --git a/Crawler/FireBolt.cpp b/Crawler/FireBolt.cpp index 5c4aca37..afb26d06 100644 --- a/Crawler/FireBolt.cpp +++ b/Crawler/FireBolt.cpp @@ -2,7 +2,7 @@ #include "Effect.h" #include "Crawler.h" #include "DEFINES.h" -#include "utils.h" +#include "util.h" INCLUDE_game INCLUDE_MONSTER_LIST diff --git a/Crawler/InventoryScrollableWindowComponent.h b/Crawler/InventoryScrollableWindowComponent.h index c15630bb..bd86a84e 100644 --- a/Crawler/InventoryScrollableWindowComponent.h +++ b/Crawler/InventoryScrollableWindowComponent.h @@ -69,9 +69,22 @@ protected: int buttonSize="ThemeGlobal.InventoryButtonSize"_I; int totalSpacing="ThemeGlobal.InventoryItemSpacing"_I+buttonSize; - MenuFunc useItemFunc=[](MenuFuncData data){ + MenuFunc useItemFunc=[&](MenuFuncData data){ MenuItemButton*button=(MenuItemButton*)data.component; - return !button->UseItem(); + if(!data.game->GetPlayer()->GetLoadoutItem(data.menu.I(A::LOADOUT_SLOT)).IsBlank()){ //This loadout slot seems to have an item in it already, so deselect that one first. + data.game->GetPlayer()->ClearLoadoutItem(data.menu.I(A::LOADOUT_SLOT)); + for(MenuComponent*component:components){ + if(component->GetName().starts_with("item")){ + MenuItemButton*button=(MenuItemButton*)component;//HACK ALERT! This is probably an item since we populated item lists using this name for the components. So we assume these are MenuItemButton classes. + if(button->selected==data.menu.I(A::LOADOUT_SLOT)){ + button->selected=-1; + } + } + } + } + button->selected=data.menu.I(A::LOADOUT_SLOT); + data.game->GetPlayer()->SetLoadoutItem(button->selected,button->GetItem().Name()); + return true; }; MenuItemButton*button=NEW MenuItemButton{parentMenu,{{float(totalSpacing*x),float(totalSpacing*y)},{float(buttonSize),float(buttonSize)}},Inventory::get("Consumables"),itemIndex,useItemFunc}; diff --git a/Crawler/InventoryWindow.cpp b/Crawler/InventoryWindow.cpp index 0782c359..de7197e3 100644 --- a/Crawler/InventoryWindow.cpp +++ b/Crawler/InventoryWindow.cpp @@ -21,6 +21,8 @@ void Menu::InitializeInventoryWindow(){ Menu*inventoryWindow=CreateMenu(INVENTORY,CENTERED,windowSize); + inventoryWindow->I(A::LOADOUT_SLOT)=0; + InventoryScrollableWindowComponent*inventory=NEW InventoryScrollableWindowComponent(INVENTORY,{{1,0},{windowSize.x,float(totalSpacing*3-itemSpacing)}}); inventoryWindow->AddComponent("inventory",inventory); Menu::AddInventoryListener(inventory,"Consumables"); diff --git a/Crawler/Item.h b/Crawler/Item.h index 625540dc..612f8981 100644 --- a/Crawler/Item.h +++ b/Crawler/Item.h @@ -17,7 +17,7 @@ typedef std::function ItemScript; class Item{ friend class Inventory; - friend class Palyer; + friend class Player; private: uint32_t amt; ItemInfo*it; diff --git a/Crawler/LightningBolt.cpp b/Crawler/LightningBolt.cpp index fbc4f4b1..0ef73341 100644 --- a/Crawler/LightningBolt.cpp +++ b/Crawler/LightningBolt.cpp @@ -3,7 +3,7 @@ #include "Crawler.h" #include "DEFINES.h" #include "Emitter.h" -#include "utils.h" +#include "util.h" INCLUDE_game INCLUDE_MONSTER_LIST diff --git a/Crawler/LightningBoltEmitter.cpp b/Crawler/LightningBoltEmitter.cpp index fd075b4e..6440e38d 100644 --- a/Crawler/LightningBoltEmitter.cpp +++ b/Crawler/LightningBoltEmitter.cpp @@ -1,6 +1,6 @@ #include "Emitter.h" #include "olcUTIL_Geometry2D.h" -#include "utils.h" +#include "util.h" #include "Crawler.h" #include "DEFINES.h" diff --git a/Crawler/Menu.h b/Crawler/Menu.h index 69aaaed5..1fa181c1 100644 --- a/Crawler/Menu.h +++ b/Crawler/Menu.h @@ -27,7 +27,7 @@ T*Component(MenuType menu,std::string componentName){ return (T*)Menu::menus[menu]->components[componentName]; } -class Menu:IAttributable{ +class Menu:public IAttributable{ friend class Crawler; friend class Player; friend class ItemInfo; diff --git a/Crawler/MenuItemButton.h b/Crawler/MenuItemButton.h index c9d2736a..cf0897c3 100644 --- a/Crawler/MenuItemButton.h +++ b/Crawler/MenuItemButton.h @@ -1,10 +1,13 @@ #pragma once +#include "Menu.h" +#include "MenuLabel.h" #include "MenuIconButton.h" #include "DEFINES.h" #include "Crawler.h" #include "Item.h" #include "safemap.h" #include "olcPGEX_Graphics2D.h" +#include "drawutil.h" INCLUDE_game INCLUDE_ITEM_DATA @@ -14,9 +17,10 @@ private: std::vector&invRef; int inventoryIndex=0; public: + int selected=-1; //0-2 representing which loadout slot this item consumes. -1 means not selected. inline MenuItemButton(MenuType parent,geom2d::rectrect,std::vector&invRef,int invIndex,MenuFunc onClick) :MenuIconButton(parent,rect,invRef.size()>invIndex?ITEM_DATA.at(invRef[invIndex]).Decal():nullptr,onClick),invRef(invRef),inventoryIndex(invIndex){ - draggable=true; + draggable=false; valid=invRef.size()>invIndex; } inline Item GetItem(){ @@ -39,9 +43,9 @@ protected: switch(parentMenu){ case INVENTORY:{ //There should be an itemName label to modify. - menu->components.at("itemName")->label=ITEM_DATA.at(invRef[inventoryIndex]).Name(); + Component(INVENTORY,"itemName")->label=ITEM_DATA.at(invRef[inventoryIndex]).Name(); //There should be an itemDescription label to modify. - menu->components.at("itemDescription")->label=ITEM_DATA.at(invRef[inventoryIndex]).Description(); + Component(INVENTORY,"itemDescription")->label=ITEM_DATA.at(invRef[inventoryIndex]).Description(); }break; } } @@ -51,15 +55,21 @@ protected: switch(parentMenu){ case INVENTORY:{ //There should be an itemName label to modify. - menu->components.at("itemName")->label=""; + Component(INVENTORY,"itemName")->label=""; //There should be an itemDescription label to modify. - menu->components.at("itemDescription")->label=""; + Component(INVENTORY,"itemDescription")->label=""; }break; } } } } } + virtual inline void Draw(Crawler*game,vf2d parentPos)override{ + MenuIconButton::Draw(game,parentPos); + if(selected!=-1){ + drawutil::DrawCrosshair(game,{parentPos+rect.pos,rect.size},0); + } + } virtual inline void DrawDecal(Crawler*game,vf2d parentPos,bool focused)override{ MenuIconButton::DrawDecal(game,parentPos,focused); if(valid){ diff --git a/Crawler/MenuLabel.h b/Crawler/MenuLabel.h index bb2cfd0c..77d2ba70 100644 --- a/Crawler/MenuLabel.h +++ b/Crawler/MenuLabel.h @@ -2,7 +2,7 @@ #include "MenuComponent.h" #include "DEFINES.h" #include "Crawler.h" -#include "utils.h" +#include "util.h" INCLUDE_game diff --git a/Crawler/Meteor.cpp b/Crawler/Meteor.cpp index 72df9eeb..02a4575f 100644 --- a/Crawler/Meteor.cpp +++ b/Crawler/Meteor.cpp @@ -1,7 +1,7 @@ #include "Effect.h" #include "DEFINES.h" #include "Crawler.h" -#include "utils.h" +#include "util.h" #include "safemap.h" INCLUDE_game diff --git a/Crawler/Monster.cpp b/Crawler/Monster.cpp index 30622e73..0510e99b 100644 --- a/Crawler/Monster.cpp +++ b/Crawler/Monster.cpp @@ -6,7 +6,7 @@ #include "DEFINES.h" #include "safemap.h" #include "MonsterStrategyHelpers.h" -#include "utils.h" +#include "util.h" #include "MonsterAttribute.h" INCLUDE_ANIMATION_DATA diff --git a/Crawler/MonsterAttribute.h b/Crawler/MonsterAttribute.h index ec89172f..8468fc46 100644 --- a/Crawler/MonsterAttribute.h +++ b/Crawler/MonsterAttribute.h @@ -30,4 +30,6 @@ enum class Attribute{ INDEXED_THEME, SCROLL_OFFSET, CLASS_SELECTION, //A class name that represents what the menu's class is. + LOADOUT_SLOT, //Which loadout slot we are selecting an item for. + ALLOW_DRAGGING, //Whether or not to allow inventory dragging. }; \ No newline at end of file diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 24a24e38..ebe40a15 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -6,7 +6,7 @@ #include "BulletTypes.h" #include "DEFINES.h" #include "safemap.h" -#include "utils.h" +#include "util.h" #include "Key.h" #include "Menu.h" #include "GameState.h" @@ -734,6 +734,7 @@ void Player::SetLoadoutItem(int slot,std::string itemName){ ERR("Trying to set item "+itemName+" in Loadout slot "+std::to_string(slot)+" when said item does not exist in our inventory!"); } } + void Player::UseLoadoutItem(int slot){ if(slot<0||slot>loadout.size()-1)ERR("Invalid inventory slot "+std::to_string(slot)+", please choose a slot in range (0-"+std::to_string(loadout.size()-1)+")."); if(GetLoadoutItem(slot).Amt()>0){ @@ -741,4 +742,9 @@ void Player::UseLoadoutItem(int slot){ GetLoadoutItem(slot).OnUseAction(); GetLoadoutItem(slot).amt--; } +} + +void Player::ClearLoadoutItem(int slot){ + if(slot<0||slot>loadout.size()-1)ERR("Invalid inventory slot "+std::to_string(slot)+", please choose a slot in range (0-"+std::to_string(loadout.size()-1)+")."); + loadout[slot]={}; } \ No newline at end of file diff --git a/Crawler/Player.h b/Crawler/Player.h index f9c07929..a58057fa 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -10,6 +10,7 @@ #include "config.h" #include "Key.h" #include "Class.h" +#include "Item.h" #undef GetClassName @@ -161,6 +162,8 @@ public: Item&GetLoadoutItem(int slot); void SetLoadoutItem(int slot,std::string itemName); void UseLoadoutItem(int slot); + //Blanks out this loadout item. + void ClearLoadoutItem(int slot); //Triggers when the player has moved. void Moved(); virtual ~Player()=default; diff --git a/Crawler/PulsatingFire.cpp b/Crawler/PulsatingFire.cpp index 5459c9be..8040b68b 100644 --- a/Crawler/PulsatingFire.cpp +++ b/Crawler/PulsatingFire.cpp @@ -1,7 +1,7 @@ #include "Effect.h" #include "DEFINES.h" #include "Crawler.h" -#include "utils.h" +#include "util.h" #include "safemap.h" INCLUDE_game diff --git a/Crawler/Ranger.cpp b/Crawler/Ranger.cpp index b61d7f0b..0f1acd36 100644 --- a/Crawler/Ranger.cpp +++ b/Crawler/Ranger.cpp @@ -5,7 +5,7 @@ #include "Effect.h" #include "Crawler.h" #include "BulletTypes.h" -#include "utils.h" +#include "util.h" #include "config.h" INCLUDE_MONSTER_LIST diff --git a/Crawler/SlimeKing.cpp b/Crawler/SlimeKing.cpp index 7aa38609..d7336b31 100644 --- a/Crawler/SlimeKing.cpp +++ b/Crawler/SlimeKing.cpp @@ -2,7 +2,7 @@ #include "MonsterStrategyHelpers.h" #include "DEFINES.h" #include "Crawler.h" -#include "utils.h" +#include "util.h" #include "safemap.h" #include "Effect.h" #include "FallingDebris.h" diff --git a/Crawler/SpawnEncounterLabel.h b/Crawler/SpawnEncounterLabel.h index f90b59c4..dac017c9 100644 --- a/Crawler/SpawnEncounterLabel.h +++ b/Crawler/SpawnEncounterLabel.h @@ -2,7 +2,7 @@ #include "MenuLabel.h" #include "DEFINES.h" #include "Crawler.h" -#include "utils.h" +#include "util.h" INCLUDE_game INCLUDE_MONSTER_DATA diff --git a/Crawler/State_OverworldMap.cpp b/Crawler/State_OverworldMap.cpp index 84dde5ed..4656e5cc 100644 --- a/Crawler/State_OverworldMap.cpp +++ b/Crawler/State_OverworldMap.cpp @@ -5,7 +5,8 @@ #include "Menu.h" #include "Unlock.h" #include "ConnectionPoint.h" -#include "utils.h" +#include "util.h" +#include "drawutil.h" #include "MenuLabel.h" #include "EncountersSpawnListScrollableWindowComponent.h" @@ -84,37 +85,7 @@ void State_OverworldMap::Draw(Crawler*game){ } for(ConnectionPoint&cp:connections){ if(Unlock::IsUnlocked(cp)&&geom2d::overlaps(game->GetWorldMousePos(),cp.rect)&&(&cp==currentConnectionPoint||cp.IsNeighbor(*currentConnectionPoint))){ - float borderThickness=4; - vf2d crosshairExtension={std::min(0.25f*cp.rect.size.x-borderThickness/2,12.f),std::min(0.25f*cp.rect.size.y-borderThickness/2,12.f)}; - vf2d pulsatingAmt=vf2d{1,1}*std::abs(std::sin(currentTime*3))*2; - //Lower-Left Corner - vf2d pos=cp.rect.pos+vf2d{0,cp.rect.size.y-borderThickness}+vf2d{-pulsatingAmt.x,pulsatingAmt.y}; - vf2d size={borderThickness+crosshairExtension.x,borderThickness}; - game->view.FillRectDecal(pos,size,RED); - pos=vf2d{pos.x,pos.y-crosshairExtension.y}; - size={borderThickness,crosshairExtension.y}; - game->view.FillRectDecal(pos,size,RED); - //Lower-Right Corner - pos=cp.rect.pos+vf2d{cp.rect.size.x-borderThickness-crosshairExtension.x,cp.rect.size.y-borderThickness}+vf2d{pulsatingAmt.x,pulsatingAmt.y}; - size={borderThickness+crosshairExtension.x,borderThickness}; - game->view.FillRectDecal(pos,size,RED); - pos=vf2d{pos.x+crosshairExtension.x,pos.y-crosshairExtension.y}; - size={borderThickness,crosshairExtension.y}; - game->view.FillRectDecal(pos,size,RED); - //Upper-Left Corner - pos=cp.rect.pos+vf2d{0,0}+vf2d{-pulsatingAmt.x,-pulsatingAmt.y}; - size={borderThickness+crosshairExtension.x,borderThickness}; - game->view.FillRectDecal(pos,size,RED); - pos=vf2d{pos.x,pos.y+borderThickness}; - size={borderThickness,crosshairExtension.y}; - game->view.FillRectDecal(pos,size,RED); - //Upper-Right Corner - pos=cp.rect.pos+vf2d{cp.rect.size.x-borderThickness-crosshairExtension.x,0}+vf2d{pulsatingAmt.x,-pulsatingAmt.y}; - size={borderThickness+crosshairExtension.x,borderThickness}; - game->view.FillRectDecal(pos,size,RED); - pos=vf2d{pos.x+crosshairExtension.x,pos.y+borderThickness}; - size={borderThickness,crosshairExtension.y}; - game->view.FillRectDecal(pos,size,RED); + drawutil::DrawCrosshairDecalTransformedView(game->view,cp.rect,currentTime); break; } } diff --git a/Crawler/Turret.cpp b/Crawler/Turret.cpp index e9a0930c..f6984987 100644 --- a/Crawler/Turret.cpp +++ b/Crawler/Turret.cpp @@ -2,7 +2,7 @@ #include "MonsterStrategyHelpers.h" #include "DEFINES.h" #include "Crawler.h" -#include "utils.h" +#include "util.h" #include "MonsterAttribute.h" typedef Attribute A; diff --git a/Crawler/Version.h b/Crawler/Version.h index ded51223..a643d2ff 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 2794 +#define VERSION_BUILD 2812 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/Wizard.cpp b/Crawler/Wizard.cpp index 7c1ca1c6..7a0d944c 100644 --- a/Crawler/Wizard.cpp +++ b/Crawler/Wizard.cpp @@ -6,7 +6,7 @@ #include "Crawler.h" #include "BulletTypes.h" #include "config.h" -#include "utils.h" +#include "util.h" INCLUDE_MONSTER_LIST INCLUDE_BULLET_LIST diff --git a/Crawler/drawutil.cpp b/Crawler/drawutil.cpp new file mode 100644 index 00000000..82016fa9 --- /dev/null +++ b/Crawler/drawutil.cpp @@ -0,0 +1,137 @@ +#include "drawutil.h" +#include "Crawler.h" +#include "DEFINES.h" + +INCLUDE_game + +void drawutil::DrawCrosshair(Crawler*game,geom2d::rectrect,float accTime,float pulsatingAmt,float borderThickness){ + vf2d crosshairExtension={std::min(0.25f*rect.size.x-borderThickness/2,12.f),std::min(0.25f*rect.size.y-borderThickness/2,12.f)}; + vf2d pulseAmt=vf2d{1,1}*std::abs(std::sin(accTime*3))*2; + //Lower-Left Corner + vf2d pos=rect.pos+vf2d{0,rect.size.y-borderThickness}+vf2d{-pulseAmt.x,pulseAmt.y}; + vf2d size={borderThickness+crosshairExtension.x,borderThickness}; + game->FillRect(pos,size,RED); + pos=vf2d{pos.x,pos.y-crosshairExtension.y}; + size={borderThickness,crosshairExtension.y}; + game->FillRect(pos,size,RED); + //Lower-Right Corner + pos=rect.pos+vf2d{rect.size.x-borderThickness-crosshairExtension.x,rect.size.y-borderThickness}+vf2d{pulseAmt.x,pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->FillRect(pos,size,RED); + pos=vf2d{pos.x+crosshairExtension.x,pos.y-crosshairExtension.y}; + size={borderThickness,crosshairExtension.y}; + game->FillRect(pos,size,RED); + //Upper-Left Corner + pos=rect.pos+vf2d{0,0}+vf2d{-pulseAmt.x,-pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->FillRect(pos,size,RED); + pos=vf2d{pos.x,pos.y+borderThickness}; + size={borderThickness,crosshairExtension.y}; + game->FillRect(pos,size,RED); + //Upper-Right Corner + pos=rect.pos+vf2d{rect.size.x-borderThickness-crosshairExtension.x,0}+vf2d{pulseAmt.x,-pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->FillRect(pos,size,RED); + pos=vf2d{pos.x+crosshairExtension.x,pos.y+borderThickness}; + size={borderThickness,crosshairExtension.y}; + game->FillRect(pos,size,RED); +}; + +void drawutil::DrawCrosshairTransformedView(olc::TransformedView&view,geom2d::rectrect,float accTime,float pulsatingAmt,float borderThickness){ + vf2d crosshairExtension={std::min(0.25f*rect.size.x-borderThickness/2,12.f),std::min(0.25f*rect.size.y-borderThickness/2,12.f)}; + vf2d pulseAmt=vf2d{1,1}*std::abs(std::sin(accTime*3))*2; + //Lower-Left Corner + vf2d pos=rect.pos+vf2d{0,rect.size.y-borderThickness}+vf2d{-pulseAmt.x,pulseAmt.y}; + vf2d size={borderThickness+crosshairExtension.x,borderThickness}; + game->view.FillRect(pos,size,RED); + pos=vf2d{pos.x,pos.y-crosshairExtension.y}; + size={borderThickness,crosshairExtension.y}; + game->view.FillRect(pos,size,RED); + //Lower-Right Corner + pos=rect.pos+vf2d{rect.size.x-borderThickness-crosshairExtension.x,rect.size.y-borderThickness}+vf2d{pulseAmt.x,pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->view.FillRect(pos,size,RED); + pos=vf2d{pos.x+crosshairExtension.x,pos.y-crosshairExtension.y}; + size={borderThickness,crosshairExtension.y}; + game->view.FillRect(pos,size,RED); + //Upper-Left Corner + pos=rect.pos+vf2d{0,0}+vf2d{-pulseAmt.x,-pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->view.FillRect(pos,size,RED); + pos=vf2d{pos.x,pos.y+borderThickness}; + size={borderThickness,crosshairExtension.y}; + game->view.FillRect(pos,size,RED); + //Upper-Right Corner + pos=rect.pos+vf2d{rect.size.x-borderThickness-crosshairExtension.x,0}+vf2d{pulseAmt.x,-pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->view.FillRect(pos,size,RED); + pos=vf2d{pos.x+crosshairExtension.x,pos.y+borderThickness}; + size={borderThickness,crosshairExtension.y}; + game->view.FillRect(pos,size,RED); +} + +void drawutil::DrawCrosshairDecal(Crawler*game,geom2d::rectrect,float accTime,float pulsatingAmt,float borderThickness){ + vf2d crosshairExtension={std::min(0.25f*rect.size.x-borderThickness/2,12.f),std::min(0.25f*rect.size.y-borderThickness/2,12.f)}; + vf2d pulseAmt=vf2d{1,1}*std::abs(std::sin(accTime*3))*2; + //Lower-Left Corner + vf2d pos=rect.pos+vf2d{0,rect.size.y-borderThickness}+vf2d{-pulseAmt.x,pulseAmt.y}; + vf2d size={borderThickness+crosshairExtension.x,borderThickness}; + game->FillRectDecal(pos,size,RED); + pos=vf2d{pos.x,pos.y-crosshairExtension.y}; + size={borderThickness,crosshairExtension.y}; + game->FillRectDecal(pos,size,RED); + //Lower-Right Corner + pos=rect.pos+vf2d{rect.size.x-borderThickness-crosshairExtension.x,rect.size.y-borderThickness}+vf2d{pulseAmt.x,pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->FillRectDecal(pos,size,RED); + pos=vf2d{pos.x+crosshairExtension.x,pos.y-crosshairExtension.y}; + size={borderThickness,crosshairExtension.y}; + game->FillRectDecal(pos,size,RED); + //Upper-Left Corner + pos=rect.pos+vf2d{0,0}+vf2d{-pulseAmt.x,-pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->FillRectDecal(pos,size,RED); + pos=vf2d{pos.x,pos.y+borderThickness}; + size={borderThickness,crosshairExtension.y}; + game->FillRectDecal(pos,size,RED); + //Upper-Right Corner + pos=rect.pos+vf2d{rect.size.x-borderThickness-crosshairExtension.x,0}+vf2d{pulseAmt.x,-pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->FillRectDecal(pos,size,RED); + pos=vf2d{pos.x+crosshairExtension.x,pos.y+borderThickness}; + size={borderThickness,crosshairExtension.y}; + game->FillRectDecal(pos,size,RED); +}; + +void drawutil::DrawCrosshairDecalTransformedView(olc::TransformedView&view,geom2d::rectrect,float accTime,float pulsatingAmt,float borderThickness){ + vf2d crosshairExtension={std::min(0.25f*rect.size.x-borderThickness/2,12.f),std::min(0.25f*rect.size.y-borderThickness/2,12.f)}; + vf2d pulseAmt=vf2d{1,1}*std::abs(std::sin(accTime*3))*2; + //Lower-Left Corner + vf2d pos=rect.pos+vf2d{0,rect.size.y-borderThickness}+vf2d{-pulseAmt.x,pulseAmt.y}; + vf2d size={borderThickness+crosshairExtension.x,borderThickness}; + game->view.FillRectDecal(pos,size,RED); + pos=vf2d{pos.x,pos.y-crosshairExtension.y}; + size={borderThickness,crosshairExtension.y}; + game->view.FillRectDecal(pos,size,RED); + //Lower-Right Corner + pos=rect.pos+vf2d{rect.size.x-borderThickness-crosshairExtension.x,rect.size.y-borderThickness}+vf2d{pulseAmt.x,pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->view.FillRectDecal(pos,size,RED); + pos=vf2d{pos.x+crosshairExtension.x,pos.y-crosshairExtension.y}; + size={borderThickness,crosshairExtension.y}; + game->view.FillRectDecal(pos,size,RED); + //Upper-Left Corner + pos=rect.pos+vf2d{0,0}+vf2d{-pulseAmt.x,-pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->view.FillRectDecal(pos,size,RED); + pos=vf2d{pos.x,pos.y+borderThickness}; + size={borderThickness,crosshairExtension.y}; + game->view.FillRectDecal(pos,size,RED); + //Upper-Right Corner + pos=rect.pos+vf2d{rect.size.x-borderThickness-crosshairExtension.x,0}+vf2d{pulseAmt.x,-pulseAmt.y}; + size={borderThickness+crosshairExtension.x,borderThickness}; + game->view.FillRectDecal(pos,size,RED); + pos=vf2d{pos.x+crosshairExtension.x,pos.y+borderThickness}; + size={borderThickness,crosshairExtension.y}; + game->view.FillRectDecal(pos,size,RED); +} \ No newline at end of file diff --git a/Crawler/drawutil.h b/Crawler/drawutil.h new file mode 100644 index 00000000..933c598d --- /dev/null +++ b/Crawler/drawutil.h @@ -0,0 +1,11 @@ +#pragma once +#include "olcUTIL_Geometry2D.h" +#include "olcPGEX_TransformedView.h" +class Crawler; + +namespace drawutil{ + void DrawCrosshair(Crawler*game,geom2d::rectrect,float accTime,float pulsatingAmt=2,float borderThickness=4); + void DrawCrosshairTransformedView(TransformedView&view,geom2d::rectrect,float accTime,float pulsatingAmt=2,float borderThickness=4); + void DrawCrosshairDecal(Crawler*game,geom2d::rectrect,float accTime,float pulsatingAmt=2,float borderThickness=4); + void DrawCrosshairDecalTransformedView(TransformedView&view,geom2d::rectrect,float accTime,float pulsatingAmt=2,float borderThickness=4); +} \ No newline at end of file diff --git a/Crawler/utils.cpp b/Crawler/util.cpp similarity index 98% rename from Crawler/utils.cpp rename to Crawler/util.cpp index 89c58877..1a680755 100644 --- a/Crawler/utils.cpp +++ b/Crawler/util.cpp @@ -1,4 +1,4 @@ -#include "utils.h" +#include "util.h" #include "olcPixelGameEngine.h" float util::random(float range){ diff --git a/Crawler/utils.h b/Crawler/util.h similarity index 100% rename from Crawler/utils.h rename to Crawler/util.h