Merge pull request #157 from teamfisk/DashAbiltyEffect
Dash abilty effect
This commit is contained in:
@@ -27,7 +27,7 @@ public:
|
||||
virtual bool OnCommand(const Events::InputCommand& e) override;
|
||||
virtual void Reset();
|
||||
|
||||
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer);
|
||||
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityID playerID);
|
||||
virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; }
|
||||
virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; }
|
||||
|
||||
@@ -41,6 +41,7 @@ protected:
|
||||
bool m_Crouching = false;
|
||||
//assault dash membervariables - needed to calculate the doubletap- and dashlogic
|
||||
double m_AssaultDashDoubleTapDeltaTime = 0.0;
|
||||
double m_DashEffectResetTimer = 0.0;
|
||||
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable),
|
||||
//and its very unlikely that someone wants to change that value
|
||||
const float m_AssaultDashDoubleTapSensitivityTimer = 0.25f;
|
||||
@@ -51,7 +52,7 @@ protected:
|
||||
bool m_ShiftDashing = false;
|
||||
bool m_ValidDoubleTap = false;
|
||||
|
||||
//specialabilitys
|
||||
//specialabilities
|
||||
bool m_MovementKeyDown = false;
|
||||
bool m_SpecialAbilityKeyDown = false;
|
||||
int m_NumberOfMovementKeysDown = 0;
|
||||
@@ -190,12 +191,19 @@ bool FirstPersonInputController<EventContext>::OnLockMouse(const Events::LockMou
|
||||
}
|
||||
|
||||
template <typename EventContext>
|
||||
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer) {
|
||||
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityID playerID) {
|
||||
m_AssaultDashDoubleTapDeltaTime += dt;
|
||||
m_DashEffectResetTimer += dt;
|
||||
assaultDashCoolDownTimer -= dt;
|
||||
//cooldown = assaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work)
|
||||
if (assaultDashCoolDownTimer > (assaultDashCoolDownMaxTimer - 0.25f)) {
|
||||
m_PlayerIsDashing = true;
|
||||
if (m_DashEffectResetTimer > 0.05) {
|
||||
Events::DashAbility e;
|
||||
e.Player = playerID;
|
||||
m_EventBroker->Publish(e);
|
||||
m_DashEffectResetTimer = 0.0;
|
||||
}
|
||||
} else {
|
||||
m_PlayerIsDashing = false;
|
||||
}
|
||||
@@ -207,6 +215,9 @@ void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool
|
||||
assaultDashCoolDownTimer = assaultDashCoolDownMaxTimer;
|
||||
m_AssaultDashDoubleTapped = true;
|
||||
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||
Events::DashAbility e;
|
||||
e.Player = playerID;
|
||||
m_EventBroker->Publish(e);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -237,6 +248,7 @@ void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool
|
||||
assaultDashCoolDownTimer = assaultDashCoolDownMaxTimer;
|
||||
|
||||
Events::DashAbility e;
|
||||
e.Player = playerID;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "Core/EPlayerSpawned.h"
|
||||
#include "Core/EAmmoPickup.h"
|
||||
#include "Network/ESearchForServers.h"
|
||||
#include "../Game/Events/EDashAbility.h"
|
||||
|
||||
struct ServerInfo
|
||||
{
|
||||
@@ -107,6 +108,7 @@ private:
|
||||
void parsePlayerDamage(Packet& packet);
|
||||
void parseComponentDeletion(Packet& packet);
|
||||
void parseDoubleJump(Packet& packet);
|
||||
void parseDashEffect(Packet& packet);
|
||||
void parseAmmoPickup(Packet& packet);
|
||||
void InterpolateFields(Packet& packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
|
||||
void parseSnapshot(Packet& packet);
|
||||
@@ -135,6 +137,9 @@ private:
|
||||
EventRelay< Client, Events::SearchForServers> m_ESearchForServers;
|
||||
EventRelay<Client, Events::DoubleJump> m_EDoubleJump;
|
||||
bool OnDoubleJump(Events::DoubleJump & e);
|
||||
EventRelay<Client, Events::DashAbility> m_EDashAbility;
|
||||
bool OnDashAbility(const Events::DashAbility& e);
|
||||
|
||||
bool OnSearchForServers(const Events::SearchForServers& e);
|
||||
UDPClient m_ServerlistRequest;
|
||||
std::vector<ServerInfo> m_Serverlist;
|
||||
|
||||
@@ -20,6 +20,7 @@ enum class MessageType
|
||||
ComponentDeleted,
|
||||
PlayerTransform,
|
||||
OnDoubleJump,
|
||||
OnDashEffect,
|
||||
ServerlistRequest,
|
||||
AmmoPickup,
|
||||
Invalid
|
||||
|
||||
@@ -83,6 +83,7 @@ private:
|
||||
void parseClientPing();
|
||||
void parsePing();
|
||||
bool parseDoubleJump(Packet& packet);
|
||||
void parseDashEffect(Packet& packet);
|
||||
void parseUDPConnect(Packet& packet);
|
||||
void parseTCPConnect(Packet& packet);
|
||||
void parseDisconnect();
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
#define Events_DashAbility_h__
|
||||
|
||||
#include "Core/Event.h"
|
||||
#include "Core/EntityWrapper.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct DashAbility : public Event { };
|
||||
struct DashAbility : public Event
|
||||
{
|
||||
EntityID Player;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ private:
|
||||
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
||||
EventRelay<PlayerMovementSystem, Events::DoubleJump> m_EDoubleJump;
|
||||
bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e);
|
||||
EventRelay<PlayerMovementSystem, Events::DashAbility> m_EDashAbility;
|
||||
bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e);
|
||||
|
||||
void updateMovementControllers(double dt);
|
||||
void updateVelocity(EntityWrapper player, double dt);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<Entity name="DashEffect" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
|
||||
|
||||
<Components>
|
||||
<c:Animation/>
|
||||
<c:Lifetime>
|
||||
<Lifetime>0.5</Lifetime>
|
||||
</c:Lifetime>
|
||||
<c:ExplosionEffect>
|
||||
<Velocity X="0" Y="0" Z="0"/>
|
||||
<TimeSinceDeath>0</TimeSinceDeath>
|
||||
<ExplosionDuration>0.5</ExplosionDuration>
|
||||
<EndColor A="0" B="0" G="0" R="0"/>
|
||||
</c:ExplosionEffect>
|
||||
<c:Model/>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
</Entity>
|
||||
@@ -33,6 +33,7 @@ void Client::Connect(std::string address, int port)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Client::OnPlayerDamage);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &Client::OnPlayerSpawned);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &Client::OnDoubleJump);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &Client::OnDashAbility);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESearchForServers, &Client::OnSearchForServers);
|
||||
auto config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
m_Address = address;
|
||||
@@ -143,6 +144,9 @@ void Client::parseMessageType(Packet& packet)
|
||||
case MessageType::OnDoubleJump:
|
||||
parseDoubleJump(packet);
|
||||
break;
|
||||
case MessageType::OnDashEffect:
|
||||
parseDashEffect(packet);
|
||||
break;
|
||||
case MessageType::AmmoPickup:
|
||||
parseAmmoPickup(packet);
|
||||
break;
|
||||
@@ -262,7 +266,7 @@ void Client::parseEntityDeletion(Packet & packet)
|
||||
if (m_ServerIDToClientID.find(entityToDelete) != m_ServerIDToClientID.end()) {
|
||||
EntityID localEntity = m_ServerIDToClientID.at(entityToDelete);
|
||||
if (m_World->ValidEntity(localEntity)) {
|
||||
if (m_World->HasComponent(localEntity,"Player")) {
|
||||
if (m_World->HasComponent(localEntity, "Player")) {
|
||||
Events::PlayerDeath e;
|
||||
e.Player = EntityWrapper(m_World, localEntity);
|
||||
m_EventBroker->Publish(e);
|
||||
@@ -297,8 +301,22 @@ void Client::parseDoubleJump(Packet & packet)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Client::parseDashEffect(Packet& packet)
|
||||
{
|
||||
EntityID serverID = packet.ReadPrimitive<EntityID>();
|
||||
if (!serverClientMapsHasEntity(serverID)) {
|
||||
return;
|
||||
}
|
||||
Events::DashAbility e;
|
||||
e.Player = m_ServerIDToClientID.at(serverID);
|
||||
if (e.Player != m_LocalPlayer.ID) {
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
|
||||
void Client::parseAmmoPickup(Packet & packet)
|
||||
{
|
||||
{
|
||||
Events::AmmoPickup e;
|
||||
e.AmmoGain = packet.ReadPrimitive<int>();
|
||||
e.Player = m_LocalPlayer;
|
||||
@@ -388,7 +406,7 @@ void Client::parseSnapshot(Packet& packet)
|
||||
if (m_SnapshotFilter != nullptr) {
|
||||
shouldApply = m_SnapshotFilter->FilterComponent(localEntity, newComponent);
|
||||
}
|
||||
if (shouldApply) {
|
||||
if (shouldApply) {
|
||||
ComponentWrapper currentComponent = m_World->GetComponent(localEntityID, componentType);
|
||||
memcpy(currentComponent.Data, newComponent.Data, componentInfo.Stride);
|
||||
}
|
||||
@@ -518,6 +536,18 @@ bool Client::OnPlayerSpawned(const Events::PlayerSpawned& e)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Client::OnDashAbility(const Events::DashAbility& e)
|
||||
{
|
||||
if (!clientServerMapsHasEntity(e.Player) || e.Player != m_LocalPlayer.ID) {
|
||||
return false;
|
||||
}
|
||||
Packet packet(MessageType::OnDashEffect);
|
||||
packet.WritePrimitive(m_ClientIDToServerID.at(e.Player));
|
||||
m_Reliable.Send(packet);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::OnSearchForServers(const Events::SearchForServers& e)
|
||||
{
|
||||
m_SearchingForServers = true;
|
||||
|
||||
@@ -141,6 +141,9 @@ void Server::parseMessageType(Packet& packet)
|
||||
case MessageType::OnDoubleJump:
|
||||
parseDoubleJump(packet);
|
||||
break;
|
||||
case MessageType::OnDashEffect:
|
||||
parseDashEffect(packet);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -555,6 +558,11 @@ bool Server::parseDoubleJump(Packet & packet)
|
||||
return true;
|
||||
}
|
||||
|
||||
void Server::parseDashEffect(Packet& packet)
|
||||
{
|
||||
reliableBroadcast(packet);
|
||||
}
|
||||
|
||||
void Server::parseOnInputCommand(Packet& packet)
|
||||
{
|
||||
PlayerID player = -1;
|
||||
|
||||
@@ -5,6 +5,7 @@ PlayerMovementSystem::PlayerMovementSystem(SystemParams params)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &PlayerMovementSystem::OnDoubleJump);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &PlayerMovementSystem::OnDashAbility);
|
||||
}
|
||||
|
||||
PlayerMovementSystem::~PlayerMovementSystem()
|
||||
@@ -72,7 +73,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
|
||||
ComponentWrapper cPhysics = player["Physics"];
|
||||
//Assault Dash Check
|
||||
if (player.HasComponent("DashAbility")) {
|
||||
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"]);
|
||||
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"], player.ID);
|
||||
}
|
||||
wishDirection = controller->Movement() * glm::inverse(glm::quat(ori));
|
||||
//this makes sure you can only dash in the 4 directions: forw,backw,left,right
|
||||
@@ -313,11 +314,11 @@ bool PlayerMovementSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
||||
bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e)
|
||||
{
|
||||
// If entity does not exist, exit
|
||||
if (!EntityWrapper(m_World, e.entityID).Valid()) {
|
||||
if (!EntityWrapper(m_World, e.entityID).Valid()) {
|
||||
return false;
|
||||
}
|
||||
// If entity IsLocalPlayer, exit
|
||||
if (e.entityID == m_LocalPlayer.ID) {
|
||||
if (e.entityID == m_LocalPlayer.ID) {
|
||||
return false;
|
||||
}
|
||||
spawnHexagon(EntityWrapper(m_World, e.entityID));
|
||||
@@ -325,11 +326,37 @@ bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e)
|
||||
}
|
||||
|
||||
void PlayerMovementSystem::spawnHexagon(EntityWrapper target)
|
||||
{
|
||||
{
|
||||
//put a hexagon at the entitys... feet?
|
||||
auto hexagonEffect = ResourceManager::Load<EntityFile>("Schema/Entities/DoubleJumpHexagon.xml");
|
||||
EntityFileParser parser(hexagonEffect);
|
||||
EntityID hexagonEffectID = parser.MergeEntities(m_World);
|
||||
EntityWrapper hexagonEW = EntityWrapper(m_World, hexagonEffectID);
|
||||
hexagonEW["Transform"]["Position"] = (glm::vec3)target["Transform"]["Position"];
|
||||
}
|
||||
}
|
||||
|
||||
bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
|
||||
{
|
||||
EntityWrapper player(m_World, e.Player);
|
||||
if (!player.Valid() || !IsClient || player.ID == LocalPlayer.ID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto dashEffectResource = ResourceManager::Load<EntityFile>("Schema/Entities/DashEffect.xml");
|
||||
EntityFileParser parser(dashEffectResource);
|
||||
EntityID dashEffectID = parser.MergeEntities(m_World);
|
||||
EntityWrapper dashEffect(m_World, dashEffectID);
|
||||
auto playerModel = player.FirstChildByName("PlayerModel");
|
||||
auto playerEntityModel = playerModel["Model"];
|
||||
auto playerEntityAnimation = playerModel["Animation"];
|
||||
playerEntityModel.Copy(dashEffect["Model"]);
|
||||
playerEntityAnimation.Copy(dashEffect["Animation"]);
|
||||
dashEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"];
|
||||
((glm::vec4&)dashEffect["ExplosionEffect"]["EndColor"]).w = 0.f;
|
||||
dashEffect["Animation"]["Speed1"] = 0.0;
|
||||
dashEffect["Animation"]["Speed2"] = 0.0;
|
||||
dashEffect["Animation"]["Speed3"] = 0.0;
|
||||
dashEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"];
|
||||
dashEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"];
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user