implemented bolas + status effect mechanic

This commit is contained in:
Adam Salah 2025-07-14 23:44:00 -04:00
parent e7a03f71ec
commit d9b96438de
20 changed files with 515 additions and 43 deletions

View File

@ -152,7 +152,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 531d7966d86bd0c4d83baf58bcb56cd5, type: 3}
m_Name:
m_EditorClassIdentifier:
_entityLinked: {fileID: 6069600615579642376}
_entityLinked: {fileID: 5530763025372097863}
--- !u!1 &1167891119861249516
GameObject:
m_ObjectHideFlags: 0
@ -499,10 +499,10 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 7468362030574254172}
- component: {fileID: 5530763025372097863}
- component: {fileID: 7802907299062813180}
- component: {fileID: 1182150014477180862}
- component: {fileID: 5931428661698025033}
- component: {fileID: 6069600615579642376}
- component: {fileID: 577648786767256172}
m_Layer: 0
m_Name: bolasStick
@ -530,6 +530,24 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5530763025372097863
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7468362030574254173}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 20821ed53f7f53e4cbdc7b3157c35b97, type: 3}
m_Name:
m_EditorClassIdentifier:
_lifeBar: {fileID: 9115548409632460044}
_hp: 4
_speed: 0
_attack_damage: 1
_attack_interval: 4
_enemy: {fileID: 0}
--- !u!50 &7802907299062813180
Rigidbody2D:
serializedVersion: 4
@ -592,24 +610,6 @@ MonoBehaviour:
playableSounds:
- {fileID: 11400000, guid: 24352f713d54a924c98784212780e0da, type: 2}
- {fileID: 11400000, guid: 155d3b4d90b751748a35f21d3074b910, type: 2}
--- !u!114 &6069600615579642376
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7468362030574254173}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4efc1afdf7c559a4cac25dad0d8917cb, type: 3}
m_Name:
m_EditorClassIdentifier:
_lifeBar: {fileID: 9115548409632460044}
_hp: 4
_speed: 0
_attack_damage: 1
_attack_interval: 4
_enemy: {fileID: 0}
--- !u!82 &577648786767256172
AudioSource:
m_ObjectHideFlags: 0
@ -1963,8 +1963,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c0fbd934c179894458914437255781c4, type: 3}
m_Name:
m_EditorClassIdentifier:
_entity: {fileID: 6069600615579642376}
_projectile: {fileID: 6962989255644195630, guid: 869a03bba705e8d4485aa73daad773dc, type: 3}
_entity: {fileID: 5530763025372097863}
_projectile: {fileID: 6962989255644195630, guid: 3df5eaab2a4c1d64bba590ed4e1ac0f7, type: 3}
_projectileSpawn: {fileID: 7322466304790414952}
--- !u!1 &9107841294774877216
GameObject:

View File

