Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Assets/Group1/10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions Assets/Scripts/Player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using UnityEngine;
using System.Collections;
using System.Linq;

public class Player : MonoBehaviour
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Слишком много ответственностей

{
[SerializeField] private Transform _enemiesContainer;
[SerializeField] private Transform _finishPanel;

public int EnemiesOnLevel { get; private set; }

public int KilledEnemys { get; private set; } = 0;
Comment on lines +10 to +12
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно обойтись одним состоянием: оставшиеся на уровне


private void Start ()
{
var enemies = _enemiesContainer.GetComponentsInChildren<Square>();
EnemiesOnLevel = enemies.Count();
}

private void OnTriggerEnter2D (Collider2D collision)
{
if (collision.GetComponent<Square>())
{
EnemiesOnLevel--;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возможно это тоже не его ответственность


if (EnemiesOnLevel == 0)
OnLevelPassed();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кинуть событие

}
}

private void OnLevelPassed ()
{
Time.timeScale = 0;
_finishPanel.gameObject.SetActive(true);
}
}
54 changes: 54 additions & 0 deletions Assets/Scripts/PlayerMover.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMover : MonoBehaviour
{
[SerializeField] private float _speed;

private float _boosterTime = 0;
private float _boosterForce = 0;
private float _defaultSpeed;

private void Start ()
{
_defaultSpeed = _speed;
}

private void OnTriggerEnter2D (Collider2D collision)
{
if (collision.TryGetComponent(out SquareBooster squareBooster))
{
_boosterForce = squareBooster.BoosterForce;
_boosterTime = squareBooster.BoosterTime;
Comment on lines +22 to +23
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В полях это хранить не надо, надо передать методу

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Прочитай про чистые функции


StartCoroutine(Booster());
}
}

private IEnumerator Booster ()
{
var waitForSeconds = new WaitForSeconds(_boosterTime);
ChangeSpeed(_speed + _boosterForce);

for (int i = 0; i < 1; i++)
{
yield return waitForSeconds;
}

ChangeSpeed(_defaultSpeed);
StopCoroutine(Booster());
}
Comment on lines +29 to +41
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

переделать


private void ChangeSpeed (float speed)
{
_speed = speed;
}
Comment on lines +43 to +46
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишняя функция


private void Update ()
{
Vector3 moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);

transform.Translate(moveDirection * _speed * Time.deltaTime);
}
}
35 changes: 35 additions & 0 deletions Assets/Scripts/Square.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Square : MonoBehaviour
{
[SerializeField] private float _speed = 2;
[SerializeField] private float _movementRadius = 4;

private Vector3 _target;

private void OnTriggerEnter2D (Collider2D collision)
{
if (collision.GetComponent<Player>())
gameObject.SetActive(false);
}

private void Start ()
{
CreateNewTarget();
}

private void Update ()
{
transform.position = Vector3.MoveTowards(transform.position, _target, _speed * Time.deltaTime);

if (transform.position == _target)
CreateNewTarget();
}

protected void CreateNewTarget ()
{
_target = Random.insideUnitCircle * _movementRadius;
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Square.cs.meta

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

13 changes: 13 additions & 0 deletions Assets/Scripts/SquareBooster.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SquareBooster : Square
{
[SerializeField] private float _boosterForce;
[SerializeField] private float _boosterTime;

public float BoosterForce => _boosterForce;
public float BoosterTime => _boosterTime;

}
11 changes: 11 additions & 0 deletions Assets/Scripts/SquareBooster.cs.meta

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