Merge branch 'master' into enemy-unstuck

This commit is contained in:
Denis-Cosmin Nutiu 2019-08-09 15:33:29 +03:00 committed by GitHub
commit 1ce89ad8bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 2281 additions and 74 deletions

2
.gitignore vendored
View file

@ -143,6 +143,7 @@ fabric.properties
# TextMesh Pro files # TextMesh Pro files
[Aa]ssets/TextMesh*Pro/ [Aa]ssets/TextMesh*Pro/
[Aa]ssets/TextMesh*
# Visual Studio cache directory # Visual Studio cache directory
.vs/ .vs/
@ -536,6 +537,7 @@ MigrationBackup/
# Ignore editor plugins # Ignore editor plugins
Assets/Plugins/Editor* Assets/Plugins/Editor*
[Aa]ssets/Plugins/Editor/JetBrains/* [Aa]ssets/Plugins/Editor/JetBrains/*
Assets/TextMesh Pro.meta
# Don't store keystores on Github # Don't store keystores on Github
*.keystore *.keystore

View file

@ -111,6 +111,7 @@ GameObject:
- component: {fileID: 1330784298487411849} - component: {fileID: 1330784298487411849}
- component: {fileID: 3670963333241729696} - component: {fileID: 3670963333241729696}
- component: {fileID: 7110750718968962680} - component: {fileID: 7110750718968962680}
- component: {fileID: 430766997717814334}
m_Layer: 14 m_Layer: 14
m_Name: Dumb m_Name: Dumb
m_TagString: Enemy m_TagString: Enemy
@ -192,3 +193,15 @@ BoxCollider2D:
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 0.9, y: 0.9} m_Size: {x: 0.9, y: 0.9}
m_EdgeRadius: 0 m_EdgeRadius: 0
--- !u!114 &430766997717814334
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:

View file

@ -0,0 +1,175 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1538228739935925895
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1538228739935925892}
- component: {fileID: 1538228739935925893}
- component: {fileID: 1538228739935925894}
- component: {fileID: 1538228739935925891}
m_Layer: 14
m_Name: DummyEnemy
m_TagString: Enemy
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1538228739935925892
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1538228739935925895}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 5, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1538228741088485487}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!50 &1538228739935925893
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1538228739935925895}
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: 6200000, guid: dc8eb6133faaf45f6820487d0d28b47f, type: 2}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 4
--- !u!114 &1538228739935925894
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1538228739935925895}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 29972d94a069eef40924fbb80ca2fb24, type: 3}
m_Name:
m_EditorClassIdentifier:
OneDirection: {x: -1, y: 0}
--- !u!61 &1538228739935925891
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1538228739935925895}
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.9}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.5, y: 0.9}
m_EdgeRadius: 0
--- !u!1 &1538228741088485488
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1538228741088485487}
- component: {fileID: 1538228741088485486}
m_Layer: 14
m_Name: Sprite
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1538228741088485487
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1538228741088485488}
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: 1538228739935925892}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &1538228741088485486
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1538228741088485488}
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

View file

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

View file

@ -299,7 +299,7 @@ PrefabInstance:
- target: {fileID: 485484359815032853, guid: a977eab75b5324ec4b659c2e2a0e9cfd, - target: {fileID: 485484359815032853, guid: a977eab75b5324ec4b659c2e2a0e9cfd,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: 10.969402 value: 7.7734566
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 485484359815032853, guid: a977eab75b5324ec4b659c2e2a0e9cfd, - target: {fileID: 485484359815032853, guid: a977eab75b5324ec4b659c2e2a0e9cfd,
type: 3} type: 3}
@ -309,7 +309,7 @@ PrefabInstance:
- target: {fileID: 485484359815032853, guid: a977eab75b5324ec4b659c2e2a0e9cfd, - target: {fileID: 485484359815032853, guid: a977eab75b5324ec4b659c2e2a0e9cfd,
type: 3} type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: -10 value: -2.7893844
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 485484359815032853, guid: a977eab75b5324ec4b659c2e2a0e9cfd, - target: {fileID: 485484359815032853, guid: a977eab75b5324ec4b659c2e2a0e9cfd,
type: 3} type: 3}

File diff suppressed because it is too large Load diff

View file

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

View file

@ -33,7 +33,7 @@ public abstract class EnemyBase : MonoBehaviour, IExplosable
{ {
Unstuck(); Unstuck();
} }
Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime); Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction);
} }
public void OnTriggerEnter2D(Collider2D other) public void OnTriggerEnter2D(Collider2D other)

View file

@ -0,0 +1,18 @@
namespace src.Enemy
{
public class CollisionMovementEnemy : EnemyBase
/* Enemy that will change direction only on collision. */
{
protected new void Start()
{
Speed = 4f;
base.Start();
}
protected new void FixedUpdate()
{
base.FixedUpdate();
}
}
}

View file