@ -0,0 +1,231 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6962989255644195630
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6962989255644195631}
- component: {fileID: -1491803373025033585}
- component: {fileID: 2924140018079318964}
m_Layer: 0
m_Name: bolasProjectile
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6962989255644195631
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6962989255644195630}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -6.61, y: -0.638, z: 1.8112363}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6962989256011107500}
- {fileID: 6802302589573039538}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!50 &-1491803373025033585
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6962989255644195630}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 0
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 4
--- !u!114 &2924140018079318964
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6962989255644195630}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: af32629f84318134799756134098abf9, type: 3}
m_Name:
m_EditorClassIdentifier:
_detectionLinked: {fileID: 4130391605812397686}
straightProjectile: 1
_angle: 0
_speed: 2
_slowIntensity: 0.25
--- !u!1 &6962989256011107503
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6962989256011107500}
- component: {fileID: 6962989256011107501}
m_Layer: 0
m_Name: sprite
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6962989256011107500
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6962989256011107503}
m_LocalRotation: {x: 0, y: -0, z: 0.7071068, w: -0.7071068}
m_LocalPosition: {x: 0.0259, y: 0.01, z: 0}
m_LocalScale: {x: 0.5394133, y: 0.56488746, z: 0.9686}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 6962989255644195631}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 270}
--- !u!212 &6962989256011107501
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6962989256011107503}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 364159097
m_SortingLayer: 1
m_SortingOrder: 4
m_Sprite: {fileID: 21300000, guid: b28a7c5aeb45b224983f69339965c55d, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1.06, y: 1.69}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &8726647054546243319
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6802302589573039538}
- component: {fileID: 7006189111012443782}
- component: {fileID: 4130391605812397686}
m_Layer: 0
m_Name: detection
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6802302589573039538
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8726647054546243319}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 6962989255644195631}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &7006189111012443782
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8726647054546243319}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0.16277367, y: 0.016521543}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.3744527, y: 0.17825907}
m_EdgeRadius: 0
--- !u!114 &4130391605812397686
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8726647054546243319}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 531d7966d86bd0c4d83baf58bcb56cd5, type: 3}
m_Name:
m_EditorClassIdentifier:
_entityLinked: {fileID: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3df5eaab2a4c1d64bba590ed4e1ac0f7
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -11,7 +11,6 @@ public class Ally : Entity
public override float SpeedMultiplier => GlobalConfig.Instance.Current.allySpeedMultiplier;
public float PopulationCost => GlobalConfig.Instance.Current.populationCostPerUnit;
public override void Update()
{
base.Update();

View File

@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bolas : Ally
{
public override void Start()
{
base.Start();
}
public override void Update()
{
base.Update();
if (IsEnemyDetected)
{
AttackEnemy();
}
}
void AttackEnemy()
{
//Attack Cooldown
if (AttackInterval < AttackSpeedWait)
{
Animation.PlayAttackAnim();
AttackSpeedWait = 0f;
}
AttackSpeedWait += Time.deltaTime;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 20821ed53f7f53e4cbdc7b3157c35b97
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -23,6 +23,10 @@ public abstract class Entity : LevelObject
private Shader _shaderSpritesDefault;
private SpriteRenderer[] _spriteRenderers;
private AudioPlayerComponent _audioPlayerComponent;
private StatusHandler _statusHandler;
// status modifiers
private float _speedStatusModifier = 1;
//Enemy Spotted
private bool _isEnemyDetected = false;
@ -36,11 +40,12 @@ public abstract class Entity : LevelObject
_spriteRenderers = GetComponentsInChildren<SpriteRenderer>(true);
_audioPlayerComponent = GetComponent<AudioPlayerComponent>();
Animation = gameObject.AddComponent<AnimationEntity>();
_statusHandler = gameObject.AddComponent<StatusHandler>();
}
public virtual void Update()
{
Animation.AttackSpeedMultiplier = AttackSpeedMultiplier;
Animation.SpeedMultiplier = SpeedMultiplier;
Animation.SpeedMultiplier = SpeedMultiplier * SpeedStatusModifier;
_lifeBar.gameObject.SetActive(_lifeBar.value <= 0.99f);
}
@ -121,7 +126,7 @@ public abstract class Entity : LevelObject
public int Hp => (int)(_hp * HpMultiplier);
public float Speed => _speed * SpeedMultiplier;
public float Speed => _speed * SpeedMultiplier * SpeedStatusModifier;
public int AttackDamage
{
@ -157,6 +162,11 @@ public abstract class Entity : LevelObject
public SpriteRenderer[] SpriteRenderers { get { return _spriteRenderers; } }
public StatusHandler StatusHandler {
get => _statusHandler;
}
public float SpeedStatusModifier { get => _speedStatusModifier; set => _speedStatusModifier = value; }
#region [LevelManager code]
public override bool Equals(ILevelObject other)
{

View File

@ -13,4 +13,9 @@ public class Enum
Farm = 2,
BerryBush = 3
}
public enum StatusType
{
Slow = 0,
SpeedBoost = 1,
}
}

View File

@ -53,7 +53,7 @@ public class Projectile : MonoBehaviour
_initialYDistance = Mathf.Abs(_initialY - _destinationY);
}
private void Update()
protected virtual void Update()
{
if (straightProjectile)
{
@ -70,6 +70,7 @@ public class Projectile : MonoBehaviour
if (transform.position.x >= _vectorEnd.x)
{
ApplyEffects();
Destroy(this.gameObject);
}
return;
@ -87,12 +88,13 @@ public class Projectile : MonoBehaviour
_speedTime += _speed * Time.deltaTime;
if(y < 0) {
if (y < 0)
{
Destroy(this.gameObject);
}
}
private void DetStraigthArrowAngle()
protected virtual void DetStraigthArrowAngle()
{
if (_target != null) _enemyPosY = _target.Position.y;
@ -121,7 +123,8 @@ public class Projectile : MonoBehaviour
//Calcul utilise pour tenter de mieux faire fonctionner l'angle de la fleche lorsque l'ennemi est
//proche de l'unite.
else {
else
{
lerpStepS = -Mathf.Rad2Deg * Mathf.Atan(angleY / angleX);
}
@ -131,6 +134,8 @@ public class Projectile : MonoBehaviour
}
}
protected virtual void ApplyEffects() { }
//Getter and Setter
public float EnemySpeed
{

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 796c5970b01ebd249b04e1a0598abc7c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BolasProjectile : Projectile
{
[SerializeField]
private float _slowIntensity = 0.25f;
private float _slowDuration = 5f;
protected override void ApplyEffects()
{
if (Target.StatusHandler)
{
Target.StatusHandler.ApplySlow(_slowIntensity, _slowDuration);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: af32629f84318134799756134098abf9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -42,7 +42,6 @@ public class Root : MonoBehaviour
_newArrow.GetComponent<Projectile>().VectorStart = _rigidbodyAlly.position;
_newArrow.GetComponent<Projectile>().VectorEnd = _rigidbodyOpponent.position;
_newArrow.GetComponent<Projectile>().Target = _entity.Enemy;
}
public void PlaySound(string soundName)

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 53425a7650ca89b438da0796d0bd79ed
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Slow : Status
{
private float _speedModifier;
public override void Apply(float duration)
{
_duration += duration;
EntityLinked.SpeedStatusModifier *= _speedModifier;
}
public override void Unapply()
{
EntityLinked.SpeedStatusModifier /= _speedModifier;
Destroy(this);
}
/// <summary>
/// A higher intensity results in a stronger slow.
/// Example: An intensity of 0.99 multiplies the entity's speed by 0.01 (which would result in a really low speed)
/// </summary>
public float Intensity {
get => 1 - _speedModifier;
set => _speedModifier = _speedModifier == 0 ? 1 - value : _speedModifier + (1 - _speedModifier) * value;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b89154fc4d657474e988151a13f82fc5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Status : MonoBehaviour
{
private Entity entityLinked;
protected float _duration;
protected virtual void Start()
{
EntityLinked = GetComponent<Entity>();
}
protected virtual void Update()
{
_duration -= Time.deltaTime;
if ( _duration < 0 ) Unapply();
}
public abstract void Apply(float duration);
public abstract void Unapply();
public Entity EntityLinked { get => entityLinked; set => entityLinked = value; }
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8cd371169b5f23347994997e816d1d0f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StatusHandler : MonoBehaviour
{
private Entity _entityLinked;
private Dictionary<Enum.StatusType, Status> activeStatuses = new();
public void ApplySlow(float intensity, float duration)
{
Slow slow = (Slow)GetStatus(Enum.StatusType.Slow);
slow.Intensity = intensity;
slow.Apply(duration);
}
// please add status to switch case everytime you design one!
private Status GetStatus(Enum.StatusType type)
{
Status status;
activeStatuses.TryGetValue(Enum.StatusType.Slow, out status);
if (!status)
{
switch (type)
{
case Enum.StatusType.Slow:
status = gameObject.AddComponent<Slow>();
break;
default: break;
}
}
status.EntityLinked = _entityLinked;
return status;
}
private void Start()
{
_entityLinked = gameObject.GetComponent<Entity>(); ;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e1a590a40aadfa24ab3c0d725467255f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: