Browse Source

[2.0.3.9] Space Jellyfish Added

Zariteis 4 years ago
parent
commit
29b8bc992e

BIN
Assets/Meteoroid/jelly.png


BIN
Assets/Meteoroid/jellyLegs.png


+ 25 - 0
Gadgets/Meteoroid/MeteoroidGadget.Create.cs

@@ -1,4 +1,5 @@
 using GadgetCore.API;
+using Subworlds.Scripts;
 using UnityEngine;
 
 namespace Subworlds
@@ -116,5 +117,29 @@ namespace Subworlds
       GadgetCoreAPI.AddCustomResource("z/Subworlds/" + name, gameObject);
     }
 
+    private void CreateJellyfishEnemy(string name, Texture2D texture, Texture2D texture2)
+    {
+      GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("e/wisp"));
+      gameObject.name = name;
+      gameObject.transform.GetChild(0).GetChild(0).gameObject.name = name;
+      Renderer rendererHead = gameObject.transform.GetChild(0).GetChild(0).GetChild(0).GetComponentInChildren<Renderer>();
+      rendererHead.material = new Material(Shader.Find("Unlit/Transparent"))
+      {
+        mainTexture = texture2
+      };
+      Renderer rendererLegs = gameObject.transform.GetChild(0).GetChild(0).GetChild(1).GetComponentInChildren<Renderer>();
+      rendererLegs.material = new Material(Shader.Find("Unlit/Transparent"))
+      {
+        mainTexture = texture
+      };
+      Component.DestroyImmediate(gameObject.GetComponent<WispScript>());
+      gameObject.AddComponent<SpaceJellyfishScript>();
+
+      gameObject.transform.GetChild(1).gameObject.SetActive(true);
+      gameObject.transform.GetChild(1).localScale = new Vector3(65, 40, 1);
+
+      GadgetCoreAPI.AddCustomResource("e/Subworlds/" + name, gameObject);
+    }
+
   }
 }

+ 3 - 0
Gadgets/Meteoroid/MeteoroidGadget.Init.cs

@@ -73,6 +73,9 @@ namespace Subworlds
       CreateBrakableObject("SpaceOre2", GadgetCoreAPI.LoadTexture2D("Meteoroid/spaceOreBig.png"), itemId: 1);
 
       CreateBrakableObject("BrokenMeteor", GadgetCoreAPI.LoadTexture2D("Meteoroid/brokenMeteor.png"), itemId: 1, large: true);
+
+      // Create Enemies
+      CreateJellyfishEnemy("Jelly", GadgetCoreAPI.LoadTexture2D("Meteoroid/jelly.png"), GadgetCoreAPI.LoadTexture2D("Meteoroid/jellyLegs.png"));
     }
   }
 }

+ 75 - 0
Scripts/SpaceJellyfishScript.cs

@@ -0,0 +1,75 @@
+
+
+
+using System;
+using System.Collections;
+using UnityEngine;
+
+namespace Subworlds.Scripts
+{
+  class SpaceJellyfishScript : EnemyScript
+  {
+    private Vector3 dir;
+    private bool attacking;
+
+    private void Awake()
+    {
+      base.Initialize(130, 7, 80, new int[] { 25, 25, 52 }, 60);
+    }
+
+    private void Update()
+    {
+      if (Network.isServer)
+      {
+        if (!this.attacking)
+        {
+          this.r.velocity = new Vector3(0f, 0f, 0f);
+          if (this.target)
+          {
+            if (Mathf.Abs(this.target.transform.position.x - this.t.position.x) < 45f)
+            {
+              this.attacking = true;
+              base.StartCoroutine(this.Attack());
+            }
+            else
+            {
+              this.target = null;
+              this.r.velocity = new Vector3(0f, 0f, 0f);
+            }
+          }
+        }
+      }
+    }
+
+    private float speedVariant = 1;
+
+    private IEnumerator Attack()
+    {
+      //gameObject.transform.GetChild(0).gameObject.GetComponent<Animation>().Play();
+      yield return new WaitForSeconds(0.35f);
+      speedVariant = (1 + UnityEngine.Random.Range(-10, 10) / 20f);
+      yield return new WaitForSeconds(0.01f * UnityEngine.Random.Range(0, 25));
+      for (int i = 0; i < 20; i++)
+      {
+        this.dir = this.target.transform.position - this.t.position;
+        this.dir.Normalize();
+        var prevRotation = gameObject.transform.GetChild(0).localEulerAngles.z + 90;
+        var newRotation = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
+        var diffAngle = (prevRotation - newRotation + 180) % 360 - 180;
+        gameObject.transform.GetChild(0).localEulerAngles = new Vector3(0, 0, prevRotation - 90 - diffAngle / 6);
+        yield return new WaitForSeconds(0.01f);
+      }
+      this.r.velocity = this.dir * (15f);
+      yield return new WaitForSeconds(0.2f);
+      for (int j = 0; j < 8; j++)
+      {
+        this.r.velocity = this.dir * (16f) * (1f / (j + 1)) * speedVariant;
+        yield return new WaitForSeconds(0.5f);
+      }
+      this.r.velocity = new Vector3(0f, 0f, 0f);
+      yield return new WaitForSeconds(0.2f);
+      this.attacking = false;
+      yield break;
+    }
+  }
+}