Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 0787478
Author: Vlad Lavrishko <[email protected]>
Date:   Sun Oct 29 22:53:47 2023 +0200

    Add music

commit 514f278
Author: Vlad Lavrishko <[email protected]>
Date:   Sun Oct 29 22:33:51 2023 +0200

    Add sort

commit 8379a7a
Author: Vlad Lavrishko <[email protected]>
Date:   Sun Oct 29 22:25:07 2023 +0200

    hotfix

commit 305ebdb
Author: Vlad Lavrishko <[email protected]>
Date:   Sun Oct 29 22:21:52 2023 +0200

    Add slider for brake
  • Loading branch information
seTc1 committed Oct 29, 2023
1 parent 3c37f85 commit 86152f6
Show file tree
Hide file tree
Showing 36 changed files with 326 additions and 273 deletions.
31 changes: 5 additions & 26 deletions .idea/.idea.HalloweenGameJam2023/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using CodeBase.Services.GameLoopService;
using CodeBase.Services.GameScoreService;
using CodeBase.Services.Input;
using CodeBase.Services.InteractiveObject;
using CodeBase.Services.PersistentProgress;
using CodeBase.Services.StaticData;
using CodeBase.Services.StaticData.Interactive;
Expand All @@ -30,17 +31,19 @@ public class GameFactory : IGameFactory
private readonly IGameScoreService _gameScoreService;
private readonly IDisplayInputService _displayInputService;
private readonly IGameTimer _gameTimer;
private readonly IInteractive _interactive;
private GameObject _hero;

public GameFactory(IAssetProvider assets, IStaticDataService staticData, IInputService inputService,
IGameScoreService gameScoreService, IDisplayInputService displayInputService, IGameTimer gameTimer)
IGameScoreService gameScoreService, IDisplayInputService displayInputService, IGameTimer gameTimer, IInteractive interactive)
{
_assets = assets;
_staticData = staticData;
_inputService = inputService;
_gameScoreService = gameScoreService;
_displayInputService = displayInputService;
_gameTimer = gameTimer;
_interactive = interactive;
}

public void Cleanup()
Expand Down Expand Up @@ -102,7 +105,7 @@ public async Task<GameObject> CreateInteractiveObject(InteractiveID id, Transfor
GameObject prefab = await _assets.Load<GameObject>(interactiveStaticData.PrefabReference);
GameObject interactive = Object.Instantiate(prefab, parent.position, Quaternion.identity, parent);
interactive.GetComponent<BaseInteractiveObject>()
.Constructor(_inputService, _gameScoreService, _displayInputService);
.Constructor(_inputService, _gameScoreService, _displayInputService, _interactive);
return interactive;
}

Expand Down
9 changes: 7 additions & 2 deletions Assets/CodeBase/Infrastructure/States/BootstrapState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using CodeBase.UI.Services.Factory;
using CodeBase.UI.Services.Windows;
using CodeBase.Services.Input;
using CodeBase.Services.InteractiveObject;
using UnityEngine;

namespace CodeBase.Infrastructure.States
Expand Down Expand Up @@ -44,6 +45,8 @@ private void RegisterServices()
{
_services.RegisterSingle<IInputService>(
implementation: InputService());
_services.RegisterSingle<IInteractive>(
implementation: new Interactive());
_services.RegisterSingle<IDisplayInputService>(
implementation: new DisplayInputService());
_services.RegisterSingle<IRandomService>(
Expand All @@ -66,7 +69,8 @@ private void RegisterServices()
inputService: _services.Single<IInputService>(),
gameScoreService: _services.Single<IGameScoreService>(),
displayInputService: _services.Single<IDisplayInputService>(),
gameTimer: _services.Single<IGameTimer>()));
gameTimer: _services.Single<IGameTimer>(),
interactive: _services.Single<IInteractive>()));
_services.RegisterSingle<IAudioPlayer>(new AudioPlayer(
gameFactory: _services.Single<IGameFactory>(),
staticData: _services.Single<IStaticDataService>(),
Expand All @@ -81,7 +85,8 @@ private void RegisterServices()
inputService: _services.Single<IInputService>(),
displayInputService: _services.Single<IDisplayInputService>(),
gameTimer: _services.Single<IGameTimer>(),
audioPlayer: _services.Single<IAudioPlayer>()));
audioPlayer: _services.Single<IAudioPlayer>(),
interactive: _services.Single<IInteractive>()));
_services.RegisterSingle<IWindowService>(new WindowService(
uiFactory: _services.Single<IUIFactory>()));
_services.RegisterSingle<ISaveLoadService>(new SaveLoadService(
Expand Down
20 changes: 15 additions & 5 deletions Assets/CodeBase/InteractiveObjects/Base/BaseInteractiveObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using CodeBase.InteractiveObjects.Logic;
using CodeBase.Services.GameScoreService;
using CodeBase.Services.Input;
using CodeBase.Services.InteractiveObject;
using UnityEditor;
using UnityEngine;

namespace CodeBase.InteractiveObjects.Base
Expand All @@ -16,6 +18,7 @@ public abstract class BaseInteractiveObject : MonoBehaviour
[SerializeField] private Sprite _destroySprite;
[SerializeField] private int _costHappyScore;
[SerializeField] private float _waitToDestroy = 0.5f;
private IInteractive _interactive;
private IGameScoreService _gameScoreService;
private bool _isDestroy;
[HideInInspector] public HeroMove HeroMove;
Expand All @@ -27,10 +30,11 @@ private void OnDestroy() =>
OnDestroyAction();

public virtual void Constructor(IInputService inputService, IGameScoreService gameScoreService,
IDisplayInputService displayInputService)
IDisplayInputService displayInputService, IInteractive interactive)
{
_interactiveDetector.Constructor(inputService, displayInputService);
_gameScoreService = gameScoreService;
_interactive = interactive;
}

protected virtual void OnAwake() =>
Expand All @@ -43,9 +47,6 @@ protected virtual void ChangeToDestroySprite()
{
if (_isDestroy)
return;
_gameScoreService.MinusHappyScore(_costHappyScore);
_spriteRenderer.sprite = _destroySprite;
_isDestroy = true;
StartCoroutine(StopMoveHero());
}

Expand All @@ -54,7 +55,16 @@ private IEnumerator StopMoveHero()
if (HeroMove == null)
yield break;
HeroMove.StopMove();
yield return new WaitForSeconds(_waitToDestroy);
float waitCount = 0;
while (waitCount < _waitToDestroy)
{
waitCount++;
_interactive.EventActionBraking(waitCount < _waitToDestroy, waitCount, _waitToDestroy);
yield return null;
}
_gameScoreService.MinusHappyScore(_costHappyScore);
_spriteRenderer.sprite = _destroySprite;
_isDestroy = true;
HeroMove.enabled = true;
}
}
Expand Down
13 changes: 9 additions & 4 deletions Assets/CodeBase/NPC/NPCMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ private void SpeedCorrector(bool agro)
_currentSpeed = _defaultMovementSpeed;
}
}
private void Flip(Vector3 movementVector)
private void Flip(Vector3 targetPoint)
{
if (movementVector.x < transform.position.x)
_spriteFlip.localScale = _spriteFlip.localScale.WithToX(Mathf.Abs(_spriteFlip.localScale.x));
else
Vector3 toTarget = (targetPoint - transform.position).normalized;
Vector3 forward = transform.right;
float dotProduct = Vector3.Dot(forward, toTarget);

if (dotProduct < 0)
_spriteFlip.localScale = _spriteFlip.localScale.WithToX(-Mathf.Abs(_spriteFlip.localScale.x));
else
_spriteFlip.localScale = _spriteFlip.localScale.WithToX(Mathf.Abs(_spriteFlip.localScale.x));
}

