Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ component BattlePlayerDataQComponent
// Player's attributes
int GridExtendTop;
int GridExtendBottom;
bool DisableMovement;
bool DisableRotation;
BattlePlayerSpawnBehaviour SpawnBehaviour;

Expand Down Expand Up @@ -65,6 +66,7 @@ component BattlePlayerDataTemplateQComponent

BattlePlayerHitboxTemplate Hitbox;

bool DisableMovement;
bool DisableRotation;

BattlePlayerSpawnBehaviour SpawnBehaviour;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ component BattlePlayerClass100DataQComponent
FrameTimer JoystickTimer;
[HideInInspector]
FrameTimer CooldownTimer;
[HideInInspector]
FrameTimer PlacementTimer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ component BattlePlayerClass100ProjectileQComponent
FPVector2 Direction;
[HideInInspector]
FP Speed;
[HideInInspector]
FP Radius;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public struct ProjectileCollisionData
public EntityRef OtherEntity;
}

public struct PlayerClass100ProjectileCollisionData
{
public BattlePlayerClass100ProjectileQComponent* Projectile;
public EntityRef ProjectileEntity;
public EntityRef OtherEntity;
}

public struct ArenaBorderCollisionData
{
public BattleArenaBorderQComponent* ArenaBorder;
Expand Down Expand Up @@ -243,6 +250,13 @@ public void OnTrigger2D(Frame f, TriggerInfo2D info)
{
BattlePlayerClass100ProjectileQComponent* playerClass100Projectile = f.Unsafe.GetPointer<BattlePlayerClass100ProjectileQComponent>(info.Entity);

PlayerClass100ProjectileCollisionData playerClass100ProjectileCollisionData = new()
{
Projectile = playerClass100Projectile,
ProjectileEntity = info.Entity,
OtherEntity = info.Other
};

switch (collisionTrigger->Type)
{
case BattleCollisionTriggerType.Projectile:
Expand Down Expand Up @@ -273,7 +287,12 @@ public void OnTrigger2D(Frame f, TriggerInfo2D info)
case BattleCollisionTriggerType.ArenaBorder:
{
s_debugLogger.Log("Player class 100 projectile hit the Arena Border");
BattlePlayerClass100ProjectileQSystem.OnProjectileHitObstacle(f, info.Entity);

ArenaBorderCollisionData arenaBorderCollisionData = new()
{
ArenaBorder = f.Unsafe.GetPointer<BattleArenaBorderQComponent>(info.Other)
};
BattlePlayerClass100ProjectileQSystem.OnProjectileHitArenaBorder(f, &arenaBorderCollisionData, &playerClass100ProjectileCollisionData);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public override void Update(Frame f)
// Transition from GetReadyToPlay to Playing
if (gameSession->TimeUntilStartSec <= FP._0)
{
BattlePlayerQSystem.OnGameStart(f);
BattleProjectileQSystem.Launch(f);
f.Events.BattleViewGameStart();
gameSession->State = BattleGameState.Playing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ public virtual unsafe void OnProjectileHitPlayerShield(Frame f, BattleCollisionQ
/// <param name="playerData">Pointer to the player data.</param>
/// <param name="playerEntity">Reference to the player entity.</param>
public virtual unsafe void OnUpdate(Frame f, BattlePlayerManager.PlayerHandle playerHandle, BattlePlayerDataQComponent* playerData, BattlePlayerEntityRef playerEntity, BattleSpecialInput* specialInput) { }

/// <summary>
/// Called by the @cref{Battle.QSimulation.Player,BattlePlayerClassManager}
/// <see cref="BattlePlayerClassManager.OnGameStart(Frame, BattlePlayerManager.PlayerHandle, BattlePlayerDataQComponent*, EntityRef)">OnGameStart</see> method
/// when the game starts.<br/>
/// Provides a hook for derived classes to implement character class specific simulation logic.
/// </summary>
///
/// <param name="f">Current simulation frame.</param>
/// <param name="playerHandle">Reference to the player handle.</param>
/// <param name="playerData">Pointer to the player data.</param>
/// <param name="playerEntity">Reference to the player entity.</param>
public virtual unsafe void OnGameStart(Frame f, BattlePlayerManager.PlayerHandle playerHandle, BattlePlayerDataQComponent* playerData, EntityRef playerEntity) { }
}

/// <summary>
Expand Down Expand Up @@ -389,6 +402,23 @@ public static void OnUpdate(Frame f, BattlePlayerManager.PlayerHandle playerHand
playerClass.OnUpdate(f, playerHandle, playerData, playerEntity, specialInput);
}

/// <summary>
/// Calls the OnGameStart method of the class of the given player character, if it is implemented.
/// </summary>
///
/// <param name="f">Current simulation frame.</param>
/// <param name="playerHandle">Reference to the player handle.</param>
/// <param name="playerData">Pointer to the player data.</param>
/// <param name="playerEntity">Reference to the player entity.</param>
public static void OnGameStart(Frame f, BattlePlayerManager.PlayerHandle playerHandle, BattlePlayerDataQComponent* playerData, EntityRef playerEntity)
{
ReturnCode returnCode = GetClass(playerData->CharacterClass, out BattlePlayerClassBase playerClass);

if (returnCode != ReturnCode.ClassRetrieved) return;

playerClass.OnGameStart(f, playerHandle, playerData, playerEntity);
}

/// <value>Constant for a class index error.</value>
private const int ClassIndexError = -1;
/// <value>Constant for Desensitizer class index.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,12 @@ public static void CreatePlayers(Frame f)
// player's attributes
GridExtendTop = playerGridExtendTop,
GridExtendBottom = playerGridExtendBottom,
DisableMovement = playerCharacterDataTemplate->DisableMovement,
DisableRotation = playerCharacterDataTemplate->DisableRotation,
SpawnBehaviour = playerCharacterDataTemplate->SpawnBehaviour,

// player's current state related data
MovementEnabled = true,
MovementEnabled = !playerCharacterDataTemplate->DisableMovement,
RotationEnabled = !playerCharacterDataTemplate->DisableRotation,
CurrentDefence = FP._0,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ public static void OnProjectileHitPlayerShield(Frame f, BattleCollisionQSystem.P
BattleProjectileQSystem.SetCollisionFlag(f, projectileCollisionData->Projectile, BattleProjectileCollisionFlags.Player);
}

/// <summary>
/// Calls BattlePlayerClassManager::OnGameStart for every player's selected character.
/// </summary>
///
/// <param name="f">Current simulation frame.</param>
public static void OnGameStart(Frame f)
{
foreach (BattlePlayerManager.PlayerHandle playerHandle in BattlePlayerManager.PlayerHandle.GetPlayerHandleArray(f))
{
if (playerHandle.PlayState.IsNotInGame()) continue;

BattlePlayerEntityRef entityRef = playerHandle.GetSelectedCharacterEntityRef(f);
BattlePlayerDataQComponent* playerData = entityRef.GetDataQComponent(f);

BattlePlayerClassManager.OnGameStart(f, playerHandle, playerData, entityRef);
}
}

/// <summary>
/// <span class="brief-h"><a href="https://doc.photonengine.com/quantum/current/manual/quantum-ecs/systems">Quantum System Update method@u-exlink</a> gets called every frame.</span><br/>
/// Relays the appropriate input data to each player in the game
Expand Down Expand Up @@ -633,7 +651,7 @@ private void HandleInPlay(Frame f, Input* input, BattlePlayerManager.PlayerHandl

if (!playerData->StunCooldown.IsRunning(f))
{
playerData->MovementEnabled = true;
playerData->MovementEnabled = !playerData->DisableMovement;
playerData->RotationEnabled = !playerData->DisableRotation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// Battle Qsimulation usings
using Battle.QSimulation.Projectile;
using Battle.QSimulation.Game;

namespace Battle.QSimulation.Player
{
Expand Down Expand Up @@ -53,11 +54,13 @@ public static void Create(Frame f, EntityPrototype entityPrototype, FPVector2 po
// get components
Transform2D* projectileTransform = f.Unsafe.GetPointer<Transform2D>(projectileEntityRef);
BattlePlayerClass100ProjectileQComponent* projectile = f.Unsafe.GetPointer<BattlePlayerClass100ProjectileQComponent>(projectileEntityRef);
PhysicsCollider2D* collider = f.Unsafe.GetPointer<PhysicsCollider2D>(projectileEntityRef);

// set Initial projectile direction and speed
projectileTransform->Position = position;
projectile->Direction = direction;
projectile->Speed = speed;
projectile->Radius = collider->Shape.Circle.Radius;
}

/// <summary>
Expand All @@ -71,7 +74,7 @@ public static void Create(Frame f, EntityPrototype entityPrototype, FPVector2 po
/// <param name="filter">Reference to <a href="https://doc.photonengine.com/quantum/current/manual/quantum-ecs/systems">Quantum Filter@u-exlink</a>.</param>
public override void Update(Frame f, ref Filter filter)
{
filter.Transform->Position += filter.Projectile->Direction * filter.Projectile->Speed;
filter.Transform->Position += filter.Projectile->Direction * (filter.Projectile->Speed * f.DeltaTime);
}

/// <summary>
Expand All @@ -93,6 +96,43 @@ public static void OnProjectileHitEmotionProjectile(
f.Destroy(playerClass100ProjectileEntityRef);
}

/// <summary>
/// Updates the player class 100 projectile's direction when it hits the arena border.
/// </summary>
///
/// <param name="f">Current simulation frame.</param>
/// <param name="arenaCollisionData">Collision data related to the arena.</param>
/// <param name="playerClass100ProjectileCollisionData">Collision data related to the class 100 projectile.</param>
public static void OnProjectileHitArenaBorder(
Frame f,
BattleCollisionQSystem.ArenaBorderCollisionData* arenaCollisionData,
BattleCollisionQSystem.PlayerClass100ProjectileCollisionData* playerClass100ProjectileCollisionData
)
{
BattlePlayerClass100ProjectileQComponent* playerClass100Projectile = playerClass100ProjectileCollisionData->Projectile;
EntityRef playerClass100ProjectileEntityRef = playerClass100ProjectileCollisionData->ProjectileEntity;
EntityRef otherEntity = playerClass100ProjectileCollisionData->OtherEntity;
BattleArenaBorderQComponent* arenaBorder = arenaCollisionData->ArenaBorder;

FPVector2 normal = arenaBorder->Normal;
FP collisionMinOffset = arenaBorder->CollisionMinOffset;

FPVector2 direction = FPVector2.Reflect(playerClass100Projectile->Direction, normal).Normalized;

Transform2D* projectileTransform = f.Unsafe.GetPointer<Transform2D>(playerClass100ProjectileEntityRef);
Transform2D* otherTransform = f.Unsafe.GetPointer<Transform2D>(otherEntity);

FPVector2 offsetVector = projectileTransform->Position - otherTransform->Position;
FP collisionOffset = FPVector2.Rotate(offsetVector, -FPVector2.RadiansSigned(FPVector2.Up, normal)).Y;

if (collisionOffset - playerClass100Projectile->Radius < collisionMinOffset)
{
projectileTransform->Position += normal * (collisionMinOffset - collisionOffset + playerClass100Projectile->Radius);
}

playerClass100Projectile->Direction = direction;
}

/// <summary>
/// Destroys the player class 100 projectile.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ public class BattlePlayerClass100QSpec : AssetObject
[Tooltip("Maximum distance from joystick center for a press to register as pressing the middle")]
/// <summary>Maximum distance from joystick center for a press to register as pressing the middle</summary>
public FP JoystickTapDistanceMax;
[Tooltip("Time in seconds before character stops moving completely.")]
/// <summary>Time in seconds before character stops moving completely.</summary>
public FP PlacementTimeDurationSec;
}
}
Loading