Partial Dumb & dumber enemies

This commit is contained in:
Andrei Gavra 2019-06-22 11:53:01 +03:00
parent cc48a67bad
commit 00065089dd
22 changed files with 2757 additions and 299 deletions

143
Assets/DevMocks/Dumb.prefab Normal file
View file

@ -0,0 +1,143 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &7795087027144463245
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3746656334748574901}
- component: {fileID: 8735042184812970439}
- component: {fileID: 1330784298487411849}
- component: {fileID: 3670963333241729696}
- component: {fileID: 7110750718968962680}
m_Layer: 14
m_Name: Dumb
m_TagString: Enemy
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3746656334748574901
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7795087027144463245}
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!212 &8735042184812970439
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7795087027144463245}
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: 0
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: 21300000, guid: 55fee6a02b8d5bc4e993261a717e89cc, type: 3}
m_Color: {r: 1, g: 0.14877324, b: 0, 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: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!114 &1330784298487411849
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7795087027144463245}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1ec64748dfd5f8948996e97a49538538, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!50 &3670963333241729696
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7795087027144463245}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 0
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 4
--- !u!61 &7110750718968962680
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7795087027144463245}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0.5, y: 0.5}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.9, y: 0.9}
m_EdgeRadius: 0

View file

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

View file

@ -0,0 +1,143 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4346602752014574748
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 644191348100887617}
- component: {fileID: 2013141934724497034}
- component: {fileID: 2122485943191788385}
- component: {fileID: 3292464784200894759}
- component: {fileID: 2823282795561844331}
m_Layer: 14
m_Name: Dumber
m_TagString: Enemy
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &644191348100887617
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4346602752014574748}
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!212 &2013141934724497034
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4346602752014574748}
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: 0
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: 21300000, guid: 55fee6a02b8d5bc4e993261a717e89cc, type: 3}
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: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!114 &2122485943191788385
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4346602752014574748}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f2a42cb28de7d67479c1c852ea36e205, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!50 &3292464784200894759
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4346602752014574748}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 0
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 4
--- !u!61 &2823282795561844331
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4346602752014574748}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0.5, y: 0.5}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.9, y: 0.9}
m_EdgeRadius: 0

View file

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

BIN
Assets/DevMocks/enemy1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 515 B

View file

@ -0,0 +1,99 @@
fileFormatVersion: 2
guid: 55fee6a02b8d5bc4e993261a717e89cc
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 9
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: 0
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 6
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 32
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: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5d310d0120df55e4c86df3d39d7addcc
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View file

@ -63,3 +63,6 @@ MonoBehaviour:
destructibleWallPrefabs:
- {fileID: 4177940729222266681, guid: da559e681f8d34d58bb5f3457045664a, type: 3}
- {fileID: 8729402555587492036, guid: 7e54504f1e1de4334be2e6a115b838c2, type: 3}
enemiesPrefab:
- {fileID: 4346602752014574748, guid: e719de70e335f4e49ae40cc6731309d4, type: 3}
- {fileID: 7795087027144463245, guid: fe8fb4e4a7e127648b306469b723d81e, type: 3}

File diff suppressed because it is too large Load diff

View file

@ -8168,7 +8168,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 10.383259, y: -4.0430503, z: -10}
m_LocalPosition: {x: 7.777341, y: -4.0430503, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
@ -8288,105 +8288,6 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 6843575829779162303}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1778702655
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1778702656}
- component: {fileID: 1778702657}
- component: {fileID: 1778702658}
m_Layer: 15
m_Name: Sprite
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1778702656
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1778702655}
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: 1352658977}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &1778702657
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1778702655}
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: 0
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: 21300064, guid: acfc12ff3498641aa93645b517a11af4, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 2, y: 2}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!95 &1778702658
Animator:
serializedVersion: 3
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1778702655}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: dc9347e7518ed4709b6cacd42554e650, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!1001 &2013742123
PrefabInstance:
m_ObjectHideFlags: 0
@ -8547,6 +8448,11 @@ PrefabInstance:
propertyPath: m_Name
value: Player
objectReference: {fileID: 0}
- target: {fileID: 6843575828445418657, guid: d3055091a17dc4aa1accf2e33ccef144,
type: 3}
propertyPath: m_TagString
value: Player
objectReference: {fileID: 0}
- target: {fileID: 6843575828445418657, guid: d3055091a17dc4aa1accf2e33ccef144,
type: 3}
propertyPath: m_Layer
@ -8607,47 +8513,5 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6843575828445418656, guid: d3055091a17dc4aa1accf2e33ccef144,
type: 3}
propertyPath: respawnPosition
value:
objectReference: {fileID: 185746015}
- target: {fileID: 6843575828445418655, guid: d3055091a17dc4aa1accf2e33ccef144,
type: 3}
propertyPath: m_SortingOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6843575828445418655, guid: d3055091a17dc4aa1accf2e33ccef144,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6843575828445418652, guid: d3055091a17dc4aa1accf2e33ccef144,
type: 3}
propertyPath: m_Offset.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 6843575828445418652, guid: d3055091a17dc4aa1accf2e33ccef144,
type: 3}
propertyPath: m_Offset.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 6843575828445418652, guid: d3055091a17dc4aa1accf2e33ccef144,
type: 3}
propertyPath: m_Size.x
value: 0.8
objectReference: {fileID: 0}
- target: {fileID: 6843575828445418652, guid: d3055091a17dc4aa1accf2e33ccef144,
type: 3}
propertyPath: m_EdgeRadius
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6843575828445418652, guid: d3055091a17dc4aa1accf2e33ccef144,
type: 3}
propertyPath: m_Size.y
value: 0.8
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 6843575828445418655, guid: d3055091a17dc4aa1accf2e33ccef144, type: 3}
- {fileID: 6843575828445418651, guid: d3055091a17dc4aa1accf2e33ccef144, type: 3}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d3055091a17dc4aa1accf2e33ccef144, type: 3}

