Commit 1d8a797c authored by Martin Mihálik's avatar Martin Mihálik 🔥
Browse files

Refactoring

parent 67e6bf7c
......@@ -14,6 +14,8 @@ GameObject:
- component: {fileID: 82881188109033698}
- component: {fileID: 82881188109033699}
- component: {fileID: -8143619350437993802}
- component: {fileID: 2892727529551940620}
- component: {fileID: 4294483201110357005}
m_Layer: 9
m_Name: Meteor
m_TagString: Untagged
......@@ -103,7 +105,7 @@ PolygonCollider2D:
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 0.57, y: 0.53}
oldSize: {x: 0.8142857, y: 0.75714284}
newSize: {x: 0.58, y: 0.53}
adaptiveTilingThreshold: 0.5
drawMode: 0
......@@ -241,10 +243,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3a08ab749ab9ce6478905ab3509cbb04, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Direction: {x: 0, y: 0}
m_Speed: 0
m_ExplosionPrefab: {fileID: 9034781248440383852, guid: c84a1d0620e6bee4099ba5078530b2bc, type: 3}
m_RubblePrefab: {fileID: 4362927315812235910, guid: b70e9174981d32c40861eb95d6d1b357, type: 3}
--- !u!114 &-8143619350437993802
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -257,4 +255,27 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0f51ba1a63d0af9448dc4136820d75b5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Damage: 1
--- !u!114 &2892727529551940620
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 82881188109033727}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1f41bf291c48dda4391837dffbc69e84, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &4294483201110357005
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 82881188109033727}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d929d720267b42548a5b51c79a1fc626, type: 3}
m_Name:
m_EditorClassIdentifier:
......@@ -167,8 +167,8 @@ GameObject:
- component: {fileID: 512397501}
- component: {fileID: 512397505}
- component: {fileID: 512397506}
- component: {fileID: 512397507}
- component: {fileID: 512397508}
- component: {fileID: 512397507}
m_Layer: 7
m_Name: Player
m_TagString: Untagged
......@@ -287,7 +287,7 @@ Transform:
m_Children:
- {fileID: 519420032}
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &512397505
MonoBehaviour:
......@@ -456,6 +456,36 @@ Transform:
m_Father: {fileID: 512397504}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &574392413
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 574392414}
m_Layer: 0
m_Name: Rubbles
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &574392414
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 574392413}
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: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &792207689
GameObject:
m_ObjectHideFlags: 0
......@@ -486,6 +516,36 @@ Transform:
m_Father: {fileID: 2028534472}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1344835038
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1344835039}
m_Layer: 0
m_Name: Explosions
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1344835039
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1344835038}
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: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1364465086
GameObject:
m_ObjectHideFlags: 0
......@@ -540,8 +600,12 @@ GameObject:
m_Component:
- component: {fileID: 1654006369}
- component: {fileID: 1654006368}
- component: {fileID: 1654006372}
- component: {fileID: 1654006370}
- component: {fileID: 1654006371}
- component: {fileID: 1654006373}
m_Layer: 0
m_Name: GameState
m_Name: Settings
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
......@@ -564,19 +628,7 @@ MonoBehaviour:
m_Calls: []
m_AfterPauseHooks:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 512397505}
m_TargetAssemblyTypeName: PlayerMovement, Assembly-CSharp
m_MethodName: OnPause
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_Calls: []
m_BeforeResumeHooks:
m_PersistentCalls:
m_Calls: []
......@@ -597,6 +649,76 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1654006370
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1654006367}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7ec2855d1141e014b9163816f8645ee3, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Prefab: {fileID: 82881188109033727, guid: 9c8a7026b012f2a4aa0ec85ca243f8a4, type: 3}
m_Parent: {fileID: 2028534472}
m_BaseSpeed: 10
m_BaseSpeedLevelIncrease: 5
m_BaseSpawnRate: 0.1
m_SpawnRateGrowthRate: 0.1
m_RotationsPerSecond: 1
m_Damage: 0
--- !u!114 &1654006371
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1654006367}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f8abafb856935a74fa298f3d370d91c0, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Prefab: {fileID: 9034781248440383852, guid: c84a1d0620e6bee4099ba5078530b2bc, type: 3}
m_Parent: {fileID: 1344835039}
m_StartingScale: 0
m_BaseMaxScale: 2
m_MaxScaleLevelIncrease: 0.5
m_Duration: 0.5
m_Damage: 0
--- !u!114 &1654006372
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1654006367}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9d17f1d2eb3b89f4b96011e0f4f00cac, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MeteorSettings: {fileID: 1654006370}
m_ExplosionSettings: {fileID: 1654006371}
m_RubbleSettings: {fileID: 0}
--- !u!114 &1654006373
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1654006367}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a6bc21e39c3933e4abbf7f5c5ff813e9, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Prefab: {fileID: 4362927315812235910, guid: b70e9174981d32c40861eb95d6d1b357, type: 3}
m_Parent: {fileID: 574392414}
m_SpawnCount: 3
m_SpawnShootoutForce: 300
--- !u!1 &1695424172
GameObject:
m_ObjectHideFlags: 0
......@@ -606,10 +728,10 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1695424173}
- component: {fileID: 1695424174}
- component: {fileID: 1695424176}
- component: {fileID: 1695424175}
- component: {fileID: 1695424177}
- component: {fileID: 1695424174}
m_Layer: 11
m_Name: Walls
m_TagString: Untagged
......@@ -653,7 +775,7 @@ CompositeCollider2D:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1695424172}
m_Enabled: 1
m_Enabled: 0
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
......@@ -1587,10 +1709,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 00d3d62a89544b445b4bd549d52e7f5d, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Settings: {fileID: 1654006372}
m_Source: {fileID: 106956313}
m_Target: {fileID: 792207690}
m_Parent: {fileID: 2028534472}
m_Prefab: {fileID: 82881188109033727, guid: 9c8a7026b012f2a4aa0ec85ca243f8a4, type: 3}
m_MeteorSpeed: 10
m_SpawnRate: 1
m_SpawnRateGrowthRate: 0.1
......@@ -9,10 +9,7 @@ public class DamageDealer : MonoBehaviour
return nextId++;
}
[SerializeField]
private uint m_Damage;
public uint Damage { get => m_Damage; }
public uint Damage { get; set; }
public long Id { get; set; } = -1;
private void Start()
......
fileFormatVersion: 2
guid: da92495cf7e466d4689233639513344d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
public class ExplosionController : MonoBehaviour
{
public Settings Settings { get; set; }
private bool Exhausted { get => gameObject.transform.localScale.x > Settings.Explosions.MaxScale; }
private void Update()
{
if (Exhausted)
{
Die();
}
else
{
Grow();
}
}
private void Die()
{
Destroy(gameObject);
}
private void Grow()
{
var growth = Settings.Explosions.GrowthRate * Time.deltaTime;
Vector3 growthVector = Vector2.one * growth;
gameObject.transform.localScale += growthVector;
}
}
using UnityEngine;
public class ExplosionSpawner : MonoBehaviour
{
public Settings Settings { get; set; }
public void SpawnExplosion(Vector2 position, DamageDealer sharedDealer)
{
var explosion = Instantiate(Settings.Explosions.Prefab, position, Quaternion.identity, Settings.Explosions.Parent);
explosion.transform.localScale = Vector2.one * Settings.Explosions.StartingScale;
var explosionController = explosion.GetComponent<ExplosionController>();
explosionController.Settings = Settings;
var dealer = explosion.GetComponent<DamageDealer>();
dealer.Id = sharedDealer.Id;
dealer.Damage = Settings.Explosions.Damage;
}
}
fileFormatVersion: 2
guid: 1f41bf291c48dda4391837dffbc69e84
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
public class ExplosionController : MonoBehaviour
{
public float m_MaxScale = 2f;
public float m_GrowthRate = .1f;
private void Update()
{
if (gameObject.transform.localScale.x > m_MaxScale)
{
Destroy(gameObject);
}
else
{
gameObject.transform.localScale = new Vector3(
gameObject.transform.localScale.x + m_GrowthRate * Time.deltaTime,
gameObject.transform.localScale.y + m_GrowthRate * Time.deltaTime,
1
);
}
}
}
......@@ -2,63 +2,66 @@ using UnityEngine;
public class MeteorController : MonoBehaviour
{
public Vector2 m_Direction = Vector2.zero;
public float m_Speed = 0f;
public Settings Settings { get; set; }
[SerializeField] private GameObject m_ExplosionPrefab;
[SerializeField] private GameObject m_RubblePrefab;
private Vector2 m_Direction = Vector2.down;
public Vector2 Direction { get => m_Direction; set => m_Direction = value.normalized; }
private bool Crashed { get; set; }
private SpriteRenderer m_Sprite;
private Collider2D m_Collider;
private DamageDealer m_Dealer;
private ExplosionSpawner m_ExplosionSpawner;
private RubbleSpawner m_RubbleSpawner;
private void Start()
{
m_Sprite = GetComponent<SpriteRenderer>();
m_Collider = GetComponent<Collider2D>();
m_Dealer = GetComponent<DamageDealer>();
m_Direction.Normalize();
m_ExplosionSpawner = GetComponent<ExplosionSpawner>();
m_RubbleSpawner = GetComponent<RubbleSpawner>();
}
private void Move()
private void FixedUpdate()
{
Vector3 movement = m_Direction * m_Speed * Time.fixedDeltaTime;
gameObject.transform.position += movement;
if (!Crashed)
{
Move();
Rotate();
}
}
private void Rotate()
private void OnTriggerEnter2D(Collider2D other)
{
gameObject.transform.Rotate(Vector3.forward * 360f * Time.fixedDeltaTime);
Crash();
}
private void FixedUpdate()
private void Move()
{
Move();
Rotate();
}
Vector3 movement = Direction * Settings.Meteors.Speed * Time.fixedDeltaTime;
public void OnTriggerEnter2D(Collider2D other)
{
Crash();
gameObject.transform.position += movement;
}
private void Crash()
private void Rotate()
{
Stop();
Explode();
gameObject.transform.Rotate(Vector3.forward * Settings.Meteors.RotationSpeed * Time.fixedDeltaTime);
}
private void Stop()
private void Crash()
{
m_Speed = 0f;
Crashed = true;
Explode();
}
private void Explode()
{
SpawnExplosion(gameObject.transform.position, 2f, 4f, gameObject.transform.parent, m_Dealer);
SpawnRubble(3, gameObject.transform.position, m_Collider.bounds.extents, 300f, gameObject.transform.parent);
m_ExplosionSpawner.SpawnExplosion(gameObject.transform.position, m_Dealer);
m_RubbleSpawner.SpawnRubbles(gameObject.transform.position, m_Collider.bounds);
Disappear();
}
......@@ -68,39 +71,4 @@ public class MeteorController : MonoBehaviour
m_Sprite.enabled = false;
m_Collider.enabled = false;
}
private void SpawnExplosion(Vector2 position, float maxScale, float growthRate, Transform parent, DamageDealer sharedDealer)
{
var explosion = Instantiate(m_ExplosionPrefab, position, Quaternion.identity, parent);
var controller = explosion.GetComponent<ExplosionController>();
controller.m_MaxScale = maxScale;
controller.m_GrowthRate = growthRate;
var dealer = explosion.GetComponent<DamageDealer>();
dealer.Id = sharedDealer.Id;
}
private void SpawnRubble(uint count, Vector2 basePosition, Vector2 bbox, float force, Transform parent)
{
for (uint i = 0; i < count; ++i)
{
var offset = new Vector2(Random.Range(-bbox.x / 2, bbox.x / 2), Random.Range(-bbox.y / 2, bbox.y / 2));
var startingPoint = basePosition + offset;
SpawnSingleRubble(startingPoint, (startingPoint - basePosition).normalized, force, parent);
}
}
private void SpawnSingleRubble(Vector2 startingPosition, Vector2 direction, float force, Transform parent)
{
var rubble = Instantiate(m_RubblePrefab, startingPosition, Quaternion.identity, parent);
var rubbleBody = rubble.GetComponent<Rigidbody2D>();
rubbleBody.AddForce(direction * force);
}
}
......@@ -2,55 +2,49 @@ using UnityEngine;
public class MeteorSpawner : MonoBehaviour
{
[SerializeField] private Settings m_Settings;
[SerializeField] private Transform m_Source;
[SerializeField] private Transform m_Target;
[SerializeField] private Transform m_Parent;
[SerializeField] private GameObject m_Prefab;
private bool m_Running;
[SerializeField] private float m_MeteorSpeed;
[SerializeField] private float m_SpawnRate;
[SerializeField] private float m_SpawnRateGrowthRate;
public float MeteorSpeed { get; set; }
private float SpawnPeriod { get => 1 / m_SpawnRate; }
private Settings Settings { get => m_Settings; }
private void Start()
{
Resume();
}
private void Update()
{
m_SpawnRate += m_SpawnRateGrowthRate * Time.deltaTime;
SpawnMeteors();
}
private void SpawnMeteors()
{
if (!m_Running)
{
return;
}