Three kinds of bullets are firing, bomb breaks the wall
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BlockCracked : MonoBehaviour {
|
||||
void OnCollisionEnter2D(Collision2D collision) {
|
||||
//TODO: use durability class?
|
||||
ExplosionDamager exp = collision.gameObject.GetComponent<ExplosionDamager> ();
|
||||
if (exp != null) {
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7046e112ee78bae4ab5aa561c4e3c603
|
||||
timeCreated: 1524277929
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Bomb : MonoBehaviour {
|
||||
public float timer;
|
||||
|
||||
GameObject explosion;
|
||||
|
||||
void Awake() {
|
||||
StartCoroutine (ExplodeAfter (timer));
|
||||
|
||||
explosion = transform.GetChild (0).gameObject;
|
||||
}
|
||||
|
||||
IEnumerator ExplodeAfter(float delay) {
|
||||
yield return new WaitForSeconds (delay);
|
||||
explosion.SetActive (true);
|
||||
transform.DetachChildren ();
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1f0e082d5001504c913bdebe25279ea
|
||||
timeCreated: 1524276915
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c07520d5190cfa54eb1ff873d0d69610
|
||||
folderAsset: yes
|
||||
timeCreated: 1524278629
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,5 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DamagerBase : MonoBehaviour {
|
||||
public int value = 1;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9df83cc686946cc4ab603daa3ea5a871
|
||||
timeCreated: 1524276968
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ExplosionDamager : DamagerBase {
|
||||
//simply causes damage and then disappears
|
||||
void Awake() {
|
||||
StartCoroutine (DestroyAfter (0.5f));
|
||||
}
|
||||
|
||||
IEnumerator DestroyAfter(float delay) {
|
||||
yield return new WaitForSeconds (delay);
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd95736c14a0eac4aa8f5d682f624d9d
|
||||
timeCreated: 1524276953
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//shootable
|
||||
public class FireDamager : DamagerBase {
|
||||
void OnTriggerEnter2D(Collider2D collider) {
|
||||
if (collider.gameObject.GetComponent<FireDamager> () == null) { //pass through other instances of self
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 310ee2a5851703045af5c47b1b760328
|
||||
timeCreated: 1524278769
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//shootable
|
||||
public class IceDamager : DamagerBase {
|
||||
void OnTriggerEnter2D(Collider2D collider) {
|
||||
if (collider.gameObject.GetComponent<IceDamager> () == null) { //pass through other instances of self
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b0265e5d9f1a804aaa77a77754f51e0
|
||||
timeCreated: 1524281573
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//shootable
|
||||
public class WindDamager : DamagerBase {
|
||||
void OnTriggerEnter2D(Collider2D collider) {
|
||||
if (collider.gameObject.GetComponent<WindDamager> () == null) { //pass through other instances of self
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36f760a1dbdd6254fa3dc2394e2bf8fb
|
||||
timeCreated: 1524281586
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,13 +3,26 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Player : MonoBehaviour {
|
||||
public enum Mode {
|
||||
FIRE, ICE, WIND
|
||||
};
|
||||
|
||||
Animator animator;
|
||||
Rigidbody2D rigidBody;
|
||||
|
||||
//movement
|
||||
float speed;
|
||||
Vector2 deltaForce;
|
||||
Vector2 lastDirection;
|
||||
Vector2 lastDirection = new Vector2(0, -1);
|
||||
|
||||
//attacking
|
||||
bool isShooting;
|
||||
float lastAttack = float.NegativeInfinity;
|
||||
const float attackDelay = 0.5f;
|
||||
Mode mode = Mode.FIRE;
|
||||
public GameObject firePelletPrefab;
|
||||
public GameObject icePelletPrefab;
|
||||
public GameObject windPelletPrefab;
|
||||
|
||||
void Awake() {
|
||||
animator = GetComponent<Animator> ();
|
||||
@@ -21,6 +34,7 @@ public class Player : MonoBehaviour {
|
||||
void Update() {
|
||||
HandleInput ();
|
||||
Move ();
|
||||
Attack ();
|
||||
SendAnimationInfo ();
|
||||
}
|
||||
|
||||
@@ -38,6 +52,10 @@ public class Player : MonoBehaviour {
|
||||
|
||||
//calculate if shooting
|
||||
isShooting = Input.GetButton ("Attack");
|
||||
|
||||
if (Input.GetButtonDown("Switch")) {
|
||||
mode += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Move() {
|
||||
@@ -47,9 +65,53 @@ public class Player : MonoBehaviour {
|
||||
rigidBody.AddForce (impulse, ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
void Attack() {
|
||||
if (Time.time - lastAttack > attackDelay && isShooting) {
|
||||
lastAttack = Time.time;
|
||||
GameObject pellet = null;
|
||||
|
||||
switch (mode) {
|
||||
case Mode.FIRE:
|
||||
pellet = Instantiate (firePelletPrefab);
|
||||
break;
|
||||
case Mode.ICE:
|
||||
pellet = Instantiate (icePelletPrefab);
|
||||
break;
|
||||
case Mode.WIND:
|
||||
pellet = Instantiate (windPelletPrefab);
|
||||
break;
|
||||
}
|
||||
|
||||
//HACK-ish
|
||||
Vector2 distance = GetShootingPoint();
|
||||
pellet.transform.position = new Vector2(transform.position.x + distance.x, transform.position.y + distance.y);
|
||||
pellet.GetComponent<Rigidbody2D> ().velocity = Vector2.zero;
|
||||
pellet.GetComponent<Rigidbody2D> ().AddForce (lastDirection.normalized * 2, ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
if (!isShooting) {
|
||||
lastAttack = float.NegativeInfinity;
|
||||
}
|
||||
}
|
||||
|
||||
void SendAnimationInfo() {
|
||||
animator.SetFloat ("xSpeed", lastDirection.x);
|
||||
animator.SetFloat ("ySpeed", lastDirection.y);
|
||||
animator.SetBool ("isShooting", isShooting);
|
||||
}
|
||||
|
||||
//utilities
|
||||
Vector2 GetShootingPoint() {
|
||||
Vector2 point = lastDirection.normalized;
|
||||
|
||||
if (Mathf.Abs (point.x) == Mathf.Abs (point.y)) {
|
||||
point *= 0.26f; //diagonal
|
||||
} else if (Mathf.Abs (point.x) < Mathf.Abs (point.y)) {
|
||||
point *= 0.23f; //vertical
|
||||
} else {
|
||||
point *= 0.2f; //horizontal
|
||||
}
|
||||
|
||||
return point;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user