1
Fork 0
This commit is contained in:
Steffo 2019-04-27 17:57:01 +02:00
parent 8af505138f
commit 6c875795a8
10 changed files with 96 additions and 90 deletions

View file

@ -18,4 +18,22 @@ public class BeforeStartAttributeDrawer : PropertyDrawer
EditorGUI.PropertyField(position, property, label, true);
GUI.enabled = true;
}
}
[CustomPropertyDrawer(typeof(AfterStartAttribute))]
public class AfterStartAttributeDrawer : PropertyDrawer
{
// Necessary since some properties tend to collapse smaller than their content
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
// Draw a disabled property field
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = Application.isPlaying;
EditorGUI.PropertyField(position, property, label, true);
GUI.enabled = true;
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d484827da1a4f984c837dbfb9f970bdd
guid: cd8509fca2c0ebe47acb277e2aed11f2
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -1,5 +0,0 @@
using UnityEngine;
public class BeforeStartAttribute : PropertyAttribute {
}

View file

@ -0,0 +1,5 @@
using UnityEngine;
public class BeforeStartAttribute : PropertyAttribute {}
public class AfterStartAttribute : PropertyAttribute {}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 13bad693cf0c2634ea1e2be679edf00f
guid: 6fdc88abee025004d9040a4026bfcb11
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -154,6 +154,11 @@ public class Map : MonoBehaviour
return tile;
}
public bool CanMoveTo(Vector2Int direction)
{
return GetTile(direction).walkable;
}
private void InitTile(Vector2Int position, bool walkable, Sprite tileSprite, bool roomPart) {
Tile tile = GetTile(position);
tile.walkable = walkable;

40
Assets/Scripts/Monster.cs Normal file
View file

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Monster : MonoBehaviour
{
public int hpMax;
public int hp;
public bool isUndead;
public int movesPerTurn;
public bool hasSpottedPlayer;
[BeforeStartAttribute]
public Sprite sprite;
private Map map;
// Start is called before the first frame update
void Start()
{
map = GameObject.FindGameObjectWithTag("Map").GetComponent<Map>();
hasSpottedPlayer = false;
}
void Turn(){
int direction = Random.Range(0, 4);
if (direction == 0 && map.CanMoveTo(Vector2Int.left)){
transform.Translate(Vector3.left);
}
else if (direction == 1 && map.CanMoveTo(Vector2Int.right)){
transform.Translate(Vector3.right);
}
else if (direction == 2 && map.CanMoveTo(Vector2Int.up)){
transform.Translate(Vector3.up);
}
else if (direction == 3 && map.CanMoveTo(Vector2Int.left)){
transform.Translate(Vector3.left);
}
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: ec73aa347f0168f4f95e1acbd3072646
guid: a72ad0eb2136f284bab78f19fa561bb8
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -1,64 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
public class Mostro : MonoBehaviour
{
public string nome;
public Sprite sprite;
public int hpmax, hp, exp;
public bool is_undead;
public enum speed {slow, standard, fast};
private bool player_spotted;
public Map map;
// Start is called before the first frame update
void Start()
{
map = gameObjectMappa.GetComponent<Map>();
player_spotted = false;
}
// Update is called once per frame
void Update()
{
if (!player_spotted){
roam();
}
//Da mettere il pathfinding per quando trova il personaggio
}
void roam(){
while (true)
{
int direction = Random.Range(1, 5);
if (direction==1 && is_valid_movement("left")){
transform.Translate(Vector3.left);
break;
}
else if (direction==2 && is_valid_movement("right")){
transform.Translate(Vector3.right);
break;
}
else if (direction==3 && is_valid_movement("up")){
transform.Translate(Vector3.up);
break;
}
else if (is_valid_movement("down")){
transform.Translate(Vector3.up);
break;
}
}
}
bool is_valid_movement(string direction)
{
Tile tile;
int posX = (int) transform.position.x;
int posY = (int) transform.position.y;
if (direction == "left") tile = map.GetTile(posX - 1, posY);
else if (direction == "right") tile = map.GetTile(posX + 1, posY);
else if (direction == "up") tile = map.GetTile(posX, posY + 1);
else tile = map.GetTile(posX, posY - 1);
return tile.walkable;
}
}
*/

View file

@ -4,18 +4,23 @@ using UnityEngine;
public class Player : MonoBehaviour
{
private int exp, level, hp, maxhp;
public int startingHp;
public Map map;
//TODO: Aggiungi gli oggetti in inventario
public int exp;
public int level;
public int hpMax;
[AfterStartAttribute]
public int hp;
private Map map;
private GameObject gameController;
// Start is called before the first frame update
void Start()
{
hp = startingHp;
map = GameObject.FindGameObjectWithTag("Map").GetComponent<Map>();
gameController = GameObject.FindGameObjectWithTag("GameController");
hp = hpMax;
}
// Update is called once per frame
void Update()
{
CheckForMovementInput();
@ -26,32 +31,34 @@ public class Player : MonoBehaviour
bool hasMoved = false;
if (Input.GetKeyDown(KeyCode.A))
{
if (CanMoveTo(Vector2Int.left)) {
transform.Translate(Vector3.left);}
if (map.CanMoveTo(Vector2Int.left)) {
transform.Translate(Vector3.left);
hasMoved = true;
}
}
else if (Input.GetKeyDown(KeyCode.D))
{
if (CanMoveTo(Vector2Int.right)) {
if (map.CanMoveTo(Vector2Int.right)) {
transform.Translate(Vector3.right);
hasMoved = true;
}
}
else if (Input.GetKeyDown(KeyCode.W))
{
if (CanMoveTo(Vector2Int.up)) {
if (map.CanMoveTo(Vector2Int.up)) {
transform.Translate(Vector3.up);
hasMoved = true;
}
}
else if (Input.GetKeyDown(KeyCode.S))
{
if (CanMoveTo(Vector2Int.down)) {
if (map.CanMoveTo(Vector2Int.down)) {
transform.Translate(Vector3.down);
hasMoved = true;
}
}
}
bool CanMoveTo(Vector2Int direction)
{
return map.GetTile(direction).walkable;
if(hasMoved) {
gameController.BroadcastMessage("Turn");
}
}
}