added gamescreen UI and simple start menu
This commit is contained in:
@@ -22,6 +22,9 @@ namespace Darkmatter.App
|
||||
|
||||
[SerializeField] private AudioService audioService;
|
||||
|
||||
[Header("UI Settings")]
|
||||
[SerializeField] private GameScreenView gameScreenView;
|
||||
|
||||
|
||||
[Header("Factory parameters")]
|
||||
[SerializeField] private Transform playerTransform;
|
||||
@@ -58,7 +61,7 @@ namespace Darkmatter.App
|
||||
c.Resolve<IObjectResolver>()), // <-- inject resolver properly
|
||||
Lifetime.Scoped);
|
||||
|
||||
|
||||
builder.Register<GameScreenController>(Lifetime.Scoped).WithParameter(gameScreenView).As<IGameScreenController>();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,5 +8,6 @@ namespace Darkmatter.Core
|
||||
public void PlayMovementAnim(Vector2 velocity);
|
||||
public void PlayReloadAnim(IReloadableWeapon reloadableWeapon);
|
||||
void PlayShootAnim();
|
||||
void PlayDeadAnim();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Core
|
||||
{
|
||||
public interface IPlayerPawn
|
||||
public interface IPlayerPawn : IDamageable
|
||||
{
|
||||
bool isGrounded { get; }
|
||||
|
||||
|
||||
@@ -11,5 +11,8 @@ namespace Darkmatter.Core
|
||||
public Vector2 moveInput { get; }
|
||||
public Vector2 lookInput { get; }
|
||||
public bool isShooting { get; }
|
||||
|
||||
public void DisableInput();
|
||||
public void EnableInput();
|
||||
}
|
||||
}
|
||||
|
||||
8
Assets/Darkmatter/Code/Core/Contracts/UI.meta
Normal file
8
Assets/Darkmatter/Code/Core/Contracts/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb18939ec56040244812046623bfe046
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Core
|
||||
{
|
||||
public interface IGameScreenController
|
||||
{
|
||||
|
||||
void UpdateFireableBulletCount(int bulletCount);
|
||||
void UpdateRemainingZombiesCount(int zombiesCount);
|
||||
void UpdateTotalZombiesCount(int totalZombiesCount);
|
||||
void ShowGameOverText();
|
||||
void ShowPlayerHealth(int health);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6871718dd9c3244eac4e4eed90a289f
|
||||
@@ -13,6 +13,6 @@ MonoBehaviour:
|
||||
m_Name: EnemyConfigSO
|
||||
m_EditorClassIdentifier: CoreAssembly::Darkmatter.Core.EnemyConfigSO
|
||||
walkSpeed: 1
|
||||
chaseSpeed: 2
|
||||
visionRange: 40
|
||||
chaseSpeed: 4
|
||||
visionRange: 50
|
||||
attackRange: 3
|
||||
|
||||
@@ -71,5 +71,15 @@ namespace Darkmatter.Core
|
||||
OnReloadPerformed?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void DisableInput()
|
||||
{
|
||||
action.Player.Disable();
|
||||
}
|
||||
|
||||
public void EnableInput()
|
||||
{
|
||||
action.Player.Enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace Darkmatter.Domain
|
||||
private void HandleAttack()
|
||||
{
|
||||
Vector3 dir = (enemyPawn.PlayerTarget.position - enemyPawn.ReturnMyPos()).normalized;
|
||||
enemyPawn.GameObject.transform.rotation = Quaternion.LookRotation(dir);
|
||||
//rotate towards player and handle Attack here
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ namespace Darkmatter.Domain
|
||||
[Inject] public readonly IReloadableWeapon currentWeapon;
|
||||
[Inject] public readonly PlayerConfigSO playerConfig;
|
||||
[Inject] public readonly CameraConfigSO cameraConfig;
|
||||
[Inject] public readonly IAudioService audioService;
|
||||
[Inject] public readonly IAudioService audioService;
|
||||
[Inject] public readonly IGameScreenController gameScreenController;
|
||||
|
||||
private Vector3 moveDir;
|
||||
private float Yaw;
|
||||
@@ -59,11 +60,14 @@ namespace Darkmatter.Domain
|
||||
{
|
||||
audioService.PlaySFX(AudioId.Gun_Fire,0.1f);
|
||||
currentWeapon.Attack();
|
||||
gameScreenController.UpdateFireableBulletCount(currentWeapon.AmmoCount);
|
||||
}
|
||||
if (currentWeapon.AmmoCount == 0 && !currentWeapon.isReloading)
|
||||
{
|
||||
audioService.PlaySFX(AudioId.Gun_Reload, 0.1f);
|
||||
playerAnim.PlayReloadAnim(currentWeapon);
|
||||
gameScreenController.UpdateFireableBulletCount(40);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,9 +77,9 @@ namespace Darkmatter.Domain
|
||||
{
|
||||
audioService.PlaySFX(AudioId.Gun_Reload, 0.1f);
|
||||
playerAnim.PlayReloadAnim(currentWeapon);
|
||||
gameScreenController.UpdateFireableBulletCount(40);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Darkmatter.Presentation
|
||||
protected readonly int moveXhash = Animator.StringToHash("MoveX");
|
||||
protected readonly int moveYhash = Animator.StringToHash("MoveY");
|
||||
private readonly int reloadHash = Animator.StringToHash("Reload");
|
||||
private readonly int deadHash = Animator.StringToHash("Dead");
|
||||
public TwoBoneIKConstraint HandOnGunIK; //for gunHand Ik
|
||||
private Coroutine reloadCoroutine;
|
||||
|
||||
@@ -71,5 +72,10 @@ namespace Darkmatter.Presentation
|
||||
{
|
||||
Debug.Log("player Shoot");
|
||||
}
|
||||
|
||||
public void PlayDeadAnim()
|
||||
{
|
||||
animator.SetTrigger(deadHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Darkmatter.Presentation
|
||||
public class EnemiesSpawnner : MonoBehaviour
|
||||
{
|
||||
[Inject] IEnemyFactory _enemyFactory;
|
||||
[Inject] IGameScreenController gameScreenController;
|
||||
public int baseEnemyCount =2;
|
||||
private ObjectPool<IEnemyPawn> _enemyPool;
|
||||
|
||||
@@ -49,6 +50,8 @@ namespace Darkmatter.Presentation
|
||||
|
||||
private void SpawnWave(int multiplier)
|
||||
{
|
||||
gameScreenController.UpdateTotalZombiesCount(baseEnemyCount*multiplier);
|
||||
gameScreenController.UpdateRemainingZombiesCount(baseEnemyCount*multiplier);
|
||||
for (int i = 0; i < baseEnemyCount*multiplier; i++)
|
||||
{
|
||||
IEnemyPawn enemy = _enemyPool.Get();
|
||||
@@ -62,6 +65,7 @@ namespace Darkmatter.Presentation
|
||||
enemy.Reset();
|
||||
_enemyPool.Release(enemy);
|
||||
killedEnemies++;
|
||||
gameScreenController.UpdateRemainingZombiesCount(baseEnemyCount*enemiesMultiplier - killedEnemies);
|
||||
if(killedEnemies == baseEnemyCount*enemiesMultiplier)
|
||||
{
|
||||
killedEnemies = 0;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Darkmatter.Presentation
|
||||
if(isDead) return;
|
||||
isDead = true;
|
||||
enemyAI.enabled = false;
|
||||
Invoke(nameof(Hide), 8f);
|
||||
Invoke(nameof(Hide), 5f);
|
||||
}
|
||||
|
||||
private void Hide()
|
||||
|
||||
@@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
using UnityEngine.SceneManagement;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
@@ -21,6 +22,8 @@ namespace Darkmatter.Presentation
|
||||
private float verticalVelocity;
|
||||
public bool isGrounded => IsOnGround();
|
||||
|
||||
public float Health { get; set; } = 100;
|
||||
|
||||
[Header("GroundCheckSensorSetting")]
|
||||
public float groundOffset;
|
||||
public float groundCheckRadius;
|
||||
@@ -29,6 +32,13 @@ namespace Darkmatter.Presentation
|
||||
[Header("TurnSetting")]
|
||||
public float turnSpeed = 5f;
|
||||
[Inject] private PlayerConfigSO playerConfig;
|
||||
[Inject] private IPlayerAnim PlayerAnim;
|
||||
[Inject] private IGameScreenController gameScreenController;
|
||||
[Inject] private IInputReader inputReader;
|
||||
|
||||
public event Action<float> OnHealthDecreased;
|
||||
|
||||
private bool isDead=false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -81,6 +91,40 @@ namespace Darkmatter.Presentation
|
||||
Vector3 groundPos = transform.position + Vector3.down * groundOffset;
|
||||
Gizmos.DrawWireSphere(groundPos, groundCheckRadius);
|
||||
}
|
||||
float damageCooldown = 1f;
|
||||
float lastHitTime;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if(other.CompareTag("Enemy")&& !isDead)
|
||||
{
|
||||
TakeDamage(10);
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
Health-=damage;
|
||||
if(Health<=0)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
gameScreenController.ShowPlayerHealth((int)Health);
|
||||
}
|
||||
|
||||
public void Die()
|
||||
{
|
||||
isDead = true;
|
||||
PlayerAnim.PlayDeadAnim();
|
||||
inputReader.DisableInput();
|
||||
Invoke("GameOver", 4f);
|
||||
}
|
||||
|
||||
private void GameOver()
|
||||
{
|
||||
gameScreenController.ShowGameOverText();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
"GUID:23f9a018fbd2e1242a0525718cc761d6",
|
||||
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
|
||||
"GUID:4307f53044263cf4b835bd812fc161a4",
|
||||
"GUID:7f7d1af65c2641843945d409d28f2e20"
|
||||
"GUID:7f7d1af65c2641843945d409d28f2e20",
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using Darkmatter.Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class GameScreenController : IGameScreenController
|
||||
{
|
||||
GameScreenView gameScreenView;
|
||||
|
||||
public GameScreenController(GameScreenView gameScreenView)
|
||||
{
|
||||
this.gameScreenView = gameScreenView;
|
||||
}
|
||||
public void UpdateFireableBulletCount(int bulletCount)
|
||||
{
|
||||
gameScreenView.UpdateBulletText(bulletCount);
|
||||
}
|
||||
|
||||
public void UpdateRemainingZombiesCount(int zombiesCount)
|
||||
{
|
||||
gameScreenView.UpdateRemainingZombiesCountText(zombiesCount);
|
||||
}
|
||||
|
||||
public void UpdateTotalZombiesCount(int totalZombiesCount)
|
||||
{
|
||||
gameScreenView.UpdateTotalZombiesCount(totalZombiesCount);
|
||||
}
|
||||
|
||||
public void ShowGameOverText()
|
||||
{
|
||||
gameScreenView.ShowGameOver();
|
||||
|
||||
}
|
||||
|
||||
public void ShowPlayerHealth(int health)
|
||||
{
|
||||
gameScreenView.ShowPlayerHealth(health);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7143025033c7d9840a214fb5c4bfefb9
|
||||
45
Assets/Darkmatter/Code/Presentation/UI/GameScreenView.cs
Normal file
45
Assets/Darkmatter/Code/Presentation/UI/GameScreenView.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class GameScreenView : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI fireableBulletText;
|
||||
public TextMeshProUGUI remainingZombiesCountText;
|
||||
public TextMeshProUGUI totalZombiesCountText;
|
||||
public TextMeshProUGUI playerHealthText;
|
||||
public GameObject GameOverObject;
|
||||
|
||||
public void UpdateBulletText(int bulletCount)
|
||||
{
|
||||
fireableBulletText.text = bulletCount.ToString();
|
||||
}
|
||||
|
||||
public void UpdateRemainingZombiesCountText(int zombiesCount)
|
||||
{
|
||||
remainingZombiesCountText.text = zombiesCount.ToString();
|
||||
}
|
||||
|
||||
public void UpdateTotalZombiesCount(int totalZombies)
|
||||
{
|
||||
totalZombiesCountText.text = totalZombies.ToString();
|
||||
}
|
||||
public void ShowPlayerHealth(int health)
|
||||
{
|
||||
playerHealthText.text = health.ToString();
|
||||
}
|
||||
public void ShowGameOver()
|
||||
{
|
||||
GameOverObject.SetActive(true);
|
||||
Invoke("ChangeScene", 2f);
|
||||
}
|
||||
|
||||
void ChangeScene()
|
||||
{
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53b791085ea93e74eb91492d67fa02a6
|
||||
@@ -5,6 +5,10 @@ namespace Darkmatter.Presentation
|
||||
{
|
||||
public class MenuScreen : MonoBehaviour
|
||||
{
|
||||
private void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
public void OnPlayBtnClick()
|
||||
{
|
||||
SceneManager.LoadScene(1);
|
||||
|
||||
Reference in New Issue
Block a user