Skip to content

Commit

Permalink
Game Prototype V0.20.1 Bullet System
Browse files Browse the repository at this point in the history
- fix Bullet System
  • Loading branch information
Kong-TH committed Feb 6, 2024
1 parent 427f295 commit ddf2466
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 27 deletions.
6 changes: 3 additions & 3 deletions Assets/Resources/CheesePlayerMulti.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ MonoBehaviour:
m_triggerEnterEvent:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
- m_Target: {fileID: 6300914170578224804}
m_TargetAssemblyTypeName: GDD.PlayerSystem, Assembly-CSharp
m_MethodName: OnEnterSpinWheel
m_Mode: 0
Expand All @@ -253,7 +253,7 @@ MonoBehaviour:
m_triggerStayEvent:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
- m_Target: {fileID: 6300914170578224804}
m_TargetAssemblyTypeName: GDD.PlayerSystem, Assembly-CSharp
m_MethodName: OnDoorEnter
m_Mode: 0
Expand All @@ -268,7 +268,7 @@ MonoBehaviour:
m_triggerExitEvent:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
- m_Target: {fileID: 6300914170578224804}
m_TargetAssemblyTypeName: GDD.PlayerSystem, Assembly-CSharp
m_MethodName: OnDoorExit
m_Mode: 0
Expand Down
20 changes: 12 additions & 8 deletions Assets/Scripts/Systems/Bullet/BulletIgnition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@ public virtual void Update()

}

public virtual List<GameObject> OnSpawnBullet(float distance, float power, int shot, float damge, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null)
public virtual List<GameObject> OnSpawnBullet(float distance, float power, int shot, float damge, Transform target, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null)
{
if (shotMode == BulletShotMode.SurroundMode)
return OnIgnitionBulletSurround(builder,
m_spawnPoint,
target,
type,
distance,
power,
shot,
damge,
surroundMode);
else
return OnIgnitionBulletRandom(builder, m_spawnPoint, distance, power, shot, damge);
return OnIgnitionBulletRandom(builder, m_spawnPoint, target, distance, power, shot, damge);
}

public virtual void OnSpawnGrenade(int shot, float damge, int[] posIndex = default, ObjectPoolBuilder builder = null)
Expand All @@ -67,14 +68,14 @@ public virtual void OnSpawnGrenade(int shot, float damge, int[] posIndex = defau
OnProjectileLaunch(builder, m_spawnPoint, shot, damge, posIndex);
}

