Commit 38d75978 authored by Martin Mihálik's avatar Martin Mihálik 🔥
Browse files

WorldRepeating

parent 86dc2076
fileFormatVersion: 2
guid: 9bfefda059bdf1c4c860aac386a71440
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
public class LevelUpController : MonoBehaviour
{
[SerializeField] private UnityEvent m_PreLevelUpHooks;
[SerializeField] private UnityEvent m_PostLevelUpHooks;
private void OnTriggerEnter2D(Collider2D collision)
{
m_PreLevelUpHooks.Invoke();
MoveObjectsDown();
m_PostLevelUpHooks.Invoke();
}
private void MoveObjectsDown()
{
foreach (var repeatable in GameObject.FindGameObjectsWithTag("Repeatable"))
{
repeatable.transform.position += Vector3.down * 30;
}
}
}
fileFormatVersion: 2
guid: 223169c625d5d394eb6db0c33dcff3a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -15,7 +15,7 @@ GameObject:
- component: {fileID: 4637414488442095651}
m_Layer: 10
m_Name: Explosion
m_TagString: Untagged
m_TagString: Explosion
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......@@ -113,8 +113,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5dfe97cb370f7c54e8ee7776ed7bedc3, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MaxScale: 0
m_GrowthRate: 0
--- !u!114 &4637414488442095651
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -127,4 +125,3 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0f51ba1a63d0af9448dc4136820d75b5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Damage: 1
......@@ -18,7 +18,7 @@ GameObject:
- component: {fileID: 4294483201110357005}
m_Layer: 9
m_Name: Meteor
m_TagString: Untagged
m_TagString: Meteor
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......
......@@ -14,7 +14,7 @@ GameObject:
- component: {fileID: 4362927315812235909}
m_Layer: 6
m_Name: Rubble
m_TagString: Untagged
m_TagString: Rubble
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......@@ -102,7 +102,7 @@ PolygonCollider2D:
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 0.55, y: 0.6}
oldSize: {x: 0.78571427, y: 0.85714287}
newSize: {x: 0.56, y: 0.61}
adaptiveTilingThreshold: 0.5
drawMode: 0
......
......@@ -287,7 +287,7 @@ Transform:
m_Children:
- {fileID: 519420032}
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &512397505
MonoBehaviour:
......@@ -467,7 +467,7 @@ GameObject:
- component: {fileID: 574392414}
m_Layer: 0
m_Name: Rubbles
m_TagString: Untagged
m_TagString: Repeatable
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......@@ -484,7 +484,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &792207689
GameObject:
......@@ -527,7 +527,7 @@ GameObject:
- component: {fileID: 1344835039}
m_Layer: 0
m_Name: Explosions
m_TagString: Untagged
m_TagString: Repeatable
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......@@ -544,7 +544,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1364465086
GameObject:
......@@ -558,7 +558,7 @@ GameObject:
- component: {fileID: 1364465087}
m_Layer: 3
m_Name: Terrain
m_TagString: Untagged
m_TagString: Repeatable
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......@@ -669,6 +669,7 @@ MonoBehaviour:
m_BaseSpawnRate: 0.1
m_SpawnRateGrowthRate: 0.1
m_RotationsPerSecond: 1
m_PostLevelUpDelay: 3
m_Damage: 1
--- !u!114 &1654006371
MonoBehaviour:
......@@ -753,7 +754,7 @@ GameObject:
- component: {fileID: 1695424174}
m_Layer: 11
m_Name: Walls
m_TagString: Untagged
m_TagString: Repeatable
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......@@ -786,6 +787,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Settings: {fileID: 1654006372}
m_Player: {fileID: 512397504}
m_BuildingOffset: {x: 0, y: 2}
--- !u!66 &1695424175
CompositeCollider2D:
m_ObjectHideFlags: 0
......@@ -1682,6 +1684,142 @@ Rigidbody2D:
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!1 &1952676060
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1952676062}
- component: {fileID: 1952676061}
- component: {fileID: 1952676063}
m_Layer: 12
m_Name: LevelUpTrigger
m_TagString: Repeatable
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!61 &1952676061
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1952676060}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
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: 1, y: 1}
m_EdgeRadius: 0
--- !u!4 &1952676062
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1952676060}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -5, z: 0}
m_LocalScale: {x: 60, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1952676063
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1952676060}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 223169c625d5d394eb6db0c33dcff3a6, type: 3}
m_Name:
m_EditorClassIdentifier:
m_PreLevelUpHooks:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1654006370}
m_TargetAssemblyTypeName: MeteorSettings, Assembly-CSharp
m_MethodName: PauseSpawning
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_Target: {fileID: 2028534473}
m_TargetAssemblyTypeName: MeteorSpawner, Assembly-CSharp
m_MethodName: DestroyMeteors
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_Target: {fileID: 2028534473}
m_TargetAssemblyTypeName: MeteorSpawner, Assembly-CSharp
m_MethodName: DestroyRubbles
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_PostLevelUpHooks:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1654006372}
m_TargetAssemblyTypeName: Settings, Assembly-CSharp
m_MethodName: OnLevelUp
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_Target: {fileID: 1654006370}
m_TargetAssemblyTypeName: MeteorSettings, Assembly-CSharp
m_MethodName: ResumeSpawningAfterLevelUp
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 3
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!1 &2028534471
GameObject:
m_ObjectHideFlags: 0
......@@ -1694,7 +1832,7 @@ GameObject:
- component: {fileID: 2028534473}
m_Layer: 0
m_Name: Meteors
m_TagString: Untagged
m_TagString: Repeatable
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......@@ -1713,7 +1851,7 @@ Transform:
- {fileID: 106956313}
- {fileID: 792207690}
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2028534473
MonoBehaviour:
......
......@@ -8,19 +8,31 @@ public class MeteorSpawner : MonoBehaviour
private Settings Settings { get => m_Settings; }
private void Start()
private float LastSpawnTime { get; set; }
private void Update()
{
SpawnMeteors();
}
private void SpawnMeteors()
{
if (!Settings.Meteors.Spawning)
{
return;
}
if (Time.time - LastSpawnTime < Settings.Meteors.SpawnPeriod)
{
return;
}
LastSpawnTime = Time.time;
var sourcePoint = RandomPointInTransform(m_Source);
var targetPoint = RandomPointInTransform(m_Target);
SpawnMeteor(sourcePoint, targetPoint);
Invoke("SpawnMeteors", Settings.Meteors.SpawnPeriod);
}
private void SpawnMeteor(Vector2 sourcePoint, Vector2 TargetPoint)
......@@ -54,4 +66,22 @@ public class MeteorSpawner : MonoBehaviour
Random.Range(transform.position.y - transform.localScale.y / 2, transform.position.y + transform.localScale.y / 2)
);
}
static public void DestroyRubbles()
{
DestroyAllObjectsWithTag("Rubble");
}
static public void DestroyMeteors()
{
DestroyAllObjectsWithTag("Meteor");
}
static private void DestroyAllObjectsWithTag(string tag)
{
foreach (var gameObject in GameObject.FindGameObjectsWithTag(tag))
{
Destroy(gameObject);
}
}
}
......@@ -10,6 +10,7 @@ public class MeteorSettings : MonoBehaviour
[SerializeField] private float m_BaseSpawnRate;
[SerializeField] private float m_SpawnRateGrowthRate;
[SerializeField] private float m_RotationsPerSecond;
[SerializeField] private float m_PostLevelUpDelay;
[SerializeField] private uint m_Damage;
......@@ -19,15 +20,17 @@ public class MeteorSettings : MonoBehaviour
public Transform Parent { get => m_Parent; }
public float Speed { get; private set; }
public bool Spawning { get; private set; }
public float SpawnPeriod { get => 1 / m_SpawnRate; }
public float RotationSpeed { get => m_RotationsPerSecond * 360; }
public uint Damage { get => m_Damage; }
private void Start()
{
ResetSpawnRate();
ResetMeteorSpeed();
ResumeSpawningAfterLevelUp();
}
private void Update()
......@@ -41,6 +44,26 @@ public class MeteorSettings : MonoBehaviour
IncreaseMeteorSpeed();
}
public void PauseSpawning()
{
Spawning = false;
}
public void ResumeSpawning()
{
Spawning = true;
}
public void ResumeSpawningAfterLevelUp()
{
ResumeSpawningAfterDelay(m_PostLevelUpDelay);
}
private void ResumeSpawningAfterDelay(float delay)
{
Invoke("ResumeSpawning", delay);
}
private void ResetSpawnRate()
{
m_SpawnRate = m_BaseSpawnRate;
......@@ -53,7 +76,10 @@ public class MeteorSettings : MonoBehaviour
private void IncreaseSpawnRate()
{
m_SpawnRate += m_SpawnRateGrowthRate * Time.deltaTime;
if (Spawning)
{
m_SpawnRate += m_SpawnRateGrowthRate * Time.deltaTime;
}
}
private void IncreaseMeteorSpeed()
......
......@@ -11,4 +11,10 @@ public class Settings : MonoBehaviour
public ExplosionSettings Explosions { get => m_ExplosionSettings; }
public RubbleSettings Rubbles { get => m_RubbleSettings; }
public WallSettings Walls { get => m_WallSettings; }
public void OnLevelUp()
{
Meteors.OnLevelUp();
Explosions.OnLevelUp();
}
}
......@@ -5,6 +5,7 @@ public class WallSpawner : MonoBehaviour
[SerializeField] private Settings m_Settings;
[SerializeField] private Transform m_Player;
[SerializeField] private Vector2 m_BuildingOffset;
private Settings Settings { get => m_Settings; }
......@@ -12,17 +13,16 @@ public class WallSpawner : MonoBehaviour
{
if (Input.GetKeyDown(KeyCode.W))
{
SpawnWall(m_Player.position);
SpawnWall(m_Player.position + new Vector3(m_BuildingOffset.x, m_BuildingOffset.y, 0));
}
}
private void SpawnWall(Vector2 position)
{
var cell = Settings.Walls.Grid.LocalToCell(position);
cell.y += 2;
position = Settings.Walls.Grid.GetCellCenterWorld(cell);
var cell = Settings.Walls.Grid.WorldToCell(position);
var snappedPosition = Settings.Walls.Grid.GetCellCenterWorld(cell);
var wall = Instantiate(Settings.Walls.Prefab, position, Quaternion.identity, Settings.Walls.Parent);
var wall = Instantiate(Settings.Walls.Prefab, snappedPosition, Quaternion.identity, Settings.Walls.Parent);
var damageTaker = wall.GetComponent<DamageTaker>();
......
......@@ -13,6 +13,7 @@
"com.unity.test-framework": "1.1.29",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.4.8",
"com.unity.toolchain.win-x86_64-linux-x86_64": "0.1.21-preview",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
......
......@@ -118,6 +118,22 @@
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.sysroot": {
"version": "0.1.19-preview",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.sysroot.linux-x86_64": {
"version": "0.1.14-preview",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.sysroot": "0.1.18-preview"
},
"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.29",
"depth": 0,
......@@ -150,6 +166,16 @@
},
"url": "https://packages.unity.com"
},
"com.unity.toolchain.win-x86_64-linux-x86_64": {
"version": "0.1.21-preview",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.sysroot": "0.1.19-preview",
"com.unity.sysroot.linux-x86_64": "0.1.14-preview"
},
"url": "https://packages.unity.com"
},
"com.unity.ugui": {
"version": "1.0.0",
"depth": 0,
......
......@@ -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: ffffffff01f0ffff01f0ffffc1f6ffff01f0ffff01f0ffff09f8ffff09ffffff81f0ffff89f8ffff89f8ffffc1f6ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: ffffffff01e0ffff01e0ffffc1e6ffff01e0ffff01e0ffff09e8ffff09ffffff81e0ffff89e8ffff89e8ffffc1e6ffff81e0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
......@@ -3,7 +3,11 @@
--- !u!78 &1
TagManager:
serializedVersion: 2
tags: []
tags:
- Repeatable
- Meteor
- Explosion
- Rubble
layers:
- Default
- TransparentFX
......@@ -17,7 +21,7 @@ TagManager:
- Meteor
- Explosion
- Wall
-
- LevelUp
-
-
-
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment