Gameplay-Edit

This commit is contained in:
2023-06-16 09:26:12 +03:00
commit 36f90ddd64
185 changed files with 30364 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Level;
using DG.Tweening;
namespace Objects
{
public class Crate : MonoBehaviour
{
public Vector2Int layoutPosition; // Index in layout
private void Start()
{
LevelBuilder.Instance.LevelDestroyed += Destroy;
}
private void OnDestroy()
{
LevelBuilder.Instance.LevelDestroyed -= Destroy;
}
public void Move(Vector2Int direction)
{
LayoutCell currentCell = LevelBuilder.Instance.GetCellAt(layoutPosition);
LayoutCell targetCell = LevelBuilder.Instance.GetCellAt(layoutPosition + direction);
if (targetCell != null && targetCell.IsFree)
{
// Free previous cell
currentCell.cellData.cellContent = LayoutCell.LayoutCellData.CellContent.None;
currentCell.crate = null;
// Occupy new cell
targetCell.cellData.cellContent = LayoutCell.LayoutCellData.CellContent.Crate;
targetCell.crate = this;
// Update position
layoutPosition = layoutPosition + direction;
// Move object
transform.DOMove(targetCell.worldPos, 1f);
}
}
private void Destroy()
{
Destroy(gameObject);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d65016f694ed8e34282e3a79cfa62449
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,126 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Level;
using DG.Tweening;
namespace Objects
{
public class Player : MonoBehaviour
{
private static Player instance;
public Vector2Int layoutPosition;
private bool isMoving = false;
public static Player Instance => instance;
public bool CanMove
{
get
{
return !isMoving && GameManager.Instance.currentState == GameState.Gameplay;
}
}
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
instance = this;
}
private void Start()
{
LevelBuilder.Instance.LevelInitialized += OnLevelInitialized;
LevelBuilder.Instance.LevelDestroyed += OnLevelDestroy;
}
private void Update()
{
if (CanMove)
{
if (Input.GetKeyDown(KeyCode.DownArrow))
{
Move(Vector2Int.down);
}
else if (Input.GetKeyDown(KeyCode.UpArrow))
{
Move(Vector2Int.up);
}
else if (Input.GetKeyDown(KeyCode.LeftArrow))
{
Move(Vector2Int.left);
}
else if (Input.GetKeyDown(KeyCode.RightArrow))
{
Move(Vector2Int.right);
}
}
}
public void Teleport(LayoutCell targetCell)
{
LayoutCell currentCell = LevelBuilder.Instance.GetCellAt(layoutPosition);
// Free previous cell
currentCell.cellData.cellContent = LayoutCell.LayoutCellData.CellContent.None;
// Occupy new cell
targetCell.cellData.cellContent = LayoutCell.LayoutCellData.CellContent.Player;
// Update position
layoutPosition = targetCell.layoutPosition;
transform.position = targetCell.worldPos;
}
public void Move(Vector2Int direction)
{
LayoutCell currentCell = LevelBuilder.Instance.GetCellAt(layoutPosition);
LayoutCell targetCell = LevelBuilder.Instance.GetCellAt(layoutPosition + direction);
if (targetCell != null && targetCell.IsFree)
{
// Free previous cell
currentCell.cellData.cellContent = LayoutCell.LayoutCellData.CellContent.None;
// Occupy new cell
targetCell.cellData.cellContent = LayoutCell.LayoutCellData.CellContent.Player;
// Update position
layoutPosition = layoutPosition + direction;
// Move object
isMoving = true;
transform.DOMove(targetCell.worldPos, 1f).OnComplete(() => isMoving = false);
}
else if (targetCell != null && targetCell.cellData.cellContent == LayoutCell.LayoutCellData.CellContent.Crate)
{
targetCell.crate.Move(direction);
}
}
private void OnLevelInitialized()
{
gameObject.SetActive(true);
Teleport(LevelBuilder.Instance.GetCellAt(new Vector2Int(0, 0)));
}
private void OnLevelDestroy()
{
gameObject.SetActive(false);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: df890f9d39fcb764c833db6539805676
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: