Quickly added Enemy_4
This commit is contained in:
@@ -2,17 +2,66 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Enemy_4 will start offscreen and then pick a random point on screen to
|
||||
/// move to. Once it has arrived, it will pick another random point and
|
||||
/// continue until the player has shot it down.
|
||||
/// </summary>
|
||||
|
||||
[System.Serializable]
|
||||
public class Part {
|
||||
// These three fields need to be defined in the Inspector pane
|
||||
public string name;
|
||||
public float health;
|
||||
public string[] protectedBy;
|
||||
[HideInInspector]
|
||||
public GameObject go;
|
||||
[HideInInspector]
|
||||
public Material mat;
|
||||
}
|
||||
|
||||
public class Enemy_4 : Enemy
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
[Header("Set in Inspector: Enemy_4")]
|
||||
public Part[] parts;
|
||||
private Vector3 p0, p1; // The two points to interpolate
|
||||
private float timeStart; // Birth time for this Enemy_4
|
||||
private float duration = 4; // Duration of movement
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
// There is already an initial position chosen by Main.SpawnEnemy()
|
||||
// so add it to points as the initial p0 & p1
|
||||
p0 = p1 = pos;
|
||||
InitMovement();
|
||||
Transform t;
|
||||
foreach(Part prt in parts) {
|
||||
t = transform.Find(prt.name);
|
||||
if (t != null) {
|
||||
prt.go = t.gameObject;
|
||||
prt.mat = prt.go.GetComponent<Renderer>().material;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
void InitMovement() {
|
||||
p0 = p1; // Set p0 to the old p1
|
||||
// Assign a new on-screen location to p1
|
||||
float widMinRad = bndCheck.camWidth - bndCheck.radius;
|
||||
float hgtMinRad = bndCheck.camHeight - bndCheck.radius;
|
||||
p1.x = Random.Range(-widMinRad, widMinRad);
|
||||
p1.y = Random.Range(-hgtMinRad, hgtMinRad);
|
||||
// Reset the time
|
||||
timeStart = Time.time;
|
||||
}
|
||||
public override void Move() {
|
||||
// This completely overrides Enemy.Move() with a linear interpolation
|
||||
float u = (Time.time - timeStart) / duration;
|
||||
if (u >= 1) {
|
||||
InitMovement();
|
||||
u = 0;
|
||||
}
|
||||
u = 1 - Mathf.Pow(1 - u, 2); // Apply East Out easing to u
|
||||
pos = (1 - u) * p0 + u*p1; // Simple linear interpolation
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// This is an enum of the various possible weapon types.
|
||||
/// It also includes a "shield" type to allow a shield power-up.
|
||||
/// Items marked [NI] below are Not Implemented in the IGDPD book.
|
||||
/// </summary>
|
||||
|
||||
public enum WeaponType {
|
||||
none, // The default / no weapon
|
||||
blaster, // A simple blaster
|
||||
spread, // Two shots simultaneously
|
||||
phaser, // [NI] Shots that move in waves
|
||||
missile, // [NI] Homing missiles
|
||||
laser, // [NI]Damage over time
|
||||
shield // Raise shieldLevel
|
||||
}
|
||||
|
||||
public class Weapon : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a45dacce959bdd1c943cd342de8d377
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user