separate ally and enemy config + bugfixes

la config des ennemis influencait la config des alliés, ce qui était un bug maintenant, il y a une config différente pour les alliés et les ennemis.

l'animation d'attaque ne se terminait pas à temps pour faire le dégat, il a donc fallu multiplier la vitesse d'animation par le attack speed quand on attaque

j'en ai profité pour faire la même chose pour le walk animation et le speed

j'ai changé l'attribut des unités "attack speed" pour un "attack interval", pour que ça représente mieux son utilisation. Le multiplicateur reste sur la vitesse, et non sur l'interval.

Les configs pour les ressources sont les valeurs des ressources directement (pas des multiplicateurs)
This commit is contained in:
Felix Boucher 2023-08-30 14:57:01 -04:00
parent 0aa3327433
commit 0714036b57
18 changed files with 154 additions and 505 deletions

View File

@ -12,12 +12,19 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 32e788fd2a7bdaf4ab145b64231cb833, type: 3}
m_Name: GlobalConfig
m_EditorClassIdentifier:
enemyBaseDamage: 1
enemyBaseLife: 5
enemyBaseRange: 1
enemyBaseAttackSpeed: 1
damageFlashIntensity: 1
harvestDuration: 1
harvestAmount: 1
harvestRandomDurationMinimum: 0
harvestRandomDurationMaximum: 0
enemySpeedMultiplier: 1
enemyDamageMultiplier: 1
enemyLifeMultiplier: 1
enemyRangeMultiplier: {x: 1, y: 1}
enemyAttackSpeedMultiplier: 1
allyDamageMultiplier: 1
allyLifeMultiplier: 1
allyAttackSpeedMultiplier: 0.5
allySpeedMultiplier: 1
allyRangeMultiplier: {x: 1, y: 1}
harvestDuration: 5
harvestAmount: 10
useRandomHarvestDuration: 0
randomHarvestDurationMinimum: 0
randomHarvestDurationMaximum: 0

View File

@ -9,7 +9,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 80204295746100151}
- component: {fileID: 3889963999147056896}
- component: {fileID: 788547799086903831}
- component: {fileID: 8565800310011739221}
- component: {fileID: 313037212318601125}
@ -37,44 +36,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1839735485 &3889963999147056896
Tilemap:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 80204295746100150}
m_Enabled: 0
m_Tiles: {}
m_AnimatedTiles: {}
m_TileAssetArray: []
m_TileSpriteArray: []
m_TileMatrixArray: []
m_TileColorArray: []
m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Origin: {x: 0, y: 0, z: 0}
m_Size: {x: 0, y: 0, z: 1}
m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
m_TileOrientation: 0
m_TileOrientationMatrix:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
--- !u!50 &788547799086903831
Rigidbody2D:
serializedVersion: 4
@ -137,7 +98,7 @@ MonoBehaviour:
_hp: 20
_speed: 0.12
_attack_damage: 2
_attack_speed: 2
_attack_interval: 2
--- !u!1 &381864779947488822
GameObject:
m_ObjectHideFlags: 0

View File

@ -1,77 +1,5 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &270769315063318434
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 71124047072817123}
- component: {fileID: 2608989659328117942}
- component: {fileID: 3358069652062874313}
m_Layer: 0
m_Name: detection
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &71124047072817123
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 270769315063318434}
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: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &2608989659328117942
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 270769315063318434}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0.5, y: 0}
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.5, y: 0.5}
m_EdgeRadius: 0
--- !u!114 &3358069652062874313
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 270769315063318434}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 531d7966d86bd0c4d83baf58bcb56cd5, type: 3}
m_Name:
m_EditorClassIdentifier:
_entityLinked: {fileID: 0}
--- !u!1 &6962989255035248094
GameObject:
m_ObjectHideFlags: 0
@ -397,7 +325,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 6962989255644195631}
- component: {fileID: 6072713849781841816}
- component: {fileID: -1491803373025033585}
- component: {fileID: -7538281095464317747}
- component: {fileID: -7651792297317791922}
@ -422,48 +349,9 @@ Transform:
m_Children:
- {fileID: 6962989256011107500}
- {fileID: 6962989255883535387}
- {fileID: 71124047072817123}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1839735485 &6072713849781841816
Tilemap:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6962989255644195630}
m_Enabled: 0
m_Tiles: {}
m_AnimatedTiles: {}
m_TileAssetArray: []
m_TileSpriteArray: []
m_TileMatrixArray: []
m_TileColorArray: []
m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Origin: {x: 0, y: 0, z: 0}
m_Size: {x: 0, y: 0, z: 1}
m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
m_TileOrientation: 0
m_TileOrientationMatrix:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
--- !u!50 &-1491803373025033585
Rigidbody2D:
serializedVersion: 4
@ -526,7 +414,7 @@ MonoBehaviour:
_hp: 0
_speed: 0
_attack_damage: 0
_attack_speed: 0
_attack_interval: 0
_harvesterResourcePairs:
- _harvesterPrefab: {fileID: 5157279992115123224, guid: 85534a2d6c2add54d864073914646192, type: 3}
_resource: 2