public void ResetVelocity()
{
_rigidbody2D.velocity = Vector2.zero;
Expand Down
2 changes: 2 additions & 0 deletions Assets/CodeBase/NPC/NPCPoliceKill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class NPCPoliceKill : MonoBehaviour
{
[SerializeField] private NPCAgroZone _npcAgroZone;
[SerializeField] private NPCScore _npcScore;
[SerializeField] private NPCAnimator _npcAnimator;
[SerializeField] private int _touch = 3;
[SerializeField] private NPCMove _npcMove;
private int _currentTouch;
Expand Down Expand Up @@ -39,6 +40,7 @@ private void Update()
_isTouch = false;
_npcMove.ResetVelocity();
_npcMove.enabled = false;
_npcAnimator.SetIdle();
Sequence seq = DOTween.Sequence();
seq.Append(transform.DOScale(_defaultScale * 1.1f, 0.2f));
seq.Append(transform.DOScale(_defaultScale, 0.2f));
Expand Down
3 changes: 3 additions & 0 deletions Assets/CodeBase/Services/InteractiveObject.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Assets/CodeBase/Services/InteractiveObject/IInteractive.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace CodeBase.Services.InteractiveObject
{
public interface IInteractive : IService
{
public event Action<bool, float, float> OnBraking;
void EventActionBraking(bool active, float start, float end);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Assets/CodeBase/Services/InteractiveObject/Interactive.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace CodeBase.Services.InteractiveObject
{
public class Interactive : IInteractive
{
public void EventActionBraking(bool active, float start, float end) =>
OnBraking?.Invoke(active, start, end);
public event Action<bool, float, float> OnBraking;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion Assets/CodeBase/UI/Elements/ActorGameHud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using CodeBase.Services.GameLoopService;
using CodeBase.Services.GameScoreService;
using CodeBase.Services.Input;
using CodeBase.Services.InteractiveObject;
using CodeBase.Services.PersistentProgress;
using CodeBase.Services.StaticData;
using DG.Tweening;
using TMPro;
using UnityEngine;
Expand All @@ -14,6 +16,8 @@ namespace CodeBase.UI.Elements
public class ActorGameHud : MonoBehaviour
{
[SerializeField] private Slider _slider;
[SerializeField] private GameObject _brakingObj;
[SerializeField] private Slider _sliderBraking;
[SerializeField] private GameObject _pressF;
[SerializeField] private TextMeshProUGUI _pressEText;
[SerializeField][Multiline(2)] private string _activeEText;
Expand All @@ -24,30 +28,41 @@ public class ActorGameHud : MonoBehaviour
private IGameScoreService _gameScoreService;
private IDisplayInputService _displayInputService;
private IGameTimer _gameTimer;
private IInteractive _interactive;

private void OnDestroy()
{
_gameScoreService.ChangeHappyScore -= UpdateDisplayScore;
_displayInputService.PressF -= DisplayF;
_displayInputService.PressE -= DisplayE;
_gameTimer.OnUpdateTime -= UpdateTimeText;
_interactive.OnBraking -= UpdateSliderBraking;
}

public void Construct(IGameStateMachine stateMachine, IPersistentProgressService progressService,
IGameScoreService gameScoreService, IDisplayInputService displayInputService, IGameTimer gameTimer)
IGameScoreService gameScoreService, IDisplayInputService displayInputService, IGameTimer gameTimer,
IInteractive interactive)
{
_stateMachine = stateMachine;
_progressService = progressService;
_gameScoreService = gameScoreService;
_displayInputService = displayInputService;
_gameTimer = gameTimer;
_interactive = interactive;
_gameScoreService.ChangeHappyScore += UpdateDisplayScore;
_displayInputService.PressE += DisplayE;
_displayInputService.PressF += DisplayF;
_gameTimer.OnUpdateTime += UpdateTimeText;
_interactive.OnBraking += UpdateSliderBraking;
_slider.value = _gameScoreService.HappyScore;
}

private void UpdateSliderBraking(bool active, float start, float end)
{
_brakingObj.SetActive(active);
_sliderBraking.value = start / end;
}

private void UpdateTimeText(float time) =>
_timeText.text = time.ToString("0");

Expand Down
9 changes: 7 additions & 2 deletions Assets/CodeBase/UI/Services/Factory/UIFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using CodeBase.Services.GameLoopService;
using CodeBase.Services.GameScoreService;
using CodeBase.Services.Input;
using CodeBase.Services.InteractiveObject;
using CodeBase.Services.PersistentProgress;
using CodeBase.Services.StaticData;
using CodeBase.UI.Elements;
Expand Down Expand Up @@ -33,12 +34,13 @@ public class UIFactory : IUIFactory
private readonly IDisplayInputService _displayInputService;
private readonly IGameTimer _gameTimer;
private readonly IAudioPlayer _audioPlayer;
private readonly IInteractive _interactive;
private Transform _uiRoot;

public UIFactory(IGameStateMachine stateMachine, IAssetProvider assets, IStaticDataService staticData,
IPersistentProgressService progressService, IGameScoreService gameScoreService, IGameFactory gameFactory,
IInputService inputService, IDisplayInputService displayInputService, IGameTimer gameTimer,
IAudioPlayer audioPlayer)
IAudioPlayer audioPlayer, IInteractive interactive)
{
_stateMachine = stateMachine;
_assets = assets;
Expand All @@ -50,6 +52,7 @@ public UIFactory(IGameStateMachine stateMachine, IAssetProvider assets, IStaticD
_displayInputService = displayInputService;
_gameTimer = gameTimer;
_audioPlayer = audioPlayer;
_interactive = interactive;
}

public async Task CreateUIRoot()
Expand All @@ -63,6 +66,7 @@ public async Task CreateMenuUI()
GameObject menuUi = await _assets.Instantiate(MenuUIPath);
menuUi.GetComponent<ActorUIMenu>().Construct(_stateMachine, _progressService, _audioPlayer);
}

public async Task CreateGuideUI()
{
GameObject guideUI = await _assets.Instantiate(MenuGuideUI);
Expand All @@ -86,7 +90,8 @@ public async Task CreateGameHud()
{
GameObject hud = await _assets.Instantiate(GameHud);
hud.GetComponent<ActorGameHud>()
.Construct(_stateMachine, _progressService, _gameScoreService, _displayInputService, _gameTimer);
.Construct(_stateMachine, _progressService,
_gameScoreService, _displayInputService, _gameTimer, _interactive);
}

public async Task CreateAbilityUI()
Expand Down
Loading

0 comments on commit 86152f6

Please sign in to comment.