added sound script and menu
This commit is contained in:
@@ -5,4 +5,6 @@ public interface IInputReader
|
||||
Vector2 dragInput{get;}
|
||||
float clickInput { get;}
|
||||
bool isclicked { get;}
|
||||
|
||||
bool isBlocked { get; set; }
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using UnityEngine.InputSystem;
|
||||
public class InputReader : ScriptableObject, IInputReader, GameInput.IPlayerActions
|
||||
{
|
||||
public Action<Vector2> OnDragValueChanged;
|
||||
public bool isBlocked { get; set;}
|
||||
|
||||
public Vector2 _dragInput;
|
||||
public Vector2 dragInput
|
||||
@@ -32,7 +33,7 @@ public class InputReader : ScriptableObject, IInputReader, GameInput.IPlayerActi
|
||||
inputActions = new GameInput();
|
||||
inputActions.Player.SetCallbacks(this);
|
||||
}
|
||||
|
||||
isBlocked = false;
|
||||
inputActions.Enable();
|
||||
}
|
||||
|
||||
@@ -42,12 +43,13 @@ public class InputReader : ScriptableObject, IInputReader, GameInput.IPlayerActi
|
||||
}
|
||||
|
||||
public void OnDrag(InputAction.CallbackContext context)
|
||||
{
|
||||
{ if (isBlocked) { Debug.Log("InputBlocked"); return; }
|
||||
dragInput = context.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
public void OnClick(InputAction.CallbackContext context)
|
||||
{
|
||||
if(isBlocked) return;
|
||||
clickInput = context.ReadValue<float>();
|
||||
isclicked = clickInput == 1? true : false;
|
||||
Debug.Log(isclicked);
|
||||
|
||||
@@ -8,6 +8,8 @@ public class GameLifeTimeScope : LifetimeScope
|
||||
[SerializeField] private InputReader _inputReader;
|
||||
[SerializeField] private DeathScreenView deathview;
|
||||
[SerializeField] private StartScreenView startView;
|
||||
[SerializeField] private GameScreenView gameScreenView;
|
||||
[SerializeField] private PauseScreenView pauseScreenView;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -19,10 +21,14 @@ public class GameLifeTimeScope : LifetimeScope
|
||||
builder.RegisterComponentInHierarchy<PlatformPool>();
|
||||
builder.RegisterComponentInHierarchy<Player>();
|
||||
builder.RegisterComponentInHierarchy<PlatformManager>();
|
||||
builder.RegisterComponentInHierarchy<AudioController>();
|
||||
builder.RegisterInstance(_inputReader).As<IInputReader>();
|
||||
|
||||
builder.Register<ScoreService>(Lifetime.Singleton);
|
||||
builder.Register<DeathScreenController>(Lifetime.Singleton).WithParameter(deathview);
|
||||
builder.Register<StartScreenController>(Lifetime.Singleton).WithParameter(startView);
|
||||
builder.Register<GameScreenController>(Lifetime.Singleton).WithParameter(gameScreenView);
|
||||
builder.Register<PauseScreenController>(Lifetime.Singleton).WithParameter(pauseScreenView);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
public class JumpingBall : MonoBehaviour
|
||||
{
|
||||
public float jumpforce = 4f;
|
||||
public Rigidbody BallRb;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(BallRb==null)
|
||||
{
|
||||
BallRb = GetComponent<Rigidbody>();
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if(collision.collider.CompareTag("Platform"))
|
||||
{
|
||||
BallRb.linearVelocity = new Vector3(0, jumpforce, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 747f7dce18fb6a548bafaf8388f331e4
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
@@ -7,12 +8,15 @@ public class Player : MonoBehaviour, IPlayer
|
||||
public Rigidbody BallRb;
|
||||
public bool isDead { get; private set; }
|
||||
|
||||
public GameObject splashObject;
|
||||
|
||||
[Inject] ScoreService scoreService;
|
||||
[Inject] InputReader inputReader;
|
||||
[Inject] DeathScreenController deathScreenController;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
if (BallRb == null)
|
||||
{
|
||||
BallRb = GetComponent<Rigidbody>();
|
||||
@@ -23,7 +27,11 @@ public class Player : MonoBehaviour, IPlayer
|
||||
{
|
||||
if (collision.collider.CompareTag("Platform") && !isDead)
|
||||
{
|
||||
ContactPoint contact = collision.contacts[0];
|
||||
Vector3 contactOffset = new Vector3(0, 0.1f, 0);
|
||||
GameObject currentSplash = Instantiate(splashObject, contact.point+contactOffset,splashObject.transform.rotation);
|
||||
BallRb.linearVelocity = new Vector3(0, jumpforce, 0);
|
||||
Destroy(currentSplash,0.2f);
|
||||
}
|
||||
else if (collision.collider.CompareTag("Death"))
|
||||
{
|
||||
@@ -35,7 +43,15 @@ public class Player : MonoBehaviour, IPlayer
|
||||
{
|
||||
Debug.Log("Player is Dead");
|
||||
isDead = true;
|
||||
deathScreenController.ShowDeathScreen(scoreService.score,scoreService.GetHighscore());
|
||||
StartCoroutine(DieRoutine());
|
||||
}
|
||||
|
||||
IEnumerator DieRoutine()
|
||||
{
|
||||
inputReader.isBlocked = true;
|
||||
yield return new WaitForSeconds(1f);
|
||||
Time.timeScale = 0;
|
||||
deathScreenController.ShowDeathScreen(scoreService.score, scoreService.GetHighscore());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
using System;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
public class ScoreService
|
||||
{
|
||||
public Action<int> onScoreUpdate;
|
||||
|
||||
public int score { get; private set; }
|
||||
public int HighScore = PlayerPrefs.GetInt("HighScore", 0);
|
||||
[Inject] GameScreenController gameScreenController;
|
||||
[Inject] StartScreenController startScreenController;
|
||||
|
||||
public void AddScore()
|
||||
{
|
||||
if (!startScreenController.hasGameStarted) return;
|
||||
score += 5;
|
||||
onScoreUpdate?.Invoke(score);
|
||||
gameScreenController.UpdateScore(score);
|
||||
if(score>HighScore)
|
||||
{
|
||||
SetHighScore();
|
||||
|
||||
22
Assets/Scripts/UI/AudioController.cs
Normal file
22
Assets/Scripts/UI/AudioController.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AudioController:MonoBehaviour
|
||||
{
|
||||
public AudioSource SFXSource;
|
||||
public AudioSource MusicSource;
|
||||
|
||||
//public AudioClip backgroundclip;
|
||||
// public AudioClip deadClip;
|
||||
//public AudioClip jumpClip;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
///MusicSource.clip = backgroundclip;
|
||||
// MusicSource.Play();
|
||||
}
|
||||
|
||||
public void PlaySFX(AudioClip clip)
|
||||
{
|
||||
SFXSource.PlayOneShot(clip);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/AudioController.cs.meta
Normal file
2
Assets/Scripts/UI/AudioController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e85ac425eb34fa41af76223e92aec68
|
||||
8
Assets/Scripts/UI/AudioVIew.cs
Normal file
8
Assets/Scripts/UI/AudioVIew.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AudioVIew : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
2
Assets/Scripts/UI/AudioVIew.cs.meta
Normal file
2
Assets/Scripts/UI/AudioVIew.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63a465db551023e4899a8803730af5a0
|
||||
@@ -8,6 +8,8 @@ public class DeathScreenController
|
||||
private DeathScreenView _view;
|
||||
|
||||
[Inject] private StartScreenController startScreenController;
|
||||
[Inject] private GameScreenController gameScreenController;
|
||||
[Inject] private InputReader _inputReader;
|
||||
public DeathScreenController(DeathScreenView view)
|
||||
{
|
||||
_view = view;
|
||||
@@ -22,18 +24,26 @@ public class DeathScreenController
|
||||
private void OnReplayBtnClicked()
|
||||
{
|
||||
HideDeathScreen();
|
||||
Time.timeScale = 1;
|
||||
_inputReader.isBlocked = false;
|
||||
SceneManager.LoadScene(0);
|
||||
|
||||
Debug.Log("Game Replayed");
|
||||
}
|
||||
|
||||
private void OnBackBtnClicked()
|
||||
{
|
||||
HideDeathScreen();
|
||||
Time.timeScale = 1;
|
||||
_inputReader.isBlocked = false;
|
||||
|
||||
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
|
||||
public void ShowDeathScreen(int score, int highscore)
|
||||
{
|
||||
gameScreenController.HideGameScreen();
|
||||
_view.Show(score,highscore);
|
||||
}
|
||||
}
|
||||
|
||||
38
Assets/Scripts/UI/GameScreenController.cs
Normal file
38
Assets/Scripts/UI/GameScreenController.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SocialPlatforms.Impl;
|
||||
using VContainer;
|
||||
|
||||
public class GameScreenController
|
||||
{
|
||||
private GameScreenView gameScreenView;
|
||||
[Inject] private PauseScreenController pauseScreenController;
|
||||
|
||||
public GameScreenController (GameScreenView gameScreenView)
|
||||
{
|
||||
this.gameScreenView = gameScreenView;
|
||||
this.gameScreenView.pauseBtn.onClick.AddListener(PauseBtnClicked);
|
||||
}
|
||||
|
||||
public void ShowGameScreen()
|
||||
{
|
||||
gameScreenView.Show();
|
||||
}
|
||||
public void HideGameScreen()
|
||||
{
|
||||
gameScreenView.Hide();
|
||||
}
|
||||
|
||||
private void PauseBtnClicked()
|
||||
{
|
||||
Time.timeScale = 0;
|
||||
pauseScreenController.ShowPauseScreen();
|
||||
}
|
||||
|
||||
public void UpdateScore(int score)
|
||||
{
|
||||
gameScreenView.SetScore(score);
|
||||
}
|
||||
|
||||
}
|
||||
2
Assets/Scripts/UI/GameScreenController.cs.meta
Normal file
2
Assets/Scripts/UI/GameScreenController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e9850b4745033047ad9293264a28101
|
||||
33
Assets/Scripts/UI/GameScreenView.cs
Normal file
33
Assets/Scripts/UI/GameScreenView.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using VContainer;
|
||||
|
||||
public class GameScreenView : MonoBehaviour
|
||||
{
|
||||
public GameObject gameScreen;
|
||||
public TextMeshProUGUI ScoreText;
|
||||
public Button pauseBtn;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
ScoreText.text = "0";
|
||||
gameScreen.SetActive(false);
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
gameScreen.SetActive(true);
|
||||
}
|
||||
public void Hide()
|
||||
{
|
||||
gameScreen.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
public void SetScore(int score)
|
||||
{
|
||||
ScoreText.text = score.ToString();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/GameScreenView.cs.meta
Normal file
2
Assets/Scripts/UI/GameScreenView.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dca5ef66eb1c58a419af8a5c2b4b3886
|
||||
38
Assets/Scripts/UI/PauseScreenController.cs
Normal file
38
Assets/Scripts/UI/PauseScreenController.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
using VContainer;
|
||||
|
||||
public class PauseScreenController
|
||||
{
|
||||
private PauseScreenView _pauseScreenView;
|
||||
[Inject]private InputReader _inputReader;
|
||||
public PauseScreenController(PauseScreenView pauseScreenView)
|
||||
{
|
||||
this._pauseScreenView = pauseScreenView;
|
||||
_pauseScreenView.resumeBtn.onClick.AddListener( ResumeBtnClicked);
|
||||
_pauseScreenView.BackBtn.onClick.AddListener(BackBtnClicked);
|
||||
}
|
||||
|
||||
public void ShowPauseScreen()
|
||||
{
|
||||
_inputReader.isBlocked = true;
|
||||
_pauseScreenView.Show();
|
||||
}
|
||||
|
||||
private void ResumeBtnClicked()
|
||||
{
|
||||
_inputReader.isBlocked = false;
|
||||
|
||||
Time.timeScale = 1.0f;
|
||||
_pauseScreenView.Hide();
|
||||
}
|
||||
public void BackBtnClicked()
|
||||
{
|
||||
_inputReader.isBlocked = false;
|
||||
_pauseScreenView.Hide();
|
||||
Time.timeScale = 1.0f;
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/PauseScreenController.cs.meta
Normal file
2
Assets/Scripts/UI/PauseScreenController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e684a4de28d7cdc48994f59a24f98908
|
||||
24
Assets/Scripts/UI/PauseScreenView.cs
Normal file
24
Assets/Scripts/UI/PauseScreenView.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PauseScreenView : MonoBehaviour
|
||||
{
|
||||
public GameObject pauseScreen;
|
||||
public Button resumeBtn;
|
||||
public Button BackBtn;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
pauseScreen.SetActive(false);
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
pauseScreen.SetActive(true);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
pauseScreen.SetActive(false);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/PauseScreenView.cs.meta
Normal file
2
Assets/Scripts/UI/PauseScreenView.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00144c3e01b1f804cbf7b44181344295
|
||||
@@ -5,6 +5,7 @@ public class StartScreenController
|
||||
{
|
||||
private StartScreenView _view;
|
||||
public bool hasGameStarted = false;
|
||||
[Inject] GameScreenController gameScreenController;
|
||||
|
||||
public StartScreenController(StartScreenView view)
|
||||
{
|
||||
@@ -18,6 +19,7 @@ public class StartScreenController
|
||||
{
|
||||
_view.Hide();
|
||||
hasGameStarted = true;
|
||||
gameScreenController.ShowGameScreen();
|
||||
}
|
||||
|
||||
public void ShowStartScreen()
|
||||
|
||||
@@ -7,6 +7,11 @@ public class StartScreenView : MonoBehaviour
|
||||
public GameObject startScreen;
|
||||
public Button playBtn;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
startScreen.SetActive(true);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
startScreen.SetActive(false);
|
||||
|
||||
Reference in New Issue
Block a user