View File

@ -1,77 +1,5 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &270769315063318434
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 71124047072817123}
- component: {fileID: 2608989659328117942}
- component: {fileID: 3358069652062874313}
m_Layer: 0
m_Name: detection
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &71124047072817123
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 270769315063318434}
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: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &2608989659328117942
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 270769315063318434}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0.5, y: 0}
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.5, y: 0.5}
m_EdgeRadius: 0
--- !u!114 &3358069652062874313
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 270769315063318434}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 531d7966d86bd0c4d83baf58bcb56cd5, type: 3}
m_Name:
m_EditorClassIdentifier:
_entityLinked: {fileID: 0}
--- !u!1 &6962989255035248094
GameObject:
m_ObjectHideFlags: 0
@ -397,7 +325,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 6962989255644195631}
- component: {fileID: 6072713849781841816}
- component: {fileID: -1491803373025033585}
- component: {fileID: -7538281095464317747}
- component: {fileID: 6812572548963698156}
@ -422,48 +349,9 @@ Transform:
m_Children:
- {fileID: 6962989256011107500}
- {fileID: 6962989255883535387}
- {fileID: 71124047072817123}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1839735485 &6072713849781841816
Tilemap:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6962989255644195630}
m_Enabled: 0
m_Tiles: {}
m_AnimatedTiles: {}
m_TileAssetArray: []
m_TileSpriteArray: []
m_TileMatrixArray: []
m_TileColorArray: []
m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Origin: {x: 0, y: 0, z: 0}
m_Size: {x: 0, y: 0, z: 1}
m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
m_TileOrientation: 0
m_TileOrientationMatrix:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
--- !u!50 &-1491803373025033585
Rigidbody2D:
serializedVersion: 4
@ -526,7 +414,7 @@ MonoBehaviour:
_hp: 0
_speed: 0
_attack_damage: 0
_attack_speed: 0
_attack_interval: 0
_harvesterResourcePairs:
- _harvesterPrefab: {fileID: 5157279992115123224, guid: 85534a2d6c2add54d864073914646192, type: 3}
_resource: 2

View File

@ -545,7 +545,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 5531237550998824025}
- component: {fileID: 8657602915366199534}
- component: {fileID: 5129435415547448825}
- component: {fileID: 4251894621246849979}
- component: {fileID: 9177659942431061517}
@ -574,44 +573,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1839735485 &8657602915366199534
Tilemap:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5531237550998824024}
m_Enabled: 0
m_Tiles: {}
m_AnimatedTiles: {}
m_TileAssetArray: []
m_TileSpriteArray: []
m_TileMatrixArray: []
m_TileColorArray: []
m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Origin: {x: 0, y: 0, z: 0}
m_Size: {x: 0, y: 0, z: 1}
m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
m_TileOrientation: 0
m_TileOrientationMatrix:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
--- !u!50 &5129435415547448825
Rigidbody2D:
serializedVersion: 4
@ -674,7 +635,7 @@ MonoBehaviour:
_hp: 10
_speed: 0
_attack_damage: 2
_attack_speed: 2
_attack_interval: 2
--- !u!1 &6125909153338481476
GameObject:
m_ObjectHideFlags: 0

View File

@ -398,7 +398,6 @@ GameObject:
m_Component:
- component: {fileID: 6962989255644195631}
- component: {fileID: 8585520847943034727}
- component: {fileID: 6072713849781841816}
- component: {fileID: -1491803373025033585}
- component: {fileID: -7538281095464317747}
m_Layer: 0
@ -440,46 +439,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
_hp: 100
_speed: 0
_attack_damage: 1
_attack_speed: 1.2
--- !u!1839735485 &6072713849781841816
Tilemap:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6962989255644195630}
m_Enabled: 0
m_Tiles: {}
m_AnimatedTiles: {}
m_TileAssetArray: []
m_TileSpriteArray: []
m_TileMatrixArray: []
m_TileColorArray: []
m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Origin: {x: 0, y: 0, z: 0}
m_Size: {x: 0, y: 0, z: 1}
m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
m_TileOrientation: 0
m_TileOrientationMatrix:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
_attack_damage: 0
_attack_interval: 0
--- !u!50 &-1491803373025033585
Rigidbody2D:
serializedVersion: 4

View File

@ -1063,7 +1063,6 @@ GameObject:
m_Component:
- component: {fileID: 6962989255644195631}
- component: {fileID: 8585520847943034727}
- component: {fileID: 6072713849781841816}
- component: {fileID: -1491803373025033585}
- component: {fileID: -7538281095464317747}
m_Layer: 0
@ -1106,45 +1105,7 @@ MonoBehaviour:
_hp: 10
_speed: 0
_attack_damage: 2
_attack_speed: 2
--- !u!1839735485 &6072713849781841816
Tilemap:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6962989255644195630}
m_Enabled: 0
m_Tiles: {}
m_AnimatedTiles: {}
m_TileAssetArray: []
m_TileSpriteArray: []
m_TileMatrixArray: []
m_TileColorArray: []
m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Origin: {x: 0, y: 0, z: 0}
m_Size: {x: 0, y: 0, z: 1}
m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
m_TileOrientation: 0
m_TileOrientationMatrix:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
_attack_interval: 2
--- !u!50 &-1491803373025033585
Rigidbody2D:
serializedVersion: 4

View File

@ -9,7 +9,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 6962989255644195631}
- component: {fileID: 6072713849781841816}
- component: {fileID: -1491803373025033585}
- component: {fileID: 8133954670424616578}
m_Layer: 0
@ -36,44 +35,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1839735485 &6072713849781841816
Tilemap:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6962989255644195630}
m_Enabled: 0
m_Tiles: {}
m_AnimatedTiles: {}
m_TileAssetArray: []
m_TileSpriteArray: []
m_TileMatrixArray: []
m_TileColorArray: []
m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Origin: {x: 0, y: 0, z: 0}
m_Size: {x: 0, y: 0, z: 1}
m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
m_TileOrientation: 0
m_TileOrientationMatrix:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
--- !u!50 &-1491803373025033585
Rigidbody2D:
serializedVersion: 4

View File

@ -4,14 +4,20 @@ using UnityEngine;
public class Ally : Entity
{
public override float DamageMultiplier => GlobalConfig.Instance.Current.allyDamageMultiplier;
public override float AttackSpeedMultiplier => GlobalConfig.Instance.Current.allyAttackSpeedMultiplier;
public override float HpMultiplier => GlobalConfig.Instance.Current.allyLifeMultiplier;
public override Vector2 RangeMultiplier => GlobalConfig.Instance.Current.allyRangeMultiplier;
public override float SpeedMultiplier => GlobalConfig.Instance.Current.allySpeedMultiplier;
public override void Start()
{
base.Start();
}
void Update()
public override void Update()
{
base.Update();
if(IsEnemyDetected) {
AttackEnemy();
}
@ -21,7 +27,7 @@ public class Ally : Entity
void AttackEnemy()
{
//Attack Cooldown
if (AttackSpeed < AttackSpeedWait)
if (AttackSpeedWait > AttackInterval)
{
Animation.PlayAttackAnim();

View File

@ -10,9 +10,9 @@ public class Archer : Ally
base.Start();
}
void Update()
public override void Update()
{
base.Update();
if(IsEnemyDetected) {
AttackEnemy();
}
@ -23,7 +23,7 @@ public class Archer : Ally
{
//Attack Cooldown
if(AttackSpeed < AttackSpeedWait) {
if(AttackInterval < AttackSpeedWait) {
Animation.PlayAttackAnim();

View File

@ -4,9 +4,20 @@ using static Enum;
public class Harvester : Entity
{
[SerializeField][Tooltip("helps choose the right skin for the harvester depending on resource")]
[SerializeField] [Tooltip("helps choose the right skin for the harvester depending on resource")]
private List<HarvesterResourcePair> _harvesterResourcePairs;
protected ResourceChoice ResourceChoice => _resourceChoice;
public override Vector2 RangeMultiplier { get; }
public override float HpMultiplier { get; }
public override float SpeedMultiplier { get; }
public override float DamageMultiplier { get; }
public override float AttackSpeedMultiplier { get; }
[SerializeField]
private ResourceChoice _resourceChoice;
public override sealed void Start()

View File

@ -4,6 +4,14 @@ using UnityEngine;
public class AnimationEntity : MonoBehaviour
{
enum EntityAnimationState
{
Idle = 0,
Walking = 1,
Attacking = 2,
Dying = 3
}
private EntityAnimationState entityState;
private Animator _animatorEntity;
private bool _doSomething = false;
@ -12,31 +20,47 @@ public class AnimationEntity : MonoBehaviour
void Start()
{
AttackSpeedMultiplier = 10;
SpeedMultiplier = 10;
_animatorEntity = GetComponentInChildren<Animator>();
}
void Update()
{
if (_doSomething && _animatorEntity.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f)
{
PlayIdleAnim();
_doSomething = false;
_isWalking = false;
}
_animatorEntity.speed = GetAnimatorSpeed();
}
private float GetAnimatorSpeed()
{
return entityState switch
{
EntityAnimationState.Attacking => AttackSpeedMultiplier,
EntityAnimationState.Walking => SpeedMultiplier,
_ => 1,
};
}
public void PlayIdleAnim()
{
if(!_isDead) {
_animatorEntity.speed = 1;
_animatorEntity.Play("idle", 0, 0f);
entityState = EntityAnimationState.Idle;
}
}
public void PlayWalkAnim()
{
if(!_isDead) {
_animatorEntity.speed = SpeedMultiplier;
_animatorEntity.Play("walk", 0, 0f);
entityState = EntityAnimationState.Walking;
_isWalking = true;
}
}
@ -44,14 +68,18 @@ public class AnimationEntity : MonoBehaviour
public void PlayAttackAnim()
{
if(!_isDead) {
_animatorEntity.speed = AttackSpeedMultiplier;
_animatorEntity.Play("attack", 0, 0f);
entityState = EntityAnimationState.Attacking;
_doSomething = true;
}
}
public void PlayDieAnim()
{
_animatorEntity.speed = 1;
_animatorEntity.Play("die", 0, 0f);
entityState = EntityAnimationState.Dying;
_doSomething = true;
_isDead = true;
}
@ -62,5 +90,12 @@ public class AnimationEntity : MonoBehaviour
get { return _isWalking; }
set { _isWalking = value; }
}
public float AttackSpeedMultiplier
{
get; set;
}
public float SpeedMultiplier
{
get; set;
}
}

View File

@ -24,17 +24,17 @@ public class Detection : MonoBehaviour
}
void ResizeCollider()
{
var range = GlobalConfig.Instance.Current.enemyBaseRange;
if (!EntityLinked) return;
var multiplier = EntityLinked.RangeMultiplier;
var size = _collider.size;
size.x = detectionRange.x * range.x;
size.y = detectionRange.y * range.y;
size.x = detectionRange.x * multiplier.x;
size.y = detectionRange.y * multiplier.y;
_collider.size = size;
var offset = _collider.offset;
if (offset == Vector2.zero) return;
offset.x = size.x / 2;
offset.x = Mathf.Sign(offset.x) * size.x / 2;
_collider.offset = offset;
}
//If it's a projectile damage > 0

View File

@ -2,7 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Entity : LevelObject
public abstract class Entity : LevelObject
{
//Attribut
[SerializeField]
@ -10,9 +10,9 @@ public class Entity : LevelObject
[SerializeField]
private float _speed;
[SerializeField]
private int _attack_damage;
private int _attack_damage = 2;
[SerializeField]
private float _attack_speed;
private float _attack_interval = 2;
private float _attack_speed_wait = 0f;
private AnimationEntity _animation;
private Shader _shaderGUItext;
@ -29,7 +29,11 @@ public class Entity : LevelObject
_spriteRenderers = GetComponentsInChildren<SpriteRenderer>();
Animation = gameObject.AddComponent<AnimationEntity>();
}
public virtual void Update()
{
Animation.AttackSpeedMultiplier = AttackSpeedMultiplier;
Animation.SpeedMultiplier = SpeedMultiplier;
}
//Start the animation of death and the fading of the entity
public void Death()
{
@ -89,13 +93,19 @@ public class Entity : LevelObject
//GETTERS AND SETTERS
public int Hp => (int)(_hp * GlobalConfig.Instance.Current.enemyBaseLife);
public abstract Vector2 RangeMultiplier { get; }
public abstract float HpMultiplier { get; }
public abstract float SpeedMultiplier { get; }
public abstract float DamageMultiplier { get; }
public abstract float AttackSpeedMultiplier { get; }
public float Speed => _speed;
public int Hp => (int)(_hp * HpMultiplier);
public int AttackDamage => (int)(_attack_damage * GlobalConfig.Instance.Current.enemyBaseDamage);
public float Speed => _speed * SpeedMultiplier;
public float AttackSpeed => _attack_speed * GlobalConfig.Instance.Current.enemyBaseAttackSpeed;
public int AttackDamage => (int)(_attack_damage * DamageMultiplier);
public float AttackInterval => _attack_interval / AttackSpeedMultiplier;
public float AttackSpeedWait
{
@ -128,19 +138,17 @@ public class Entity : LevelObject
&& base.Equals(otherEntity)
&& otherEntity._hp == _hp
&& otherEntity._speed == _speed
&& otherEntity._attack_speed == _attack_speed
&& otherEntity._attack_interval == _attack_interval
&& otherEntity._attack_damage == _attack_damage;
}
public override Dictionary<string, object> ToDictionary()
{
var dict = base.ToDictionary();
dict[nameof(_hp)] = _hp;
dict[nameof(_speed)] = _speed;
dict[nameof(_attack_speed)] = _attack_speed;
dict[nameof(_attack_interval)] = _attack_interval;
dict[nameof(_attack_damage)] = _attack_damage;
dict[nameof(_attack_speed_wait)] = _attack_speed_wait;
return dict;
}
@ -150,9 +158,8 @@ public class Entity : LevelObject
_hp = dict[nameof(_hp)].ToInt();
_speed = dict[nameof(_speed)].ToFloat();
_attack_speed = dict[nameof(_attack_speed)].ToFloat();
_attack_interval = dict[nameof(_attack_interval)].ToFloat();
_attack_damage = dict[nameof(_attack_damage)].ToInt();
_attack_speed_wait = dict[nameof(_attack_speed_wait)].ToFloat();
}
#endregion
}

View File

@ -2,25 +2,32 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = project_name + "/Global Config")]
public class GlobalConfigFile : ScriptableObject
{
public const string project_name = "Gather And Defend";
[Header("Enemies")]
public float enemyBaseDamage = 1;
public float enemyBaseLife = 1;
public Vector2 enemyBaseRange = Vector2.one;
public float enemyBaseAttackSpeed = 1;
public float damageFlashIntensity = 1;
[Header("Enemies")]
public float enemySpeedMultiplier = 1;
public float enemyDamageMultiplier = 1;
public float enemyLifeMultiplier = 1;
public Vector2 enemyRangeMultiplier = Vector2.one;
public float enemyAttackSpeedMultiplier = 1;
[Header("Allies")]
public float allyDamageMultiplier = 1;
public float allyLifeMultiplier = 1;
public float allyAttackSpeedMultiplier = 1;
public float allySpeedMultiplier = 1;
public Vector2 allyRangeMultiplier = Vector2.one;
[Header("resources")]
public float baseHarvestDuration = 1;
public float baseHarvestAmount = 1;
public float harvestDuration = 1;
public int harvestAmount = 1;
public bool useRandomHarvestDuration = false;
public float randomHarvestDurationMinimum = 0;
public float randomHarvestDurationMaximum = 0;
public int randomHarvestDurationMinimum = 0;
public int randomHarvestDurationMaximum = 0;
}

View File

@ -4,6 +4,11 @@ using UnityEngine;
public class Opponent : Entity
{
public override Vector2 RangeMultiplier => GlobalConfig.Instance.Current.enemyRangeMultiplier;
public override float DamageMultiplier => GlobalConfig.Instance.Current.enemyDamageMultiplier;
public override float AttackSpeedMultiplier => GlobalConfig.Instance.Current.enemyAttackSpeedMultiplier;
public override float HpMultiplier => GlobalConfig.Instance.Current.enemyLifeMultiplier;
public override float SpeedMultiplier => GlobalConfig.Instance.Current.enemySpeedMultiplier;
private Vector2 _movementVector = Vector2.zero;
private Rigidbody2D _rigidbody;
@ -16,11 +21,15 @@ public class Opponent : Entity
Animation = gameObject.AddComponent<AnimationEntity>();
}
void Update()
public override void Update()
{
base.Update();
if(IsEnemyDetected)
{
if(IsEnemyDetected) {
AttackEnemy();
}else {
}
else
{
_movementVector.x = -Time.deltaTime * Speed;
transform.position += (Vector3)_movementVector;
@ -36,7 +45,7 @@ public class Opponent : Entity
void AttackEnemy()
{
//Attack Cooldown
if(AttackSpeed < AttackSpeedWait)
if(AttackInterval < AttackSpeedWait)
{
Animation.PlayAttackAnim();

View File

@ -5,8 +5,6 @@ using UnityEngine;
/// </summary>
public class ResourceMaker : MonoBehaviour
{
[SerializeField]
private int _resourceMakingAmount;
[SerializeField]
private Enum.ResourceChoice _resourceChoice;
private ResourceManager _resourceManagerInstance;
@ -43,7 +41,7 @@ public class ResourceMaker : MonoBehaviour
if (_isPlaying)
{
var amountMult = GlobalConfig.Instance.Current.baseHarvestAmount;
var amount = GlobalConfig.Instance.Current.harvestAmount;
_timePassed += Time.deltaTime;
float duration = _timePassed / _desiredTime;
duration = duration * duration * (3.0f - 2.0f * duration);
@ -54,13 +52,13 @@ public class ResourceMaker : MonoBehaviour
switch (_resourceChoice)
{
case Enum.ResourceChoice.Rock:
_resourceManagerInstance.RockAmount = (int)(_resourceMakingAmount * amountMult);
_resourceManagerInstance.RockAmount = amount;
break;
case Enum.ResourceChoice.Wood:
_resourceManagerInstance.WoodAmount = (int)(_resourceMakingAmount * amountMult);
_resourceManagerInstance.WoodAmount = amount;
break;
case Enum.ResourceChoice.Food:
_resourceManagerInstance.FoodAmount = (int)(_resourceMakingAmount * amountMult);
_resourceManagerInstance.FoodAmount = amount;
break;
}
Destroy(gameObject);

View File

@ -12,19 +12,14 @@ public class ResourceTile : LevelTile
public GameObject YieldPrefab => _yieldPrefab;
private string YieldPrefabName => _yieldPrefab.name;
[SerializeField][Tooltip("mesure en seconde / ressource")]
private float _yieldDuration = 1; //resource per second
private float _realYieldDuration;
[SerializeField]
[Range(0.0f, 5.0f)]
private float _randomPositionConfig = 0.5f;
private float _yieldCounter = 0;
public bool Occupied { get; set; }
public override void LevelStart()
{
base.LevelStart();
_realYieldDuration = _yieldDuration;
ResetYieldDuration();
}
public override void LevelUpdate()
@ -33,8 +28,8 @@ public class ResourceTile : LevelTile
var hasFarmer = LevelManager.Instance.Get<Harvester>(x => x.Position.IsContainedIn(Position));
if (!hasFarmer) return;
_yieldCounter += Time.deltaTime;
if (_yieldCounter < _realYieldDuration) return;
_yieldCounter -= Time.deltaTime;
if (_yieldCounter > 0) return;
ResetYieldDuration();
@ -60,28 +55,24 @@ public class ResourceTile : LevelTile
{
float min = config.randomHarvestDurationMinimum,
max = config.randomHarvestDurationMaximum;
_realYieldDuration = _yieldDuration * Random.Range(min, max);
_yieldCounter = Random.Range(min, max);
}
else
{
_realYieldDuration = _yieldDuration * config.baseHarvestDuration;
_yieldCounter = config.harvestDuration;
}
}
public override bool Equals(ILevelObject other)
{
return other is ResourceTile otherRes
&& base.Equals(otherRes)
&& _yieldPrefab == otherRes._yieldPrefab
&& _yieldDuration == otherRes._yieldDuration
&& Occupied == otherRes.Occupied;
&& _yieldPrefab == otherRes._yieldPrefab;
}
public override Dictionary<string, object> ToDictionary()
{
var dict = base.ToDictionary();
dict[nameof(YieldPrefabName)] = YieldPrefabName;
dict[nameof(_yieldDuration)] = _yieldDuration;
dict[nameof(Occupied)] = Occupied;
return dict;
}
public override void LoadDictionary(Dictionary<string, object> dict)
@ -89,8 +80,5 @@ public class ResourceTile : LevelTile
base.LoadDictionary(dict);
var prefabName = dict[nameof(YieldPrefabName)].ToString();
_yieldPrefab = Database.Instance.Prefabs[prefabName];
_yieldDuration = dict[nameof(_yieldDuration)].ToFloat();
_yieldCounter = dict[nameof(_yieldCounter)].ToFloat();
Occupied = dict[nameof(Occupied)].ToBool();
}
}