summaryrefslogtreecommitdiff
path: root/AlienSurvival/Assets/Scripts/Test
diff options
context:
space:
mode:
Diffstat (limited to 'AlienSurvival/Assets/Scripts/Test')
-rw-r--r--AlienSurvival/Assets/Scripts/Test/TestCannon.cs6
-rw-r--r--AlienSurvival/Assets/Scripts/Test/TestGrenade.cs107
-rw-r--r--AlienSurvival/Assets/Scripts/Test/TestGrenade.cs.meta11
-rw-r--r--AlienSurvival/Assets/Scripts/Test/TestLauncher.cs67
-rw-r--r--AlienSurvival/Assets/Scripts/Test/TestLauncher.cs.meta11
-rw-r--r--AlienSurvival/Assets/Scripts/Test/TestTopDown2DTransform.cs78
-rw-r--r--AlienSurvival/Assets/Scripts/Test/TestTopDown2DTransform.cs.meta11
7 files changed, 288 insertions, 3 deletions
diff --git a/AlienSurvival/Assets/Scripts/Test/TestCannon.cs b/AlienSurvival/Assets/Scripts/Test/TestCannon.cs
index e68186f..22b168b 100644
--- a/AlienSurvival/Assets/Scripts/Test/TestCannon.cs
+++ b/AlienSurvival/Assets/Scripts/Test/TestCannon.cs
@@ -17,7 +17,7 @@ public class TestCannon : MonoBehaviour
{
sprite = GetComponent<SpriteRenderer>();
- StartCoroutine(coFire());
+ StartCoroutine(coFire(1f));
}
// Update is called once per frame
@@ -26,7 +26,7 @@ public class TestCannon : MonoBehaviour
}
- IEnumerator coFire()
+ IEnumerator coFire(float interval)
{
while (true)
{
@@ -37,7 +37,7 @@ public class TestCannon : MonoBehaviour
b.direction = -transform.right;
- yield return new WaitForSeconds(0.5f);
+ yield return new WaitForSeconds(interval);
}
}
diff --git a/AlienSurvival/Assets/Scripts/Test/TestGrenade.cs b/AlienSurvival/Assets/Scripts/Test/TestGrenade.cs
new file mode 100644
index 0000000..a1434d8
--- /dev/null
+++ b/AlienSurvival/Assets/Scripts/Test/TestGrenade.cs
@@ -0,0 +1,107 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class TestPseudoVec3
+{
+ public float x;
+ public float y;
+ public float h;
+ public TestPseudoVec3(float x, float y, float h)
+ {
+ this.x = x;
+ this.y = y;
+ this.h = h;
+ }
+}
+
+public class TestGrenade : MonoBehaviour
+{
+ public bool useGravity;
+
+ public float gravity = -9.8f;
+
+ public TestPseudoVec3 velocity;
+ public TestPseudoVec3 pseudoPos;
+
+ public Transform shadow;
+
+ private bool m_IsGround
+ {
+ get
+ {
+ return pseudoPos.h <= 0;
+ }
+ }
+
+ // Start is called before the first frame update
+ void Start()
+ {
+ //Invoke("Dead", 3);
+ }
+
+ void Dead()
+ {
+ if (this.gameObject)
+ {
+ GameObject.Destroy(this.gameObject);
+ }
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+ if(useGravity && !m_IsGround)
+ {
+ velocity.h += gravity * Time.deltaTime;
+ }
+
+ pseudoPos.x += velocity.x * Time.deltaTime;
+ pseudoPos.y += velocity.y * Time.deltaTime;
+ pseudoPos.h += velocity.h * Time.deltaTime;
+
+ if(m_IsGround)
+ {
+ velocity.h = -velocity.h;
+ pseudoPos.h = 0;
+ }
+
+ Vector3 position = transform.position;
+
+ position.x = pseudoPos.x;
+ position.y = pseudoPos.y + pseudoPos.h;
+
+ transform.position = position;
+
+ if (shadow)
+ {
+ // shadow position
+ shadow.rotation = Quaternion.identity;
+ Vector3 shadowPos = Vector3.zero;
+ shadowPos.x = pseudoPos.x;
+ shadowPos.y = pseudoPos.y;
+ shadowPos.z = 0;
+ shadow.position = shadowPos;
+ }
+ }
+
+ private void OnTriggerEnter2D(Collider2D collision)
+ {
+ //GameObject go = collision.gameObject;
+
+ //if (!go.CompareTag("enemy"))
+ //{
+ // return;
+ //}
+
+ //GameObject.Destroy(collision.gameObject);
+
+ ////this.gameObject.SetActive(false);
+
+ //if (this.gameObject)
+ //{
+ // GameObject.Destroy(this.gameObject);
+ //}
+ }
+
+}
diff --git a/AlienSurvival/Assets/Scripts/Test/TestGrenade.cs.meta b/AlienSurvival/Assets/Scripts/Test/TestGrenade.cs.meta
new file mode 100644
index 0000000..f5d87e9
--- /dev/null
+++ b/AlienSurvival/Assets/Scripts/Test/TestGrenade.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 76da92161ea22274996c5bc1d0bdea94
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/AlienSurvival/Assets/Scripts/Test/TestLauncher.cs b/AlienSurvival/Assets/Scripts/Test/TestLauncher.cs
new file mode 100644
index 0000000..91fb9e9
--- /dev/null
+++ b/AlienSurvival/Assets/Scripts/Test/TestLauncher.cs
@@ -0,0 +1,67 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class TestLauncher : MonoBehaviour
+{
+ public TestGrenade bullet;
+
+ public Transform shadow;
+
+ public Transform start;
+
+ public float speed = 1;
+
+ SpriteRenderer sprite;
+
+ // Start is called before the first frame update
+ void Start()
+ {
+ sprite = GetComponent<SpriteRenderer>();
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+
+ Vector3 screenPos = Input.mousePosition;
+
+ Vector2 target = Camera.main.ScreenToWorldPoint(screenPos);
+
+ Vector2 dir = Vector2.ClampMagnitude(target - (Vector2)transform.position, 1);
+ Vector3 move = dir * speed * Time.deltaTime;
+
+ float x = move.x;
+ if (x > 0)
+ {
+ sprite.flipY = false;
+ }
+ else if (x < 0)
+ {
+ sprite.flipY = true;
+ }
+
+ transform.rotation = Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(dir.y, dir.x));
+
+ Shot();
+ }
+
+ void Shot()
+ {
+ if (Input.GetButtonDown("Fire1"))
+ {
+ //Debug.Log("Shoot");
+
+ TestGrenade b = TestGrenade.Instantiate(bullet);
+ b.gameObject.SetActive(true);
+
+ b.transform.position = start.position;
+
+ b.pseudoPos = new TestPseudoVec3(start.position.x, start.position.y, 0.1f);
+
+ float speed = 5;
+ b.velocity = new TestPseudoVec3(transform.right.x * speed, transform.right.y * speed, 1f);
+ }
+ }
+
+}
diff --git a/AlienSurvival/Assets/Scripts/Test/TestLauncher.cs.meta b/AlienSurvival/Assets/Scripts/Test/TestLauncher.cs.meta
new file mode 100644
index 0000000..8688fc3
--- /dev/null
+++ b/AlienSurvival/Assets/Scripts/Test/TestLauncher.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 45111da1fa00b2a4192afc01c5be0873
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/AlienSurvival/Assets/Scripts/Test/TestTopDown2DTransform.cs b/AlienSurvival/Assets/Scripts/Test/TestTopDown2DTransform.cs
new file mode 100644
index 0000000..acfac68
--- /dev/null
+++ b/AlienSurvival/Assets/Scripts/Test/TestTopDown2DTransform.cs
@@ -0,0 +1,78 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class TestTopDown2DTransform : MonoBehaviour
+{
+ public bool useGravity = false;
+
+ public Vector3 position // x, y, h
+ {
+ get
+ {
+ Vector3 topdownPos = transform.position;
+ topdownPos.y -= h;
+ topdownPos.z = h;
+ return topdownPos;
+ }
+ set
+ {
+ h = value.z;
+ Vector3 realPos = transform.position;
+ realPos.y = value.y + h;
+ transform.position = realPos;
+ }
+ }
+
+ public float x
+ {
+ get
+ {
+ return position.x;
+ }
+ }
+
+ public float y
+ {
+ get
+ {
+ return position.y;
+ }
+ }
+
+ public float h = 0;
+
+ public float z
+ {
+ get
+ {
+ return transform.position.z;
+ }
+ }
+
+ public float depth
+ {
+ get
+ {
+ return this.z;
+ }
+ }
+
+ private float vy = 0;
+
+ private void Update()
+ {
+ if (useGravity)
+ {
+ Vector3 pos = position;
+ vy += -9.8f * Time.deltaTime;
+ pos.z = Mathf.Max(pos.z + vy * Time.deltaTime, 0f);
+ if(pos.z == 0)
+ {
+ vy = 0;
+ }
+ position = pos;
+ }
+ }
+
+}
diff --git a/AlienSurvival/Assets/Scripts/Test/TestTopDown2DTransform.cs.meta b/AlienSurvival/Assets/Scripts/Test/TestTopDown2DTransform.cs.meta
new file mode 100644
index 0000000..b8279be
--- /dev/null
+++ b/AlienSurvival/Assets/Scripts/Test/TestTopDown2DTransform.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 65a986ca41323a44c910b7d7660abf9c
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: