KerelOlivier
3 years ago
16 changed files with 462 additions and 76 deletions
@ -1,30 +1,33 @@
@@ -1,30 +1,33 @@
|
||||
using System; |
||||
using Enemies.States; |
||||
using UnityEngine; |
||||
|
||||
namespace Enemies |
||||
{ |
||||
public class Enemy : MonoBehaviour |
||||
public abstract class Enemy : MonoBehaviour |
||||
{ |
||||
public float health = 10f; |
||||
public float attackPower = 1; |
||||
public enum States |
||||
{ |
||||
Idle, |
||||
Target, |
||||
Path, |
||||
Follow, |
||||
Attack, |
||||
Die |
||||
} |
||||
|
||||
public States? currentState; |
||||
public float health { get; set; } = 10f; |
||||
public float damage = 1; |
||||
|
||||
public GameObject target { get; set; } |
||||
private float speed = 2f; |
||||
public float speed = 2f; |
||||
public float viewRange = 5f; |
||||
public float attackRange = 1f; |
||||
|
||||
public IState state { get; set; } |
||||
|
||||
public abstract void SwitchState(States s); |
||||
|
||||
// Start is called before the first frame update |
||||
void Start() |
||||
{ |
||||
Destroy(gameObject, 10f); |
||||
|
||||
} |
||||
|
||||
// Update is called once per frame |
||||
void Update() |
||||
{ |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
@ -1,27 +1,29 @@
@@ -1,27 +1,29 @@
|
||||
using Enemies.States; |
||||
using UnityEngine; |
||||
|
||||
namespace Enemies |
||||
{ |
||||
public class AttackState: IState |
||||
public class AttackState : IState |
||||
{ |
||||
private Enemy context; |
||||
|
||||
public AttackState(Enemy context) |
||||
{ |
||||
this.context = context; |
||||
} |
||||
|
||||
public void Enter() |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
Debug.Log("Entering Attack State"); |
||||
context.currentState = Enemy.States.Attack; |
||||
} |
||||
|
||||
public void Execute() |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
} |
||||
|
||||
public void Exit() |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -1,26 +1,29 @@
@@ -1,26 +1,29 @@
|
||||
using UnityEngine; |
||||
|
||||
namespace Enemies.States |
||||
{ |
||||
public class DieState:IState |
||||
public class DieState : IState |
||||
{ |
||||
private Enemy context; |
||||
|
||||
public DieState(Enemy context) |
||||
{ |
||||
this.context = context; |
||||
} |
||||
|
||||
public void Enter() |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
Debug.Log("Enemy died"); |
||||
context.currentState = Enemy.States.Die; |
||||
Object.Destroy(context.gameObject); |
||||
} |
||||
|
||||
public void Execute() |
||||
{ |
||||
Object.Destroy(context.gameObject); |
||||
} |
||||
|
||||
public void Exit() |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -1,27 +1,36 @@
@@ -1,27 +1,36 @@
|
||||
using Enemies.States; |
||||
using UnityEngine; |
||||
|
||||
namespace Enemies |
||||
{ |
||||
public class PathState: IState |
||||
public class PathState : IState |
||||
{ |
||||
private Enemy context; |
||||
private readonly Enemy context; |
||||
|
||||
public PathState(Enemy context) |
||||
{ |
||||
this.context = context; |
||||
} |
||||
|
||||
public void Enter() |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
Debug.Log("Entering Path State"); |
||||
context.currentState = Enemy.States.Path; |
||||
} |
||||
|
||||
public void Execute() |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
//Determine direction to target |
||||
Vector2 direction = context.target.transform.position - context.transform.position; |
||||
|
||||
//Move in desired direction |
||||
context.GetComponent<Rigidbody2D>().MovePosition((Vector2)context.transform.position + direction.normalized * context.speed * Time.deltaTime); |
||||
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; |
||||
context.transform.rotation = Quaternion.Euler(0, 0, angle); |
||||
} |
||||
|
||||
public void Exit() |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
using Enemies.States; |
||||
using UnityEngine; |
||||
|
||||
namespace Enemies |
||||
{ |
||||
public class TargetState: IState |
||||
{ |
||||
private readonly Enemy context; |
||||
public TargetState(Enemy context) |
||||
{ |
||||
this.context = context; |
||||
} |
||||
|
||||
public void Enter() |
||||
{ |
||||
Debug.Log("Entering Target State"); |
||||
context.currentState = Enemy.States.Target; |
||||
|
||||
//Find nearest target |
||||
GameObject player = GameObject.FindWithTag("Player"); |
||||
GameObject house = GameObject.FindWithTag("Base"); |
||||
GameObject nearest = player; ; |
||||
if (Vector3.Distance(player.transform.position, context.transform.position) > Vector3.Distance(house.transform.position, context.transform.position)) |
||||
{ |
||||
nearest = house; |
||||
} |
||||
|
||||
context.target = nearest; |
||||
} |
||||
|
||||
public void Execute() |
||||
{ |
||||
} |
||||
|
||||
public void Exit() |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -1,28 +0,0 @@
@@ -1,28 +0,0 @@
|
||||
using Enemies.States; |
||||
|
||||
namespace Enemies |
||||
{ |
||||
public class TargetingState: IState |
||||
{ |
||||
private Enemy context; |
||||
public TargetingState(Enemy context) |
||||
{ |
||||
this.context = context; |
||||
} |
||||
|
||||
public void Enter() |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
} |
||||
|
||||
public void Execute() |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
} |
||||
|
||||
public void Exit() |
||||
{ |
||||
throw new System.NotImplementedException(); |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 369 B |
@ -0,0 +1,120 @@
@@ -0,0 +1,120 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 24871896504fb6e6bae3b539a5f6e0f2 |
||||
TextureImporter: |
||||
internalIDToNameTable: [] |
||||
externalObjects: {} |
||||
serializedVersion: 11 |
||||
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 |
||||
vTOnly: 0 |
||||
grayScaleToAlpha: 0 |
||||
generateCubemap: 6 |
||||
cubemapConvolution: 0 |
||||
seamlessCubemap: 0 |
||||
textureFormat: 1 |
||||
maxTextureSize: 2048 |
||||
textureSettings: |
||||
serializedVersion: 2 |
||||
filterMode: 0 |
||||
aniso: 1 |
||||
mipBias: 0 |
||||
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: 64 |
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
||||
spriteGenerateFallbackPhysicsShape: 1 |
||||
alphaUsage: 1 |
||||
alphaIsTransparency: 1 |
||||
spriteTessellationDetail: -1 |
||||
textureType: 8 |
||||
textureShape: 1 |
||||
singleChannelComponent: 0 |
||||
flipbookRows: 1 |
||||
flipbookColumns: 1 |
||||
maxTextureSizeSet: 0 |
||||
compressionQualitySet: 0 |
||||
textureFormatSet: 0 |
||||
ignorePngGamma: 0 |
||||
applyGammaDecoding: 0 |
||||
platformSettings: |
||||
- serializedVersion: 3 |
||||
buildTarget: DefaultTexturePlatform |
||||
maxTextureSize: 2048 |
||||
resizeAlgorithm: 0 |
||||
textureFormat: -1 |
||||
textureCompression: 1 |
||||
compressionQuality: 50 |
||||
crunchedCompression: 0 |
||||
allowsAlphaSplitting: 0 |
||||
overridden: 0 |
||||
androidETC2FallbackOverride: 0 |
||||
forceMaximumCompressionQuality_BC6H_BC7: 0 |
||||
- serializedVersion: 3 |
||||
buildTarget: Standalone |
||||
maxTextureSize: 2048 |
||||
resizeAlgorithm: 0 |
||||
textureFormat: -1 |
||||
textureCompression: 1 |
||||
compressionQuality: 50 |
||||
crunchedCompression: 0 |
||||
allowsAlphaSplitting: 0 |
||||
overridden: 0 |
||||
androidETC2FallbackOverride: 0 |
||||
forceMaximumCompressionQuality_BC6H_BC7: 0 |
||||
- serializedVersion: 3 |
||||
buildTarget: WebGL |
||||
maxTextureSize: 2048 |
||||
resizeAlgorithm: 0 |
||||
textureFormat: -1 |
||||
textureCompression: 1 |
||||
compressionQuality: 50 |
||||
crunchedCompression: 0 |
||||
allowsAlphaSplitting: 0 |
||||
overridden: 0 |
||||
androidETC2FallbackOverride: 0 |
||||
forceMaximumCompressionQuality_BC6H_BC7: 0 |
||||
spriteSheet: |
||||
serializedVersion: 2 |
||||
sprites: [] |
||||
outline: [] |
||||
physicsShape: [] |
||||
bones: [] |
||||
spriteID: 5e97eb03825dee720800000000000000 |
||||
internalID: 0 |
||||
vertices: [] |
||||
indices: |
||||
edges: [] |
||||
weights: [] |
||||
secondaryTextures: [] |
||||
spritePackingTag: |
||||
pSDRemoveMatte: 0 |
||||
pSDShowRemoveMatteOption: 0 |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
Loading…
Reference in new issue