1
Fork 0
This commit is contained in:
Francesca Peres 2019-04-27 17:20:43 +02:00
commit 2f580a9e97
27 changed files with 967 additions and 25 deletions

39
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,39 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Unity Editor",
"type": "unity",
"path": "/t:/Unity Projects/LD44/Library/EditorInstance.json",
"request": "launch"
},
{
"name": "Windows Player",
"type": "unity",
"request": "launch"
},
{
"name": "OSX Player",
"type": "unity",
"request": "launch"
},
{
"name": "Linux Player",
"type": "unity",
"request": "launch"
},
{
"name": "iOS Player",
"type": "unity",
"request": "launch"
},
{
"name": "Android Player",
"type": "unity",
"request": "launch"
}
]
}

56
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,56 @@
{
"files.exclude":
{
"**/.DS_Store":true,
"**/.git":true,
"**/.gitignore":true,
"**/.gitmodules":true,
"**/*.booproj":true,
"**/*.pidb":true,
"**/*.suo":true,
"**/*.user":true,
"**/*.userprefs":true,
"**/*.unityproj":true,
"**/*.dll":true,
"**/*.exe":true,
"**/*.pdf":true,
"**/*.mid":true,
"**/*.midi":true,
"**/*.wav":true,
"**/*.gif":true,
"**/*.ico":true,
"**/*.jpg":true,
"**/*.jpeg":true,
"**/*.png":true,
"**/*.psd":true,
"**/*.tga":true,
"**/*.tif":true,
"**/*.tiff":true,
"**/*.3ds":true,
"**/*.3DS":true,
"**/*.fbx":true,
"**/*.FBX":true,
"**/*.lxo":true,
"**/*.LXO":true,
"**/*.ma":true,
"**/*.MA":true,
"**/*.obj":true,
"**/*.OBJ":true,
"**/*.asset":true,
"**/*.cubemap":true,
"**/*.flare":true,
"**/*.mat":true,
"**/*.meta":true,
"**/*.prefab":true,
"**/*.unity":true,
"build/":true,
"Build/":true,
"Library/":true,
"library/":true,
"obj/":true,
"Obj/":true,
"ProjectSettings/":true,
"temp/":true,
"Temp/":true
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: ef3d86d84c224344a94715cdfa9fe32c
guid: fd1b080c01a34694793e8f2ff140bfc0
folderAsset: yes
DefaultImporter:
externalObjects: {}

View file

@ -0,0 +1,21 @@
//From https://answers.unity.com/questions/442342/how-to-make-public-variable-read-only-during-run-t.html
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(BeforeStartAttribute))]
public class BeforeStartAttributeDrawer : 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: 3a2a8e24cbb5e9a4f88abc3055e15cb7
guid: 13bad693cf0c2634ea1e2be679edf00f
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: e823a56cb429e4b49becdc740fba66b9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

52
Assets/Prefabs/Map.prefab Normal file
View file

@ -0,0 +1,52 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &7249059666095778526
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7249059666095778521}
- component: {fileID: 6907631410461015020}
m_Layer: 0
m_Name: Map
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7249059666095778521
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7249059666095778526}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &6907631410461015020
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7249059666095778526}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 052bc569472779a429bfc51246f723d4, type: 3}
m_Name:
m_EditorClassIdentifier:
mapSize: 30
roomsToGenerate: 5
wallSprite: {fileID: 21300000, guid: f5be5362b22aa6c48993a720ec6c9b84, type: 3}
roomSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
corridorSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
tilePrefab: {fileID: 3219556109866242471, guid: 0e0b618b5499bbb40b076c0291d55487,
type: 3}

View file

@ -1,7 +1,6 @@
fileFormatVersion: 2
guid: 043f304edcc831c4ea9fcf0e1a2e520d
folderAsset: yes
DefaultImporter:
guid: cd714ea41cb7c454994bf0f5ad99abd1
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:

View file