View file

@ -31,8 +31,7 @@ namespace src.Ammo
StartCoroutine(CreateExplosions(Vector3.right));
_exploded = true;
Destroy(gameObject, 0.3f);
_bombsUtil.RemoveBomb(transform.position);
Destroy(gameObject, 0.55f);
}
private IEnumerator CreateExplosions(Vector3 direction)
@ -40,8 +39,9 @@ namespace src.Ammo
var currentPosition = transform.position;
for (var i = 1; i < _bombsUtil.Power; i++)
{
var distance = i == _bombsUtil.Power ? i : i - 0.5f;
var hit = Physics2D.Raycast(new Vector2(currentPosition.x + 0.5f,
currentPosition.y + 0.5f), direction, i, 1 << 8);
currentPosition.y + 0.5f), direction, distance, 1 << 8);
if (!hit.collider)
{
@ -73,5 +73,10 @@ namespace src.Ammo
CancelInvoke(nameof(Explode));
Explode();
}
public void OnDestroy()
{
_bombsUtil.RemoveBomb(transform.position);
}
}
}

View file

@ -0,0 +1,62 @@
using UnityEngine;
using src.Helpers;
public abstract class EnemyBase : MonoBehaviour, IExplosable
{
protected Vector2[] _directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right };
protected Rigidbody2D Rigidbody2d { get; set; }
protected float Speed { get; set; }
protected Vector2 Direction { get; set; }
// Start is called before the first frame update
protected void Start()
{
Direction = _directions.ChoseRandom();
Rigidbody2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
protected void Update()
{
Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime);
}
public void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Explosion"))
{
onExplosion();
}
}
public void onExplosion()
{
Destroy(gameObject);
}
public void OnCollisionEnter2D(Collision2D col)
{
MoveToCenterOfTheCell();
Direction = _directions.ChoseRandomExcept(Direction);
}
protected void MoveToCenterOfTheCell()
{
var absX = Mathf.RoundToInt(transform.position.x);
var absY = Mathf.RoundToInt(transform.position.y);
Vector2 position = new Vector2(absX, absY);
transform.SetPositionAndRotation(position, Quaternion.identity);
}
protected Vector2 ChooseRandomDirection()
{
return _directions.ChoseRandom();
}
protected Vector2 ChooseRandomExceptCertainDirection(Vector2 direction)
{
return _directions.ChoseRandomExcept(direction);
}
}

View file

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

View file

@ -22,11 +22,20 @@ namespace src.Base
{
onExplosion();
}
if (other.CompareTag("Enemy"))
{
OnContactWithEnemy();
}
}
public void onExplosion()
{
DebugHelper.LogInfo("Player hit by explosion");
}
private void OnContactWithEnemy()
{
DebugHelper.LogInfo("Player hit by enemy");
}
}
}

View file

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

View file

@ -0,0 +1,45 @@
using UnityEngine;
using src.Helpers;
public class DumbEnemy : EnemyBase
{
protected new void Start()
{
Speed = 4f;
base.Start();
}
protected new void Update()
{
if (transform.position.x == Mathf.Floor(transform.position.x) && transform.position.y == Mathf.Floor(transform.position.y))
{
if (RandomChange())
{
HandleChangeDirection();
}
else
{
Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime);
}
}
else
{
Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime);
}
}
private bool RandomChange()
{
System.Random random = new System.Random();
int randomNumber = random.Next(0, 100);
return randomNumber <= 25;
}
private void HandleChangeDirection()
{
DebugHelper.LogInfo("Direction randomly changed");
Direction = ChooseRandomExceptCertainDirection(Direction);
MoveToCenterOfTheCell();
Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime);
}
}

