1
Fork 0

We have a cool skeleton archer ai now

This commit is contained in:
Lorenzo Balugani 2019-04-29 22:09:41 +02:00
parent 1fb55c1018
commit 7ca47e7c47
5 changed files with 231 additions and 1 deletions

View file

@ -0,0 +1,107 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6557538193408494165
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2850779665516729054}
- component: {fileID: 1965585829385846694}
- component: {fileID: -144353291634153714}
m_Layer: 0
m_Name: SkeletonArrow
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2850779665516729054
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6557538193408494165}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 15.984027, y: 16.344006, z: -5.046875}
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!212 &1965585829385846694
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6557538193408494165}
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: -522733599
m_SortingLayer: 1
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: a39db14fa2fc34f4a84101be3d2d5d35, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 0.72, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!114 &-144353291634153714
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6557538193408494165}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8c5306e803d8d9344b3a7b100fa00deb, type: 3}
m_Name:
m_EditorClassIdentifier:
hpTrueMax: 10
overlappable: 0
hpMax: 0
hp: 0
monsterName: Skeleton Archer
moveChance: 0.3
visionRange: 6
attackRange: 3
damage: 1.5
attackAnimation: {fileID: 5896060810164205279, guid: 602b69921902efc44ab8a008655b6574,
type: 3}
upSprite: {fileID: 21300000, guid: a39db14fa2fc34f4a84101be3d2d5d35, type: 3}
downSprite: {fileID: 21300000, guid: a39db14fa2fc34f4a84101be3d2d5d35, type: 3}

View file

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

View file

@ -93,6 +93,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
hpTrueMax: 10000
overlappable: 1
overlappable: 0
hpMax: 0
hp: 0

View file

@ -0,0 +1,105 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EntitySkeletonArcher : EntityMonster
{
public float moveChance = 0.5f;
public float visionRange = 6f;
public float attackRange = 5f;
public float damage = 1.5f;
public GameObject attackAnimation;
protected EntityPlayer player;
[BeforeStartAttribute]
public Sprite upSprite;
[BeforeStartAttribute]
public Sprite downSprite;
protected new void Start() {
base.Start();
player = GameObject.FindGameObjectWithTag("Player").GetComponent<EntityPlayer>();
}
public override void OnTurn(){
if(Random.value < moveChance) return;
if (CanSeePlayer()){
Vector2Int distance = player.MapPosition - MapPosition;
if(distance.magnitude <= attackRange) {
if(Random.value < (distance.magnitude/10)+0.25f){ //se colpisce, sta fermo
float actualDamage = Random.value * damage;
player.hp -= actualDamage;
Instantiate(attackAnimation, player.transform);
messageBar.Write("Took " + actualDamage.ToString("0.0") + " damage from an arrow!", Color.red);
}
else{ //se non colpisce, avanza verso il giocatore
int direction2 = Random.Range(0, 4);
if (direction2 == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){
transform.Translate(Vector3.left);
spriteRenderer.flipX = false;
}
else if (direction2 == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){
transform.Translate(Vector3.right);
spriteRenderer.flipX = true;
}
else if (direction2 == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){
transform.Translate(Vector3.up);
spriteRenderer.sprite = upSprite;
}
else if (direction2 == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){
transform.Translate(Vector3.down);
spriteRenderer.sprite = downSprite;
}
}
}
else{
int direction = Random.Range(0, 4);
if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){
transform.Translate(Vector3.left);
spriteRenderer.flipX = false;
}
else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){
transform.Translate(Vector3.right);
spriteRenderer.flipX = true;
}
else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){
transform.Translate(Vector3.up);
spriteRenderer.sprite = upSprite;
}
else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){
transform.Translate(Vector3.down);
spriteRenderer.sprite = downSprite;
}
}
}
else {
int direction = Random.Range(0, 4);
if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){
transform.Translate(Vector3.left);
spriteRenderer.flipX = false;
}
else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){
transform.Translate(Vector3.right);
spriteRenderer.flipX = true;
}
else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){
transform.Translate(Vector3.up);
spriteRenderer.sprite = upSprite;
}
else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){
transform.Translate(Vector3.down);
spriteRenderer.sprite = downSprite;
}
}
}
public bool CanSeePlayer(){
return Vector3.Distance(player.transform.position, transform.position) < visionRange;
}
private void OnDrawGizmosSelected() {
Gizmos.color = Color.cyan;
Gizmos.DrawWireSphere(transform.position, visionRange);
}
}

View file

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