@ -0,0 +1,96 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3219556109866242471
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3219556109866242468}
- component: {fileID: 9040756953319481538}
- component: {fileID: 1691311275711631131}
m_Layer: 0
m_Name: Tile
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3219556109866242468
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3219556109866242471}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &9040756953319481538
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3219556109866242471}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4df8012d0534aea47b137c1838a5a6af, type: 3}
m_Name:
m_EditorClassIdentifier:
walkable: 0
sprite: {fileID: 0}
--- !u!212 &1691311275711631131
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3219556109866242471}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 0
m_MaskInteraction: 0
m_SpriteSortPoint: 0

View file

@ -1,7 +1,6 @@
fileFormatVersion: 2
guid: 0460346d99d385241a6d87bbd10aceb8
folderAsset: yes
DefaultImporter:
guid: 0e0b618b5499bbb40b076c0291d55487
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:

View file

@ -272,3 +272,72 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 4c25f33cb89f6624db48fc49d353a7f2, type: 3}
--- !u!1001 &7249059666254997933
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 7249059666095778526, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_Name
value: Map
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7249059666095778521, guid: cd714ea41cb7c454994bf0f5ad99abd1,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: cd714ea41cb7c454994bf0f5ad99abd1, type: 3}

View file

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

View file

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

View file

@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Consumabile : Object
{
// Start is called before the first frame update
public enum Tipo {Cura, Danno};
public GameObject player;
public Player player;
public int valore;
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void use(){
if (Tipo == Tipo.Cura){
player.hp += valore;
if (player.hp >= player.maxhp) player.hp = player.maxhp;
}
if (Tipo == Tipo.Danno){
player.hp -= valore;
}
}
}

View file

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

259
Assets/Scripts/Map.cs Normal file
View file