View file

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

View file

@ -0,0 +1,16 @@
public class DumberEnemy : EnemyBase
{
//Momentan lasam asa, o sa difere probabil la animatii and stats, nu stiu sigur
protected new void Start()
{
Speed = 4f;
base.Start();
}
protected new void Update()
{
base.Update();
}
}

View file

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

View file

@ -1,3 +1,4 @@
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
@ -10,5 +11,29 @@ namespace src.Helpers
var randomIndex = Mathf.FloorToInt(Random.Range(0, arr.Length));
return arr[randomIndex];
}
public static T ChoseRandomExcept<T>(this T[] arr, T exceptValue)
{
T value;
do
{
var randomIndex = Mathf.FloorToInt(Random.Range(0, arr.Length));
value = arr[randomIndex];
} while (exceptValue.Equals(value));
return value;
}
public static T ChoseRandomExcept<T>(this T[] arr, List<T> exceptValue)
{
T value;
do
{
var randomIndex = Mathf.FloorToInt(Random.Range(0, arr.Length));
value = arr[randomIndex];
} while (exceptValue.Contains(value));
return value;
}
}
}

View file

@ -51,6 +51,7 @@ namespace src.Managers
public Transform startPosition;
public GameObject indestructibleWallPrefab;
public GameObject[] destructibleWallPrefabs;
public GameObject[] enemiesPrefab;
/* Specifies how many objects we want per level. */
private Count _destructibleWallCount = new Count(150, 350);
@ -64,6 +65,7 @@ namespace src.Managers
/* Holds the available positions */
private readonly List<Vector3> _freeGridPositions = new List<Vector3>();
private readonly List<GameObject> _destructibleWalls = new List<GameObject>();
private readonly List<GameObject> _enemies = new List<GameObject>();
private void SetupUpgrades()
{
@ -142,7 +144,7 @@ namespace src.Managers
private void SetupLevelDestructibleWalls()
{
var numberOfDestructilbeWallsToPlace = _destructibleWallCount.RandomIntRange();
List<Vector3> usedPositions = new List<Vector3>();
_freeGridPositions.ShuffleList();
foreach (var nextPosition in _freeGridPositions)
{
@ -150,10 +152,14 @@ namespace src.Managers
{
break;
}
usedPositions.Add(nextPosition);
PlaceDestructibleTile(nextPosition);
numberOfDestructilbeWallsToPlace -= 1;
}
foreach (var usedPosition in usedPositions)
{
_freeGridPositions.Remove(usedPosition);
}
}
private void PlaceDestructibleTile(Vector3 position)
@ -171,7 +177,10 @@ namespace src.Managers
var absX = Mathf.RoundToInt(x);
var absY = Mathf.RoundToInt(y);
if (absX % 2 == 0 || absY % 2 == 0) return false;
if (absX % 2 == 0 || absY % 2 == 0)
{
return false;
}
var instance =
Instantiate(indestructibleWallPrefab, new Vector3(x, y, 0f), Quaternion.identity);
@ -179,11 +188,39 @@ namespace src.Managers
return true;
}
private void SetupLevelEnemies()
{
var numberOfEnemiesToPlace = _enemyCount.RandomIntRange();
_freeGridPositions.ShuffleList();
foreach (var nextPosition in _freeGridPositions)
{
if (numberOfEnemiesToPlace == 0)
{
break;
}
PlaceEnemy(nextPosition);
numberOfEnemiesToPlace -= 1;
}
}
private bool PlaceEnemy(Vector3 position)
{
DebugHelper.LogInfo($"PlaceEnemy: x:{position.x} y:{position.y}");
var randomEnemy = enemiesPrefab.ChoseRandom();
var instance = Instantiate(randomEnemy, position, Quaternion.identity);
_enemies.Add(instance);
instance.transform.SetParent(boardHolder);
return true;
}
/* Initializes the level. */
public void InitLevel()
{
InitBoard();
SetupLevelDestructibleWalls();
SetupLevelEnemies();
SetupExit();
SetupUpgrades();
}

View file

@ -53,4 +53,4 @@ Physics2DSettings:
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
m_LayerCollisionMatrix: fffbffffff7bffffff7bffffffffffffff7bfffffffbfffffffffffffffffffffffbffffffffffffc87affffffffffffffffffffffffffffffffffffe9fbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: fffbffffff3bffffff3bffffffffffffff3bfffffffbfffffffffffffffffffffffbffffffffffffc83affffffffffffffffffffffffffffe93bffffe9bbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

View file

@ -6,6 +6,7 @@ TagManager:
tags:
- Explosion
- Bomb
- Enemy
layers:
- Default
- TransparentFX
@ -21,7 +22,7 @@ TagManager:
-
-
-
-
- Enemy
- Player
-
-