feat: Roses spawn
This commit is contained in:
parent
ff2d68ed07
commit
f8a29f1501
206 changed files with 12637 additions and 19 deletions
|
@ -2,12 +2,27 @@
|
|||
public class Model {
|
||||
public int Score { private set; get; }
|
||||
|
||||
public Model(int score) {
|
||||
private readonly int _spawnRate;
|
||||
private bool _needsToSpawn;
|
||||
|
||||
public Model(int spawnRate) : this(0, spawnRate) { }
|
||||
|
||||
public Model(int score, int spawnRate) {
|
||||
Score = score;
|
||||
_spawnRate = spawnRate;
|
||||
}
|
||||
|
||||
public void AddScore(int score) {
|
||||
Score += score;
|
||||
public void AddScore() {
|
||||
Score++;
|
||||
if (Score % _spawnRate == 0)
|
||||
_needsToSpawn = true;
|
||||
}
|
||||
|
||||
public bool NeedsToSpawn() {
|
||||
bool needs = _needsToSpawn;
|
||||
_needsToSpawn = false;
|
||||
|
||||
return needs;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,15 +4,21 @@ namespace Presenter {
|
|||
public class ExpressionClick {
|
||||
private readonly Model _model;
|
||||
private readonly IExpressionInput _view;
|
||||
private readonly IRoseSpawner _spawner;
|
||||
|
||||
public ExpressionClick(Model model, IExpressionInput view) {
|
||||
public ExpressionClick(Model model, IExpressionInput view, IRoseSpawner spawner) {
|
||||
_model = model;
|
||||
_view = view;
|
||||
_spawner = spawner;
|
||||
}
|
||||
|
||||
public void Execute() {
|
||||
_model.AddScore(1);
|
||||
_model.AddScore();
|
||||
_view.UpdateView(_model.Score);
|
||||
|
||||
if (_model.NeedsToSpawn()) {
|
||||
_spawner.SpawnRose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
5
Assets/Scripts/Presenter/IRoseSpawner.cs
Normal file
5
Assets/Scripts/Presenter/IRoseSpawner.cs
Normal file
|
@ -0,0 +1,5 @@
|
|||
namespace Presenter {
|
||||
public interface IRoseSpawner {
|
||||
void SpawnRose();
|
||||
}
|
||||
}
|
3
Assets/Scripts/Presenter/IRoseSpawner.cs.meta
Normal file
3
Assets/Scripts/Presenter/IRoseSpawner.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 24fa8325e763470c8e412f76eeb46b59
|
||||
timeCreated: 1713197911
|
|
@ -11,13 +11,15 @@ namespace View {
|
|||
public CustomInput CustomInput { private set; get; }
|
||||
|
||||
private void Awake() {
|
||||
Model = new Model(0);
|
||||
Model = new Model(20);
|
||||
|
||||
IExpressionInput input = FindObjectOfType<ExpressionInput>();
|
||||
IExpressionInput visibility = FindObjectOfType<UIVisibility>();
|
||||
IExpressionInput inputCollections = new ExpressionInputCollection(new[] { input, visibility });
|
||||
|
||||
ExpressionClick = new ExpressionClick(Model, inputCollections);
|
||||
IRoseSpawner spawner = FindObjectOfType<RoseSpawner>();
|
||||
|
||||
ExpressionClick = new ExpressionClick(Model, inputCollections, spawner);
|
||||
|
||||
CustomInput = new CustomInput();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
using System;
|
||||
using Presenter;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace View {
|
||||
public class RoseSpawner : MonoBehaviour {
|
||||
public class RoseSpawner : MonoBehaviour, IRoseSpawner {
|
||||
[SerializeField] private Rect spawnerRegion;
|
||||
[SerializeField] private GameObject rose;
|
||||
|
||||
public void SpawnRose() {
|
||||
Vector2 spawnPos = new(
|
||||
spawnerRegion.position.x + Random.Range(-spawnerRegion.size.x / 2f, spawnerRegion.size.x / 2f),
|
||||
spawnerRegion.position.y + Random.Range(-spawnerRegion.size.y / 2f, spawnerRegion.size.y / 2f)
|
||||
);
|
||||
|
||||
Instantiate(rose, spawnPos, Quaternion.identity);
|
||||
}
|
||||
|
||||
private void OnDrawGizmos() {
|
||||
Gizmos.DrawWireCube(spawnerRegion.position, spawnerRegion.size);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue