basic movement

This commit is contained in:
reisenlol 2026-01-02 02:21:53 -08:00
parent aba5310742
commit 01a1278465
No known key found for this signature in database
25 changed files with 1140 additions and 540 deletions

41
Assets/Scripts/Entity.cs Normal file
View file

@ -0,0 +1,41 @@
using System;
using UnityEngine;
public class Entity : MonoBehaviour
{
[Header("Health")]
public float health;
public float maxHealth;
[Header("Movement")]
public int maxMovement;
[Header("Flags")]
public bool canMove;
public bool invincible;
public void TakeDamage(float damage)
{
health -= damage;
if (health <= 0)
{
OnKillEffects();
}
}
public void Heal(float healing)
{
health += healing;
health = Mathf.Clamp(health, 0, maxHealth);
}
protected virtual void OnKillEffects()
{
}
private void OnMouseDown()
{
PlayerEntityMovement.instance.SelectEntity(this);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: accbecb6e5743481d886ca88a71415e7

View file

@ -0,0 +1,76 @@
using System;
using UnityEngine;
public class PlayerEntityMovement : MonoBehaviour
{
//unsure if this should also move enemies but who knows!
#region Statication
public static PlayerEntityMovement instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
instance = this;
}
#endregion
[SerializeField] private Grid gameplayGrid;
public Entity selectedEntity;
public GameObject templateObject;
public bool isMoving;
private Vector3 mouseWorldPos;
private Camera cam;
private float debounceTime;
[SerializeField] private float debounceDuration;
private void Start()
{
cam = Camera.main;
}
private void Update()
{
mouseWorldPos = cam.ScreenToWorldPoint(Input.mousePosition);
if (debounceTime > 0)
{
debounceTime -= Time.deltaTime;
}
if (isMoving)
{
templateObject.transform.position = gameplayGrid.GetCellCenterWorld(gameplayGrid.WorldToCell(mouseWorldPos));
if (Input.GetMouseButtonDown(0) && debounceTime <= 0)
{
SelectLocation();
isMoving = false;
}
}
}
public void SelectEntity(Entity entitySelected)
{
selectedEntity = entitySelected;
isMoving = true;
debounceTime = debounceDuration;
CreateTemplate();
}
private void SelectLocation()
{
selectedEntity.transform.position = gameplayGrid.GetCellCenterWorld(gameplayGrid.WorldToCell(mouseWorldPos));
templateObject.SetActive(false);
}
private void CreateTemplate()
{
templateObject.SetActive(true);
templateObject.transform.position = gameplayGrid.GetCellCenterWorld(gameplayGrid.WorldToCell(mouseWorldPos));
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 72b7602d6bb1cf0a7959df930fd2e01b