public List<GameObject> OnIgnitionBulletSurround(ObjectPoolBuilder builder, Transform spawnPoint, BulletType _type, float distance, float power, int shot, float damage, BulletShotSurroundMode surroundMode)
public List<GameObject> OnIgnitionBulletSurround(ObjectPoolBuilder builder, Transform spawnPoint, Transform target, BulletType _type, float distance, float power, int shot, float damage, BulletShotSurroundMode surroundMode)
{
int current_axis = 0;
int surrounded_axis;
float current_axis = 0;
float surrounded_axis;
int helf_axis = 0;
if (surroundMode == BulletShotSurroundMode.Surround)
{
surrounded_axis = 360 / shot;
surrounded_axis = 360.0f / shot;
}
else
{
Expand All @@ -84,6 +85,10 @@ public List<GameObject> OnIgnitionBulletSurround(ObjectPoolBuilder builder, Tran

bullets = new List<GameObject>();

//Aim to target
Quaternion lookAt = Quaternion.LookRotation(target.position - spawnPoint.position);
current_axis += lookAt.eulerAngles.y - transform.eulerAngles.y;

if(bullet_rot_spawn == null)
bullet_rot_spawn = new GameObject("bullet rot spawn");

Expand All @@ -103,7 +108,6 @@ public List<GameObject> OnIgnitionBulletSurround(ObjectPoolBuilder builder, Tran
else if (surroundMode == BulletShotSurroundMode.Back)
spawnPoint.rotation = transform.rotation * Quaternion.Euler(new Vector3(0, (helf_axis / 2) + 90, 0));


spawnPoint.rotation *= rot;

//Rot
Expand All @@ -123,7 +127,7 @@ public List<GameObject> OnIgnitionBulletSurround(ObjectPoolBuilder builder, Tran
return bullets;
}

public List<GameObject> OnIgnitionBulletRandom(ObjectPoolBuilder builder, Transform spawnPoint, float distance, float power, int shot, float damage)
public List<GameObject> OnIgnitionBulletRandom(ObjectPoolBuilder builder, Transform spawnPoint, Transform target, float distance, float power, int shot, float damage)
{
int current_axis = 0;
int surrounded_axis;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Systems/Bullet/Enemy/EnemySpawnBullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public override void Start()

}

public override List<GameObject> OnSpawnBullet(float distance, float power, int shot, float damage, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null)
public override List<GameObject> OnSpawnBullet(float distance, float power, int shot, float damage, Transform target, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null)
{
return base.OnSpawnBullet(distance, power, shot, damage, type, surroundMode, shotMode, _bulletObjectPool);
return base.OnSpawnBullet(distance, power, shot, damage, target, type, surroundMode, shotMode, _bulletObjectPool);
}

public override void OnSpawnGrenade(int shot, float damge, int[] posIndex = default, ObjectPoolBuilder builder = null)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Systems/Bullet/Player/PlayerSpawnBullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public override void Start()
_bulletObjectPool = gameObject.AddComponent<PlayerBulletObjectPool>();
}

public override List<GameObject> OnSpawnBullet(float distance, float power, int shot, float damage, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null)
public override List<GameObject> OnSpawnBullet(float distance, float power, int shot, float damage,Transform target, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null)
{
return base.OnSpawnBullet(distance, power, shot, damage, type, surroundMode, shotMode, _bulletObjectPool);
return base.OnSpawnBullet(distance, power, shot, damage, target, type, surroundMode, shotMode, _bulletObjectPool);
}

public override void OnSpawnGrenade(int shot, float damge, int[] posIndex = default, ObjectPoolBuilder builder = null)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Systems/Character/CharacterStateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CharacterStateMachine<T> : StateMachine<T>
protected PlayerSpawnBullet PlayerSpawnBullet;
protected bool _is_Start_Fire = false;
protected List<Coroutine> _coroutines = new List<Coroutine>();

protected virtual void OnEnable()
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void OnStart(EnemySystem contrller)
//Get New Target
GetNewTarget(contrller.SetTargetRandom());

ApplyEnemyStrategy();
ApplyEnemyStrategy(target);
}

protected void GetNewTarget(int targetID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public override void OnExit()
base.OnExit();
}

public void ApplyEnemyStrategy()
public void ApplyEnemyStrategy(Transform target)
{
strategy = GetComponent<EnemyManeuver>();
//print("Apply Enemy Strategy");
strategy.Maneuver(this);
strategy.Maneuver(this, this.target);
}

public void WithdrawEnemyStrategy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public override void Start()
base.Start();
}

public override void Maneuver(EnemyState pawn)
public override void Maneuver(EnemyState pawn, Transform target)
{
base.Maneuver(pawn);
base.Maneuver(pawn, target);

if (_player == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class EnemyManeuver : StrategyPattern<EnemyState>
protected PlayerSystem _player;
protected EnemySystem _enemySystem;
protected EnemyAttackState _enemyAttackState;
protected Transform _target;

protected virtual void Awake()
{
Expand All @@ -28,8 +29,10 @@ public virtual void Start()
_enemySystem = GetComponent<EnemySystem>();
}

public override void Maneuver(EnemyState pawn)
public override void Maneuver(EnemyState pawn, Transform target)
{
_target = target;

if(GM.players.Count <= 0)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public override void Start()
_punECC.OnProjectileReflectionLinesEnable(true);
}

public override void Maneuver(EnemyState pawn)
public override void Maneuver(EnemyState pawn, Transform target)
{
_punECC.OnProjectileReflectionLinesEnable(true);
OnShowProjectileReflectionLines();

base.Maneuver(pawn);
base.Maneuver(pawn, target);
}

public override void Truce()
Expand Down Expand Up @@ -64,6 +64,7 @@ public override void ToggleFire(EnemySpawnBullet enemySpawnBullet, int[] posInde
_enemyBulletConfig.bullet_power,
_enemyBulletConfig.shot,
_enemyBulletConfig.damage,
_target,
_enemyBulletConfig.bulletType,
BulletShotSurroundMode.Front,
BulletShotMode.SurroundMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public override void ToggleFire(EnemySpawnBullet enemySpawnBullet, int[] posInde
_enemyBulletConfig.bullet_power,
_enemyBulletConfig.shot,
_enemyBulletConfig.damage,
_target,
_enemyBulletConfig.bulletType,
BulletShotSurroundMode.Back,
BulletShotMode.RandomMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public override void ToggleFire(EnemySpawnBullet enemySpawnBullet, int[] posInde
_enemyBulletConfig.bullet_power,
_enemyBulletConfig.shot,
_enemyBulletConfig.damage,
_target,
_enemyBulletConfig.bulletType,
BulletShotSurroundMode.Surround,
BulletShotMode.SurroundMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public override void ToggleFire(EnemySpawnBullet enemySpawnBullet, int[] posInde
_enemyBulletConfig.bullet_power,
_enemyBulletConfig.shot,
_enemyBulletConfig.damage,
_target,
_enemyBulletConfig.bulletType,
BulletShotSurroundMode.Surround,
BulletShotMode.SurroundMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public override void ToggleFire(EnemySpawnBullet enemySpawnBullet, int[] posInde
_enemyBulletConfig.bullet_power,
_enemyBulletConfig.shot,
_enemyBulletConfig.damage,
_target,
_enemyBulletConfig.bulletType,
BulletShotSurroundMode.Front,
BulletShotMode.SurroundMode
Expand Down
4 changes: 4 additions & 0 deletions Assets/Scripts/Systems/Weapon/WeaponSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using GDD.Spatial_Partition;
using UnityEngine;
using UnityEngine.Serialization;

Expand Down Expand Up @@ -183,13 +184,16 @@ public void ToggleFire(PlayerSpawnBullet playerSpawnBullet)
if(_weapon == null)
return;

IPawn closestEnemy = GM.grid.FindClosestEnemy(_characterSystem);

playerSpawnBullet.bulletObjectPool.weapon = _weapon;
playerSpawnBullet.bulletObjectPool.Set_GameObject = _weapon.bulletObject;
playerSpawnBullet.OnSpawnBullet(
_weapon.bullet_spawn_distance,
_weapon.power,
_weapon.shot,
_weapon.damage,
closestEnemy.GetPawnTransform(),
BulletType.Rectilinear,
_weapon.surroundMode,
_weapon.bulletShotMode
Expand Down
6 changes: 4 additions & 2 deletions Assets/Scripts/Util/Strategy Pattern/IManeuverBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace GDD.StrategyPattern
using UnityEngine;

namespace GDD.StrategyPattern
{
public interface IManeuverBehaviour<T>
{
public abstract void Maneuver(T pawn);
public abstract void Maneuver(T pawn, Transform target);

public abstract void Truce();
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Util/Strategy Pattern/StrategyPattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public virtual void Start()
GM = GameManager.Instance;
}

public abstract void Maneuver(T pawn);
public abstract void Maneuver(T pawn, Transform target);

public abstract void Truce();
}
Expand Down

0 comments on commit ddf2466

Please sign in to comment.