@ -1,46 +0,0 @@
using UnityEngine;
using src.Helpers;
public class DumbEnemy : EnemyBase
{
protected new void Start()
{
Speed = 4f;
base.Start();
}
protected new void FixedUpdate()
{
if (gameStateManager.IsGamePaused || gameStateManager.IsPlayerMovementForbidden) {return;}
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 + Speed * Time.deltaTime * Direction);
}
}
else
{
Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction);
}
}
private bool RandomChange()
{
var random = new System.Random();
var randomNumber = random.Next(0, 100);
return randomNumber <= 25;
}
private void HandleChangeDirection()
{
Direction = ChooseRandomExceptCertainDirection(Direction);
MoveToCenterOfTheCell();
Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction);
}
}

View file

@ -1,16 +0,0 @@
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 FixedUpdate()
{
base.FixedUpdate();
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: f54d1bd14bd3ca042bd867b519fee8cc guid: 738f4be39c8d33d4dbfe91e24b6b1b63
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

View file

@ -0,0 +1,27 @@
using UnityEngine;
namespace Assets.Scripts.src.Enemy.Dummy
{
//This kind of enemy is used just for testing purposes
//This enemy will go just in one direction or stays in place
//To make it stay in place, don't assign any direction in OneDirection slot or assign Vector2.zero
public class OneDirectionEnemy : EnemyBase
{
public Vector2 OneDirection = Vector2.zero;
protected new void Start()
{
Speed = 4.0f;
Rigidbody2d = GetComponent<Rigidbody2D>();
}
protected new void FixedUpdate()
{
if (OneDirection != Vector2.zero)
{
if (gameStateManager.IsGamePaused || gameStateManager.IsPlayerMovementForbidden) { return; }
Rigidbody2d.MovePosition(Rigidbody2d.position + OneDirection * Speed * Time.deltaTime);
}
}
}
}

View file

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

View file

@ -0,0 +1,53 @@
using System;
using src.Helpers;
using UnityEngine;
namespace src.Enemy
{
public class RandomMovementEnemy : EnemyBase
{
/* Enemy that will move randomly */
protected new void Start()
{
Speed = 4f;
base.Start();
}
protected new void FixedUpdate()
{
var pos = transform.position;
var x = pos.x;
var y = pos.y;
if (gameStateManager.IsGamePaused || gameStateManager.IsPlayerMovementForbidden) { return; }
if (Math.Abs(x - Mathf.Floor(x)) < 0.1 && Math.Abs(y - Mathf.Floor(y)) < 0.1)
{
if (RandomChange())
{
HandleChangeDirection();
}
else
{
Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction);
}
}
else
{
Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction);
}
}
private bool RandomChange()
{
var random = new System.Random();
var randomNumber = random.Next(0, 100);
return randomNumber <= 25;
}
private void HandleChangeDirection()
{
Direction = ChooseRandomExceptCertainDirection(Direction);
MoveToCenterOfTheCell();
Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction);
}
}
}

View file

@ -6,15 +6,14 @@ using src.Level.src.Level;
using src.Managers; using src.Managers;
using src.Wall; using src.Wall;
using UnityEngine; using UnityEngine;
using Random = UnityEngine.Random;
namespace src.Level namespace src.Level
{ {
public class LevelManager : GameplayComponent, IDynamicLevelData public class LevelManager : GameplayComponent, IDynamicLevelData
{ {
/** Extracted them here for easy to change reason */ /** Safe-zone coordinates to prevent enemies to instantly kill you*/
private const int XMaxEnemyPosition = 5; private const int XMaxEnemyPosition = 4;
private const int YMinEnemyPosition = -5; private const int YMinEnemyPosition = -4;
public Count DestructibleWallCount public Count DestructibleWallCount
{ {
@ -206,8 +205,8 @@ namespace src.Level
private void SetupLevelEnemies() private void SetupLevelEnemies()
{ {
var numberOfEnemiesToPlace = _enemyCount.RandomIntRange(); var numberOfEnemiesToPlace = _enemyCount.RandomIntRange();
_freeGridPositions.ShuffleList();
_freeGridPositions.RemoveAll(pos => pos.x <= XMaxEnemyPosition && pos.y >= YMinEnemyPosition); _freeGridPositions.RemoveAll(pos => pos.x <= XMaxEnemyPosition && pos.y >= YMinEnemyPosition);
_freeGridPositions.ShuffleList();
foreach (var nextPosition in _freeGridPositions) foreach (var nextPosition in _freeGridPositions)
{ {
if (numberOfEnemiesToPlace == 0) if (numberOfEnemiesToPlace == 0)
@ -219,14 +218,13 @@ namespace src.Level
} }
} }
private bool PlaceEnemy(Vector3 position) private void PlaceEnemy(Vector3 position)
{ {
DebugHelper.LogVerbose($"PlaceEnemy: x:{position.x} y:{position.y}"); DebugHelper.LogVerbose($"PlaceEnemy: x:{position.x} y:{position.y}");
var randomEnemy = _enemiesPrefab.ChoseRandom(); var randomEnemy = _enemiesPrefab.ChoseRandom();
var instance = Instantiate(randomEnemy, position, Quaternion.identity); var instance = Instantiate(randomEnemy, position, Quaternion.identity);
_enemies.Add(instance);
instance.transform.SetParent(boardHolder); instance.transform.SetParent(boardHolder);
return true; _enemies.Add(instance);
} }
/* Initializes the level. */ /* Initializes the level. */