From c4a244439e4bcb4dcdca59a52a843a18e304c9c5 Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Sat, 27 Apr 2019 14:40:09 +0200 Subject: [PATCH] Player class Add basic player movement --- Assets/Animations.meta | 8 --- Assets/Animators.meta | 8 --- Assets/Assets.meta | 8 --- Assets/PhysMats.meta | 8 --- Assets/Scripts/Player.cs | 56 +++++++++++++++++ Assets/Scripts/Player.cs.meta | 11 ++++ Assets/Sounds.meta | 8 --- Assets/Sprites/PurpleTileset.png.meta | 90 +++++++++++++++++++++++++++ 8 files changed, 157 insertions(+), 40 deletions(-) delete mode 100644 Assets/Animations.meta delete mode 100644 Assets/Animators.meta delete mode 100644 Assets/Assets.meta delete mode 100644 Assets/PhysMats.meta create mode 100644 Assets/Scripts/Player.cs create mode 100644 Assets/Scripts/Player.cs.meta delete mode 100644 Assets/Sounds.meta create mode 100644 Assets/Sprites/PurpleTileset.png.meta diff --git a/Assets/Animations.meta b/Assets/Animations.meta deleted file mode 100644 index b2a79e2..0000000 --- a/Assets/Animations.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ef3d86d84c224344a94715cdfa9fe32c -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Animators.meta b/Assets/Animators.meta deleted file mode 100644 index 7ff80b8..0000000 --- a/Assets/Animators.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 043f304edcc831c4ea9fcf0e1a2e520d -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Assets.meta b/Assets/Assets.meta deleted file mode 100644 index 4eba494..0000000 --- a/Assets/Assets.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 0460346d99d385241a6d87bbd10aceb8 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/PhysMats.meta b/Assets/PhysMats.meta deleted file mode 100644 index bc5b1b2..0000000 --- a/Assets/PhysMats.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: e823a56cb429e4b49becdc740fba66b9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs new file mode 100644 index 0000000..163ba18 --- /dev/null +++ b/Assets/Scripts/Player.cs @@ -0,0 +1,56 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Player : MonoBehaviour +{ + private int exp, level, hp; + public GameObject player; + 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")) player.transform.Translate(Vector3.left); + } + if (Input.GetKey(KeyCode.D)) + { + if (is_valid_movement("right")) player.transform.Translate(Vector3.right); + } + if (Input.GetKey(KeyCode.W)) + { + if (is_valid_movement("up")) player.transform.Translate(Vector3.up); + } + if (Input.GetKey(KeyCode.S)) + { + if (is_valid_movement("down")) player.transform.Translate(Vector3.down); + } + } + + bool is_valid_movement(string direction) + { + Tile tile; + int posX = (int) player.transform.position.x; + int posY = (int) player.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(); + } +} diff --git a/Assets/Scripts/Player.cs.meta b/Assets/Scripts/Player.cs.meta new file mode 100644 index 0000000..4cba488 --- /dev/null +++ b/Assets/Scripts/Player.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4de6b97c3d785d146a0df2c1c078fe91 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Sounds.meta b/Assets/Sounds.meta deleted file mode 100644 index 5fd147f..0000000 --- a/Assets/Sounds.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 19c0d85909aede34bb371863f187b9e0 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Sprites/PurpleTileset.png.meta b/Assets/Sprites/PurpleTileset.png.meta new file mode 100644 index 0000000..c4abff8 --- /dev/null +++ b/Assets/Sprites/PurpleTileset.png.meta @@ -0,0 +1,90 @@ +fileFormatVersion: 2 +guid: 61345c477d96361428c3eb1bfb0c293a +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: 100 + 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 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 1cead1e412dade640b800b9e34ee4c89 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: