1
Fork 0
This commit is contained in:
Lorenzo Balugani 2019-04-28 16:54:52 +02:00
commit 337e52a080
28 changed files with 406 additions and 331 deletions

View file

@ -289,7 +289,8 @@ MonoBehaviour:
type: 3} type: 3}
enemyPrefabs: enemyPrefabs:
- {fileID: 470211819356819165, guid: 1bd6e08f590fdd844854a34504aeaa4a, type: 3} - {fileID: 470211819356819165, guid: 1bd6e08f590fdd844854a34504aeaa4a, type: 3}
enemiesToSpawn: 10 - {fileID: 1164136568549368904, guid: a4aeecfb369f0974490d158ef9489335, type: 3}
enemiesToSpawn: 15
--- !u!1 &6763073704789207264 --- !u!1 &6763073704789207264
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -1,85 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &7475959774386308610
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7475959774386308609}
- component: {fileID: 7475959774386308608}
- component: {fileID: 7475959774386308611}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7475959774386308609
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7475959774386308610}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
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!20 &7475959774386308608
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7475959774386308610}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 8
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!81 &7475959774386308611
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7475959774386308610}
m_Enabled: 1

View file

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 04409c352bfbdea4b9830f11d7b4d40e
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,5 +1,88 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!1 &2894367173346332696
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2894367173346332699}
- component: {fileID: 2894367173346332698}
- component: {fileID: 2894367173346332697}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2894367173346332699
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2894367173346332696}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2935319493830293414}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!20 &2894367173346332698
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2894367173346332696}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 8
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!81 &2894367173346332697
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2894367173346332696}
m_Enabled: 1
--- !u!1 &2935319493830293412 --- !u!1 &2935319493830293412
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -9,8 +92,9 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 2935319493830293414} - component: {fileID: 2935319493830293414}
- component: {fileID: 2935319493830293413}
- component: {fileID: -5893075763862095451} - component: {fileID: -5893075763862095451}
- component: {fileID: 2935319493830293413}
- component: {fileID: 8856581523727923621}
m_Layer: 0 m_Layer: 0
m_Name: Player m_Name: Player
m_TagString: Player m_TagString: Player
@ -33,24 +117,6 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2935319493830293413
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2935319493830293412}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4de6b97c3d785d146a0df2c1c078fe91, type: 3}
m_Name:
m_EditorClassIdentifier:
hpMax: 10
overlappable: 0
hp: 10
sprite: {fileID: 21300000, guid: 88f4c277892ae9449a57b321cd810bce, type: 3}
exp: 0
level: 0
--- !u!212 &-5893075763862095451 --- !u!212 &-5893075763862095451
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -99,78 +165,34 @@ SpriteRenderer:
m_WasSpriteAssigned: 1 m_WasSpriteAssigned: 1
m_MaskInteraction: 0 m_MaskInteraction: 0
m_SpriteSortPoint: 0 m_SpriteSortPoint: 0
--- !u!1001 &5734536248370648602 --- !u!114 &2935319493830293413
PrefabInstance: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 2 m_CorrespondingSourceObject: {fileID: 0}
m_Modification: m_PrefabInstance: {fileID: 0}
m_TransformParent: {fileID: 2935319493830293414}
m_Modifications:
- target: {fileID: 7475959774386308610, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_Name
value: Main Camera
objectReference: {fileID: 0}
- target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_LocalPosition.z
value: -10
objectReference: {fileID: 0}
- target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 04409c352bfbdea4b9830f11d7b4d40e, type: 3}
--- !u!4 &2894367173346332699 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 7475959774386308609, guid: 04409c352bfbdea4b9830f11d7b4d40e,
type: 3}
m_PrefabInstance: {fileID: 5734536248370648602}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2935319493830293412}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f16e1b4841b0d4546a52853aafbb7d85, type: 3}
m_Name:
m_EditorClassIdentifier:
hpMax: 10
overlappable: 0
hp: 0
sprite: {fileID: 0}
exp: 0
level: 0
--- !u!114 &8856581523727923621
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2935319493830293412}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cb881aee511ed643880a50159d731b7, type: 3}
m_Name:
m_EditorClassIdentifier:
damage: 1

View file

@ -9,8 +9,8 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 2043533519980591455} - component: {fileID: 2043533519980591455}
- component: {fileID: 571363246873614695}
- component: {fileID: 1351652798109185028} - component: {fileID: 1351652798109185028}
- component: {fileID: 571363246873614695}
m_Layer: 0 m_Layer: 0
m_Name: Slime m_Name: Slime
m_TagString: Untagged m_TagString: Untagged
@ -32,22 +32,6 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &571363246873614695
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1164136568549368904}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2fcfe4b94620b234fb7a294bf4453a69, type: 3}
m_Name:
m_EditorClassIdentifier:
hpMax: 0
hp: 0
sprite: {fileID: 21300000, guid: ee7ef72c830dc204c9df0595e161f049, type: 3}
visionRange: 4
--- !u!212 &1351652798109185028 --- !u!212 &1351652798109185028
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -96,3 +80,21 @@ SpriteRenderer:
m_WasSpriteAssigned: 1 m_WasSpriteAssigned: 1
m_MaskInteraction: 0 m_MaskInteraction: 0
m_SpriteSortPoint: 0 m_SpriteSortPoint: 0
--- !u!114 &571363246873614695
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1164136568549368904}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1ce1b6adc640d6f46bbf4d7072735b7f, type: 3}
m_Name:
m_EditorClassIdentifier:
hpMax: 2
overlappable: 0
hp: 0
sprite: {fileID: 0}
moveChance: 0.5
visionRange: 4

View file