@ -0,0 +1,259 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class ImpossibleCorridorError : System.Exception
{
public ImpossibleCorridorError() { }
public ImpossibleCorridorError(string message) : base(message) { }
public ImpossibleCorridorError(string message, System.Exception inner) : base(message, inner) { }
protected ImpossibleCorridorError(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
public class MapRoom {
public readonly Vector2Int start;
public readonly Vector2Int end;
public readonly int mapSize;
public MapRoom(int mapSize, int maxRoomSize) {
this.mapSize = mapSize;
start = new Vector2Int(Random.Range(0, mapSize), Random.Range(0, mapSize));
end = new Vector2Int(Random.Range(0, mapSize), Random.Range(0, mapSize));
if(start.x > end.x) {
int swap = start.x;
start.x = end.x;
end.x = swap;
}
if(start.y > end.y) {
int swap = start.y;
start.y = end.y;
end.y = swap;
}
while(end.x - start.x > maxRoomSize) {
end.x--;
start.x++;
}
while(end.y - start.y > maxRoomSize) {
end.y--;
start.y++;
}
}
public bool RightCheck() {
return end.x < mapSize-1;
}
public Vector2Int RightCorridorAttachment() {
return new Vector2Int(end.x+1, Random.Range(start.y, end.y+1));
}
public bool LeftCheck() {
return start.x > 0;
}
public Vector2Int LeftCorridorAttachment() {
return new Vector2Int(start.x-1, Random.Range(start.y, end.y+1));
}
public bool TopCheck() {
return end.y < mapSize-1;
}
public Vector2Int TopCorridorAttachment() {
return new Vector2Int(Random.Range(start.x, end.x+1), end.y+1);
}
public bool BottomCheck() {
return start.y > 0;
}
public Vector2Int BottomCorridorAttachment() {
return new Vector2Int(Random.Range(start.x, end.x+1), start.y-1);
}
}
public enum CorridorModes {
bottomToTop,
topToBottom,
rightToLeft,
leftToRight
}
public class MapCorridor {
public readonly Vector2Int start;
public readonly Vector2Int end;
public readonly bool horizontal_priority;
public MapCorridor(MapRoom from, MapRoom to, int mapSize) {
List<CorridorModes> corridorModes = new List<CorridorModes>();
//Find allowed CorridorModes
if(from.end.y <= to.start.y && from.BottomCheck() && to.TopCheck()) corridorModes.Add(CorridorModes.bottomToTop);
if(from.start.y >= to.end.y && from.TopCheck() && to.BottomCheck()) corridorModes.Add(CorridorModes.topToBottom);
if(from.end.x <= to.start.y && from.RightCheck() && to.LeftCheck()) corridorModes.Add(CorridorModes.rightToLeft);
if(from.start.y >= to.end.y && from.LeftCheck() && to.RightCheck()) corridorModes.Add(CorridorModes.leftToRight);
//Select and use a corridor mode
if(corridorModes.Count < 1) throw new ImpossibleCorridorError();
CorridorModes corridorMode = corridorModes[Random.Range(0, corridorModes.Count)];
if(corridorMode == CorridorModes.bottomToTop) {
start = from.BottomCorridorAttachment();
end = to.TopCorridorAttachment();
}
if(corridorMode == CorridorModes.topToBottom) {
start = from.TopCorridorAttachment();
end = to.BottomCorridorAttachment();
}
if(corridorMode == CorridorModes.rightToLeft) {
start = from.RightCorridorAttachment();
end = to.LeftCorridorAttachment();
}
if(corridorMode == CorridorModes.leftToRight) {
start = from.LeftCorridorAttachment();
end = to.RightCorridorAttachment();
}
//50%
horizontal_priority = Random.Range(0f, 1f) >= 0.5f;
}
}
public class Map : MonoBehaviour
{
[BeforeStartAttribute]
public int mapSize = 30;
[BeforeStartAttribute]
public int roomsToGenerate = 5;
[BeforeStartAttribute]
public int maxRoomSize = 6;
[BeforeStartAttribute]
public int maxRoomIterations = 100;
[BeforeStartAttribute]
public Sprite wallSprite;
[BeforeStartAttribute]
public Sprite roomSprite;
[BeforeStartAttribute]
public Sprite corridorSprite;
[BeforeStartAttribute]
public GameObject tilePrefab;
private GameObject[,] tiles;
private List<MapRoom> rooms;
private System.Random rnd;
public Tile GetTile(int x, int y) {
GameObject tileObject = tiles[x, y];
Tile tile = tileObject.GetComponent<Tile>();
return tile;
}
private void InitTile(int x, int y, bool walkable, Sprite tileSprite, bool roomPart) {
Tile tile = GetTile(x, y);
tile.walkable = walkable;
tile.sprite = tileSprite;
tile.roomPart = roomPart;
}
private void FillWithWalls() {
for(int x = 0; x < mapSize; x++) {
for(int y = 0; y < mapSize; y++) {
GameObject tileObject = Instantiate(tilePrefab, transform);
tileObject.transform.position = new Vector3(x, y, 0);
tiles[x, y] = tileObject;
tileObject.name = "Tile [" + x.ToString() + ", " + y.ToString() + "]";
Tile tile = tileObject.GetComponent<Tile>();
tile.walkable = false;
tile.sprite = wallSprite;
}
}
}
private void PlaceRoom(MapRoom mr) {
for(int x = mr.start.x; x <= mr.end.x; x++) {
for(int y = mr.start.y; y <= mr.end.y; y++) {
InitTile(x, y, true, roomSprite, true);
}
}
}
private bool ScanRoom(MapRoom mr) {
//Returns true if the room can be safely placed
for(int x = Mathf.Clamp(mr.start.x-1, 0, mapSize-1); x <= Mathf.Clamp(mr.end.x+1, 0, mapSize-1); x++) {
for(int y = Mathf.Clamp(mr.start.y-1, 0, mapSize-1); y <= Mathf.Clamp(mr.end.y+1, 0, mapSize-1); y++) {
if(GetTile(x, y).roomPart) {
return false;
}
}
}
return true;
}
private void PlaceCorridor(MapCorridor mc) {
Vector2Int cursor = new Vector2Int(mc.start.x, mc.start.y);
InitTile(cursor.x, cursor.y, true, corridorSprite, false);
if(mc.horizontal_priority) {
while(cursor.x != mc.end.x) {
if(cursor.x > mc.end.x) cursor.x--;
else cursor.x++;
InitTile(cursor.x, cursor.y, true, corridorSprite, false);
}
while(cursor.y != mc.end.y) {
if(cursor.y > mc.end.y) cursor.y--;
else cursor.y++;
InitTile(cursor.x, cursor.y, true, corridorSprite, false);
}
}
else
{
while(cursor.y != mc.end.y) {
if(cursor.y > mc.end.y) cursor.y--;
else cursor.y++;
InitTile(cursor.x, cursor.y, true, corridorSprite, false);
}
while(cursor.x != mc.end.x) {
if(cursor.x > mc.end.x) cursor.x--;
else cursor.x++;
InitTile(cursor.x, cursor.y, true, corridorSprite, false);
}
}
}
private void GenerateMap() {
FillWithWalls();
int roomIterations = 0;
while(rooms.Count < roomsToGenerate && roomIterations < maxRoomIterations) {
roomIterations++;
MapRoom room = new MapRoom(mapSize, maxRoomSize);
if(ScanRoom(room)) {
PlaceRoom(room);
rooms.Add(room);
}
if(rooms.Count > 1) {
MapRoom from = rooms[rooms.Count-2];
MapRoom to = rooms[rooms.Count-1];
try {
MapCorridor corridor = new MapCorridor(from, to, mapSize);
PlaceCorridor(corridor);
}
catch (ImpossibleCorridorError) {}
}
}
}
private void Start()
{
//Initialize everything
tiles = new GameObject[mapSize, mapSize];
rooms = new List<MapRoom>();
rnd = new System.Random();
//Generate the map
GenerateMap();
}
}

View file

@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 052bc569472779a429bfc51246f723d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- wallSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
- roomSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
- corridorSprite: {fileID: 21300000, guid: e0e60c9a4ff0b8e429e6cfe316da9bbf, type: 3}
- tilePrefab: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

62
Assets/Scripts/Mostro.cs Normal file
View file

@ -0,0 +1,62 @@
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

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

View file

@ -2,8 +2,10 @@
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
public class Object : MonoBehaviour
{
public string nome;
public int costo;
// Start is called before the first frame update
void Start()
{

View file

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

56
Assets/Scripts/Player.cs Normal file
View file

@ -0,0 +1,56 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
private int exp, level, hp, maxhp;
public int startingHp;
public Map map;
//TODO: Aggiungi gli oggetti in inventario
// Start is called before the first frame update
void Start()
{
hp = startingHp;
}
// Update is called once per frame
void Update()
{
playerMovement();
}
void playerMovement()
{
if (Input.GetKey(KeyCode.A))
{
if (is_valid_movement("left")) transform.Translate(Vector3.left);
}
if (Input.GetKey(KeyCode.D))
{
if (is_valid_movement("right")) transform.Translate(Vector3.right);
}
if (Input.GetKey(KeyCode.W))
{
if (is_valid_movement("up")) transform.Translate(Vector3.up);
}
if (Input.GetKey(KeyCode.S))
{
if (is_valid_movement("down")) transform.Translate(Vector3.down);
}
// Qui c'è da aggiungere la condizione per il controllo degli hp
}
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

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

18
Assets/Scripts/Tile.cs Normal file
View file

@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tile : MonoBehaviour
{
public bool walkable;
public bool roomPart;
public Sprite sprite;
private SpriteRenderer spriteRenderer;
private void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
spriteRenderer.sprite = sprite;
}
}

View file

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

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 19c0d85909aede34bb371863f187b9e0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,112 @@
fileFormatVersion: 2
guid: e0e60c9a4ff0b8e429e6cfe316da9bbf
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 40
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 9a9cdb0ef0236d64bbd871c33fd3d927
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant: