EShoot: changed to string weaponType to int currentlyEquippedItem
PlayerSystem.h: added HeldItem enum PlayerSystem.cpp: simplified writing doubles, uses HeldItem enum ShootEventTest.cpp: simplified writing doubles
This commit is contained in:
@@ -12,7 +12,7 @@ struct Shoot : Event
|
|||||||
{
|
{
|
||||||
//shotgun etc has different amounts of damage probably (a sniper shot might one-shot)
|
//shotgun etc has different amounts of damage probably (a sniper shot might one-shot)
|
||||||
//also different weapons will have different spread
|
//also different weapons will have different spread
|
||||||
std::string weaponType;
|
int currentlyEquippedItem;
|
||||||
//currentAimingPoint must be sent, in case the camera is moved while the event is being processed
|
//currentAimingPoint must be sent, in case the camera is moved while the event is being processed
|
||||||
glm::vec2 currentAimingPoint;
|
glm::vec2 currentAimingPoint;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ private:
|
|||||||
bool PlayerSystem::OnLeave(const Events::TriggerLeave &event);
|
bool PlayerSystem::OnLeave(const Events::TriggerLeave &event);
|
||||||
EventRelay<PlayerSystem, Events::MouseRelease> m_MouseRelease;
|
EventRelay<PlayerSystem, Events::MouseRelease> m_MouseRelease;
|
||||||
bool PlayerSystem::OnMouseRelease(const Events::MouseRelease& e);
|
bool PlayerSystem::OnMouseRelease(const Events::MouseRelease& e);
|
||||||
|
enum class HeldItem {
|
||||||
|
None = 0,
|
||||||
|
PrimaryWeapon = 1,
|
||||||
|
SecondaryWeapon = 2
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+10
-10
@@ -27,39 +27,39 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou
|
|||||||
leftMouseWasReleased = false;
|
leftMouseWasReleased = false;
|
||||||
//get the health component linked to the playerId
|
//get the health component linked to the playerId
|
||||||
double currentHealth = (double)world->GetComponent(player.EntityID, "Health")["Health"];
|
double currentHealth = (double)world->GetComponent(player.EntityID, "Health")["Health"];
|
||||||
double currentAmmo = (double)0;
|
double currentAmmo = 0.0;
|
||||||
double currentCoolDownTimer = (double)0;
|
double currentCoolDownTimer = 0.0;
|
||||||
|
|
||||||
if (fabs((double)player["EquippedItem"] - (double)1) < (double) 0.0001f) {
|
if (fabs((double)player["EquippedItem"] - (double)HeldItem::PrimaryWeapon) < 0.0001) {
|
||||||
ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem");
|
ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem");
|
||||||
currentAmmo = (double)currentItem["Ammo"];
|
currentAmmo = (double)currentItem["Ammo"];
|
||||||
currentCoolDownTimer = (double)currentItem["CoolDownTimer"];
|
currentCoolDownTimer = (double)currentItem["CoolDownTimer"];
|
||||||
}
|
}
|
||||||
if (fabs((double)player["EquippedItem"] - (double)2) < (double) 0.0001f) {
|
if (fabs((double)player["EquippedItem"] - (double)HeldItem::SecondaryWeapon) < 0.0001) {
|
||||||
ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem");
|
ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem");
|
||||||
currentAmmo = (double)currentItem["Ammo"];
|
currentAmmo = (double)currentItem["Ammo"];
|
||||||
currentCoolDownTimer = (double)currentItem["CoolDownTimer"];
|
currentCoolDownTimer = (double)currentItem["CoolDownTimer"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentHealth > (double)0.0f && currentAmmo > (double)0.0f && currentCoolDownTimer < (double)0.001f) {
|
if (currentHealth > 0.0 && currentAmmo > 0.0 && currentCoolDownTimer < 0.001) {
|
||||||
//decrease ammo count
|
//decrease ammo count
|
||||||
//TODO: temp, set the cooldowntimer - probably done in some other system (itemSystem?) later
|
//TODO: temp, set the cooldowntimer - probably done in some other system (itemSystem?) later
|
||||||
if (fabs((double)player["EquippedItem"] - (double)1) < (double) 0.0001f) {
|
if (fabs((double)player["EquippedItem"] - (double)HeldItem::PrimaryWeapon) < 0.0001) {
|
||||||
ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem");
|
ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "PrimaryItem");
|
||||||
int currentAmmoInt = (int)((double)currentItem["Ammo"]);
|
int currentAmmoInt = (int)((double)currentItem["Ammo"]);
|
||||||
currentItem["Ammo"] = (double)(currentAmmoInt - 1);
|
currentItem["Ammo"] = (double)(currentAmmoInt - 1);
|
||||||
currentItem["CoolDownTimer"] = (double)2;
|
currentItem["CoolDownTimer"] = 2.0;//change later!
|
||||||
}
|
}
|
||||||
if (fabs((double)player["EquippedItem"] - (double)2) < (double) 0.0001f) {
|
if (fabs((double)player["EquippedItem"] - (double)HeldItem::SecondaryWeapon) < 0.0001) {
|
||||||
ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem");
|
ComponentWrapper& currentItem = world->GetComponent(player.EntityID, "SecondaryItem");
|
||||||
int currentAmmoInt = (int)((double)currentItem["Ammo"]);
|
int currentAmmoInt = (int)((double)currentItem["Ammo"]);
|
||||||
currentItem["Ammo"] = (double)(currentAmmoInt - 1);
|
currentItem["Ammo"] = (double)(currentAmmoInt - 1);
|
||||||
currentItem["CoolDownTimer"] = (double)2;
|
currentItem["CoolDownTimer"] = 2.0;//change later!
|
||||||
}
|
}
|
||||||
//create and publish the shoot event
|
//create and publish the shoot event
|
||||||
Events::Shoot eShoot;
|
Events::Shoot eShoot;
|
||||||
eShoot.currentAimingPoint = aimingCoordinates;
|
eShoot.currentAimingPoint = aimingCoordinates;
|
||||||
eShoot.weaponType = (int)player["EquippedItem"];
|
eShoot.currentlyEquippedItem = (int) ((double)player["EquippedItem"]);
|
||||||
m_EventBroker->Publish(eShoot);
|
m_EventBroker->Publish(eShoot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,47 +148,47 @@ ShootEventTest::~ShootEventTest()
|
|||||||
void ShootEventTest::TestSetup1(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem)
|
void ShootEventTest::TestSetup1(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem)
|
||||||
{
|
{
|
||||||
//set currentweap
|
//set currentweap
|
||||||
player["EquippedItem"] = (double)1.0f;
|
player["EquippedItem"] = 1.0;
|
||||||
//set ammo set cooldown
|
//set ammo set cooldown
|
||||||
pItem["Ammo"] = (double)100.0f;
|
pItem["Ammo"] = 100.0;
|
||||||
pItem["CoolDownTimer"] = (double)0.0f;
|
pItem["CoolDownTimer"] = 0.0;
|
||||||
}
|
}
|
||||||
void ShootEventTest::TestSetup2(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem)
|
void ShootEventTest::TestSetup2(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem)
|
||||||
{
|
{
|
||||||
//set currentweap
|
//set currentweap
|
||||||
player["EquippedItem"] = (double)2.0f;
|
player["EquippedItem"] = 2.0;
|
||||||
//set ammo set cooldown
|
//set ammo set cooldown
|
||||||
sItem["Ammo"] = (double)10.0f;
|
sItem["Ammo"] = 10.0;
|
||||||
sItem["CoolDownTimer"] = (double)0.0f;
|
sItem["CoolDownTimer"] = 0.0;
|
||||||
}
|
}
|
||||||
void ShootEventTest::TestSetup3(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem)
|
void ShootEventTest::TestSetup3(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem)
|
||||||
{
|
{
|
||||||
player["EquippedItem"] = (double)0.0f;
|
player["EquippedItem"] = 0.0;
|
||||||
pItem["Ammo"] = (double)100.0f;
|
pItem["Ammo"] = 100.0;
|
||||||
sItem["Ammo"] = (double)100.0f;
|
sItem["Ammo"] = 100.0;
|
||||||
//TestSucceeded will be set to false if ammo changes during the 100 loops
|
//TestSucceeded will be set to false if ammo changes during the 100 loops
|
||||||
TestSucceeded = true;
|
TestSucceeded = true;
|
||||||
}
|
}
|
||||||
void ShootEventTest::TestSetup4(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem)
|
void ShootEventTest::TestSetup4(ComponentWrapper &player, ComponentWrapper &pItem, ComponentWrapper &sItem)
|
||||||
{
|
{
|
||||||
//set currentweap
|
//set currentweap
|
||||||
player["EquippedItem"] = (double)1.0f;
|
player["EquippedItem"] = 1.0;
|
||||||
//set ammo set cooldown
|
//set ammo set cooldown
|
||||||
pItem["Ammo"] = (double)100.0f;
|
pItem["Ammo"] = 100.0;
|
||||||
pItem["CoolDownTimer"] = (double)5.0f;
|
pItem["CoolDownTimer"] = 5.0;
|
||||||
//TestSucceeded will be set to false if ammo changes during the 100 loops
|
//TestSucceeded will be set to false if ammo changes during the 100 loops
|
||||||
TestSucceeded = true;
|
TestSucceeded = true;
|
||||||
}
|
}
|
||||||
void ShootEventTest::TestSuccess1() {
|
void ShootEventTest::TestSuccess1() {
|
||||||
//if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired
|
//if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired
|
||||||
double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"];
|
double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"];
|
||||||
if (currentAmmo == (double)99)
|
if (currentAmmo == 99.0)
|
||||||
TestSucceeded = true;
|
TestSucceeded = true;
|
||||||
}
|
}
|
||||||
void ShootEventTest::TestSuccess2() {
|
void ShootEventTest::TestSuccess2() {
|
||||||
//if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired
|
//if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired
|
||||||
double currentAmmo = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"];
|
double currentAmmo = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"];
|
||||||
if (currentAmmo == (double)9)
|
if (currentAmmo == 9.0)
|
||||||
TestSucceeded = true;
|
TestSucceeded = true;
|
||||||
}
|
}
|
||||||
void ShootEventTest::TestSuccess3() {
|
void ShootEventTest::TestSuccess3() {
|
||||||
@@ -201,7 +201,7 @@ void ShootEventTest::TestSuccess3() {
|
|||||||
//if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired
|
//if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired
|
||||||
double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"];
|
double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"];
|
||||||
double currentAmmoSecondary = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"];
|
double currentAmmoSecondary = m_World->GetComponent(m_PlayerID, "SecondaryItem")["Ammo"];
|
||||||
if (currentAmmo != (double)100 || currentAmmoSecondary != (double)100)
|
if (currentAmmo != 100.0 || currentAmmoSecondary != 100.0)
|
||||||
TestSucceeded = false;
|
TestSucceeded = false;
|
||||||
}
|
}
|
||||||
void ShootEventTest::TestSuccess4() {
|
void ShootEventTest::TestSuccess4() {
|
||||||
@@ -213,7 +213,7 @@ void ShootEventTest::TestSuccess4() {
|
|||||||
m_EventBroker->Publish(eMouseRelease);
|
m_EventBroker->Publish(eMouseRelease);
|
||||||
//if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired
|
//if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired
|
||||||
double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"];
|
double currentAmmo = m_World->GetComponent(m_PlayerID, "PrimaryItem")["Ammo"];
|
||||||
if (currentAmmo != (double)100)
|
if (currentAmmo != 100.0)
|
||||||
TestSucceeded = false;
|
TestSucceeded = false;
|
||||||
}
|
}
|
||||||
void ShootEventTest::Tick()
|
void ShootEventTest::Tick()
|
||||||
|
|||||||
Reference in New Issue
Block a user