@ -12,7 +12,7 @@ GameObject:
- component: {fileID: 470211819356819162} - component: {fileID: 470211819356819162}
- component: {fileID: 7501912107144583665} - component: {fileID: 7501912107144583665}
m_Layer: 0 m_Layer: 0
m_Name: TEST_ Item m_Name: TEST Item
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -41,13 +41,13 @@ MonoBehaviour:
m_GameObject: {fileID: 470211819356819165} m_GameObject: {fileID: 470211819356819165}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1f0883433553dbb4fa23a815949f596b, type: 3} m_Script: {fileID: 11500000, guid: cfb3c44da9ebb1840b5a2bcdfd5e2730, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
hpMax: 0 hpMax: 1
overlappable: 0 overlappable: 0
hp: 0 hp: 0
sprite: {fileID: 21300000, guid: 5e4d29e1adc2ea0429b199b82253416c, type: 3} sprite: {fileID: 0}
--- !u!212 &7501912107144583665 --- !u!212 &7501912107144583665
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -1,10 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AI : Entity
{
public virtual void OnTurn(){
Debug.LogWarning("OnTurn() not overridden");
}
}

View file

@ -10,9 +10,6 @@ public class Entity : MonoBehaviour
[AfterStartAttribute] [AfterStartAttribute]
public float hp; public float hp;
[BeforeStartAttribute]
public Sprite sprite;
public Vector2Int MapPosition { public Vector2Int MapPosition {
get { get {
return new Vector2Int((int)transform.position.x, (int)transform.position.y); return new Vector2Int((int)transform.position.x, (int)transform.position.y);
@ -23,14 +20,21 @@ public class Entity : MonoBehaviour
protected SpriteRenderer spriteRenderer; protected SpriteRenderer spriteRenderer;
protected TurnHandler turnHandler; protected TurnHandler turnHandler;
protected Map map; protected Map map;
protected MessageBar messageBar;
protected virtual void Start() protected virtual void Start()
{ {
spriteRenderer = GetComponent<SpriteRenderer>(); spriteRenderer = GetComponent<SpriteRenderer>();
spriteRenderer.sprite = sprite;
gameController = GameObject.FindGameObjectWithTag("GameController"); gameController = GameObject.FindGameObjectWithTag("GameController");
turnHandler = gameController.GetComponentInChildren<TurnHandler>(); turnHandler = gameController.GetComponentInChildren<TurnHandler>();
map = gameController.GetComponentInChildren<Map>(); map = gameController.GetComponentInChildren<Map>();
GameObject canvas = GameObject.FindGameObjectWithTag("Canvas");
messageBar = canvas.GetComponentInChildren<MessageBar>();
hp = hpMax; hp = hpMax;
} }
public virtual void Die() {
Debug.LogWarning("Die not overridden");
Destroy(gameObject);
}
} }

View file

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EntityItem : Entity
{
public virtual string Name {
get {
Debug.LogWarning("No name given to an item");
return "";
}
}
protected override void Start() {
base.Start();
overlappable = true;
}
public virtual void OnPickup(EntityPlayer player) {
Debug.LogWarning("OnPickup not overridden");
messageBar.Write("Picked up: " + Name, Color.yellow);
Destroy(gameObject);
}
public override void Die() {
messageBar.Write("Destroyed: " + Name, Color.red);
Destroy(gameObject);
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 2fcfe4b94620b234fb7a294bf4453a69 guid: cfb3c44da9ebb1840b5a2bcdfd5e2730
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View file

@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EntityMonster : Entity
{
public virtual string Name {
get {
Debug.LogWarning("No name given to a monster");
return "";
}
}
public virtual void OnTurn(){
Debug.LogWarning("OnTurn() not overridden");
}
public override void Die() {
messageBar.Write("Killed: " + Name, Color.red);
Destroy(gameObject);
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 4de6b97c3d785d146a0df2c1c078fe91 guid: aec5e971190b4b544a78be24566f9e6c
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View file

@ -2,15 +2,21 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class AISlime : AI public class EntityMonsterSlime : EntityMonster
{ {
public override string Name {
get {
return "Slime";
}
}
public float moveChance = 0.5f; public float moveChance = 0.5f;
public float visionRange = 4; public float visionRange = 4;
protected Player player; protected EntityPlayer player;
protected new void Start() { protected new void Start() {
base.Start(); base.Start();
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>(); player = GameObject.FindGameObjectWithTag("Player").GetComponent<EntityPlayer>();
} }
public override void OnTurn(){ public override void OnTurn(){

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 1f0883433553dbb4fa23a815949f596b guid: 1ce1b6adc640d6f46bbf4d7072735b7f
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View file

@ -0,0 +1,107 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum ControlMode {
Move,
Attack
}
public class EntityPlayer : Entity
{
protected ControlMode controlMode;
protected override void Start() {
base.Start();
controlMode = ControlMode.Move;
}
protected void Update()
{
CheckForControlModeChange();
if(controlMode == ControlMode.Move) CheckForMovementInput();
if(controlMode == ControlMode.Attack) CheckForAttackInput();
}
protected void CheckForControlModeChange() {
if(Input.GetKeyDown(KeyCode.Escape)) {
controlMode = ControlMode.Move;
messageBar.Write("Control mode: Move", Color.cyan);
}
if(Input.GetKeyDown(KeyCode.A)) {
controlMode = ControlMode.Attack;
messageBar.Write("Control mode: Attack", Color.cyan);
}
}
protected void CheckForAttackInput() {
bool hasAttacked = false;
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
hasAttacked = GetComponent<PlayerAttack>().Attack(MapPosition + Vector2Int.left);
}
else if (Input.GetKeyDown(KeyCode.RightArrow))
{
hasAttacked = GetComponent<PlayerAttack>().Attack(MapPosition + Vector2Int.right);
}
else if (Input.GetKeyDown(KeyCode.UpArrow))
{
hasAttacked = GetComponent<PlayerAttack>().Attack(MapPosition + Vector2Int.up);
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
hasAttacked = GetComponent<PlayerAttack>().Attack(MapPosition + Vector2Int.down);
}
if(hasAttacked) {
//Turn happens!
turnHandler.OnTurn();
}
}
protected void CheckForMovementInput()
{
bool hasMoved = false;
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
if (map.CanMoveTo(MapPosition + Vector2Int.left)) {
transform.Translate(Vector3.left);
hasMoved = true;
spriteRenderer.flipX = false;
}
}
else if (Input.GetKeyDown(KeyCode.RightArrow))
{
if (map.CanMoveTo(MapPosition + Vector2Int.right)) {
transform.Translate(Vector3.right);
hasMoved = true;
spriteRenderer.flipX = true;
}
}
else if (Input.GetKeyDown(KeyCode.UpArrow))
{
if (map.CanMoveTo(MapPosition + Vector2Int.up)) {
transform.Translate(Vector3.up);
hasMoved = true;
}
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
if (map.CanMoveTo(MapPosition + Vector2Int.down)) {
transform.Translate(Vector3.down);
hasMoved = true;
}
}
if(hasMoved) {
//Check for pickuppable items
List<Entity> entities = turnHandler.GetEntitiesAtPosition(MapPosition);
foreach(Entity entity in entities) {
if(entity is EntityItem) {
EntityItem item = entity as EntityItem;
item.OnPickup(this);
}
}
//Turn happens!
turnHandler.OnTurn();
}
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: e694420377849854db7a2686ff36420c guid: f16e1b4841b0d4546a52853aafbb7d85
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View file

@ -5,11 +5,11 @@ using UnityEngine.UI;
public class FillAmountFromPlayerHP : MonoBehaviour public class FillAmountFromPlayerHP : MonoBehaviour
{ {
private Player player; private EntityPlayer player;
private Image image; private Image image;
private void Start() { private void Start() {
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>(); player = GameObject.FindGameObjectWithTag("Player").GetComponent<EntityPlayer>();
image = GetComponent<Image>(); image = GetComponent<Image>();
} }

View file

@ -1,17 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Item : Entity
{
protected override void Start() {
base.Start();
overlappable = true;
}
public virtual void OnPickup(Player player) {
Debug.LogWarning("OnPickup not overridden");
turnHandler.WriteToMessageBar("Picked up [NULL].");
Destroy(gameObject);
}
}

View file

@ -124,10 +124,10 @@ public class Map : MonoBehaviour
private List<MapRoom> rooms; private List<MapRoom> rooms;
private TurnHandler turnHandler; private TurnHandler turnHandler;
public Tile GetTile(Vector2Int position) { public MapTile GetTile(Vector2Int position) {
try { try {
GameObject tileObject = tiles[position.x, position.y]; GameObject tileObject = tiles[position.x, position.y];
return tileObject.GetComponent<Tile>(); return tileObject.GetComponent<MapTile>();
} }
catch(System.IndexOutOfRangeException) { catch(System.IndexOutOfRangeException) {
return null; return null;
@ -138,7 +138,7 @@ public class Map : MonoBehaviour
{ {
try { try {
bool walkable = GetTile(position).walkable; bool walkable = GetTile(position).walkable;
List<Entity> entities = turnHandler.GetEntityAtPosition(position); List<Entity> entities = turnHandler.GetEntitiesAtPosition(position);
bool free = true; bool free = true;
foreach(Entity entity in entities) { foreach(Entity entity in entities) {
free &= entity.overlappable; free &= entity.overlappable;
@ -151,7 +151,7 @@ public class Map : MonoBehaviour
} }
private void EditTile(Vector2Int position, bool walkable, bool roomPart) { private void EditTile(Vector2Int position, bool walkable, bool roomPart) {
Tile tile = GetTile(position); MapTile tile = GetTile(position);
tile.walkable = walkable; tile.walkable = walkable;
tile.roomPart |= roomPart; tile.roomPart |= roomPart;
} }
@ -163,7 +163,7 @@ public class Map : MonoBehaviour
tileObject.transform.position = new Vector3(x, y, 0); tileObject.transform.position = new Vector3(x, y, 0);
tiles[x, y] = tileObject; tiles[x, y] = tileObject;
tileObject.name = "Tile [" + x.ToString() + ", " + y.ToString() + "]"; tileObject.name = "Tile [" + x.ToString() + ", " + y.ToString() + "]";
Tile tile = tileObject.GetComponent<Tile>(); MapTile tile = tileObject.GetComponent<MapTile>();
tile.walkable = false; tile.walkable = false;
} }
} }
@ -270,8 +270,8 @@ public class Map : MonoBehaviour
public void GenerateTileSprites() { public void GenerateTileSprites() {
for(int x = 0; x < mapSize; x++) { for(int x = 0; x < mapSize; x++) {
for(int y = 0; y < mapSize; y++) { for(int y = 0; y < mapSize; y++) {
Tile tile = GetTile(new Vector2Int(x, y)); MapTile tile = GetTile(new Vector2Int(x, y));
Tile otherTile; MapTile otherTile;
if(tile.walkable) tile.sprite = SampleSprite(floorSprites); if(tile.walkable) tile.sprite = SampleSprite(floorSprites);
else if((bool)(otherTile = GetTile(new Vector2Int(x, y+1))) && otherTile.walkable) tile.sprite = SampleSprite(botWallSprites); else if((bool)(otherTile = GetTile(new Vector2Int(x, y+1))) && otherTile.walkable) tile.sprite = SampleSprite(botWallSprites);
else if((bool)(otherTile = GetTile(new Vector2Int(x, y+1))) && otherTile.walkable) tile.sprite = SampleSprite(topWallSprites); else if((bool)(otherTile = GetTile(new Vector2Int(x, y+1))) && otherTile.walkable) tile.sprite = SampleSprite(topWallSprites);

View file

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class Tile : MonoBehaviour public class MapTile : MonoBehaviour
{ {
public bool walkable; public bool walkable;
public bool roomPart; public bool roomPart;

View file

@ -17,7 +17,8 @@ public class MessageBar : MonoBehaviour
opacity = 0f; opacity = 0f;
} }
public void Write(string message) { public void Write(string message, Color color) {
text.color = color;
text.text = message; text.text = message;
opacity = 1f; opacity = 1f;
} }

View file

@ -1,61 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : Entity
{
public int exp;
public int level;
void Update()
{
CheckForMovementInput();
}
void CheckForMovementInput()
{
bool hasMoved = false;
if (Input.GetKeyDown(KeyCode.A))
{
if (map.CanMoveTo(MapPosition + Vector2Int.left)) {
transform.Translate(Vector3.left);
hasMoved = true;
spriteRenderer.flipX = false;
}
}
else if (Input.GetKeyDown(KeyCode.D))
{
if (map.CanMoveTo(MapPosition + Vector2Int.right)) {
transform.Translate(Vector3.right);
hasMoved = true;
spriteRenderer.flipX = true;
}
}
else if (Input.GetKeyDown(KeyCode.W))
{
if (map.CanMoveTo(MapPosition + Vector2Int.up)) {
transform.Translate(Vector3.up);
hasMoved = true;
}
}
else if (Input.GetKeyDown(KeyCode.S))
{
if (map.CanMoveTo(MapPosition + Vector2Int.down)) {
transform.Translate(Vector3.down);
hasMoved = true;
}
}
if(hasMoved) {
//Check for pickuppable items
List<Entity> entities = turnHandler.GetEntityAtPosition(MapPosition);
foreach(Entity entity in entities) {
if(entity is Item) {
Item item = entity as Item;
item.OnPickup(this);
}
}
//Turn happens!
turnHandler.OnTurn();
}
}
}

View file

@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAttack : MonoBehaviour
{
protected EntityPlayer player;
protected GameObject gameController;
protected TurnHandler turnHandler;
protected Map map;
protected void Start() {
player = GetComponent<EntityPlayer>();
gameController = GameObject.FindGameObjectWithTag("GameController");
turnHandler = gameController.GetComponentInChildren<TurnHandler>();
map = gameController.GetComponentInChildren<Map>();
}
public virtual bool Attack(Vector2Int target) {
//Returns if the attack was successful.
Debug.LogWarning("Attack not overridden");
return false;
}
}

View file

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

View file

@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAttackMelee : PlayerAttack
{
public float damage = 1f;
public override bool Attack(Vector2Int target) {
List<Entity> targetEntities = turnHandler.GetEntitiesAtPosition(target);
if(targetEntities.Count == 0) {
return false;
}
Entity targetEntity = targetEntities[0];
targetEntity.hp -= damage;
return true;
}
}

View file

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

View file

@ -4,25 +4,22 @@ using UnityEngine;
public class TurnHandler : MonoBehaviour public class TurnHandler : MonoBehaviour
{ {
private MessageBar messageBar;
private void Start() {
GameObject canvas = GameObject.FindGameObjectWithTag("Canvas");
messageBar = canvas.GetComponentInChildren<MessageBar>();
}
public void WriteToMessageBar(string message) {
messageBar.Write(message);
}
public void OnTurn() { public void OnTurn() {
AI[] ais = gameObject.GetComponentsInChildren<AI>(); Entity[] entities = gameObject.GetComponentsInChildren<Entity>();
foreach(AI ai in ais) { foreach(Entity entity in entities) {
ai.OnTurn(); //Check for deaths
if(entity.hp <= 0) {
entity.Die();
}
//Move AIs
if(entity is EntityMonster) {
EntityMonster ai = entity as EntityMonster;
ai.OnTurn();
}
} }
} }
public List<Entity> GetEntityAtPosition(Vector2Int position) { public List<Entity> GetEntitiesAtPosition(Vector2Int position) {
Entity[] entities = GetComponentsInChildren<Entity>(); Entity[] entities = GetComponentsInChildren<Entity>();
List<Entity> found = new List<Entity>(); List<Entity> found = new List<Entity>();
foreach(Entity entity in entities) { foreach(Entity entity in entities) {