Commit 7bdbf578 by Alisa Jung

added powerups and bullets

parent 10e1d148
fileFormatVersion: 2
guid: 15d345edd64ab094aa8c1bb7d6fdba1d
timeCreated: 1433449341
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 2103dbcfb3baa764f8239e4d35d5828c
timeCreated: 1433449355
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -7,10 +7,6 @@ public class Bullet : MonoBehaviour {
public bool destroyTrap = false;
public int speed = 5;
// Use this for initialization
void Start () {
}
/// <summary>
/// Das aufrufen, wenn die Kugel wirklich losgeschossen werden soll.
......@@ -21,18 +17,19 @@ public class Bullet : MonoBehaviour {
GetComponent<Rigidbody2D>().velocity = (float)speed*direction.normalized;
}
void OnTriggerEnter(Collider other)
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
//Debug.Log("Bullet colide with " + other.name);
if (healingPoints > 0 && other.tag == "Player")
{
other.GetComponent<PlayerHealth>().changeHealthBy(healingPoints);
Destroy(gameObject);
}
if (other.tag == "Trap")
else if (destroyTrap && other.tag == "Trap")
{
//Zerstöre Falle
Debug.Log("TODO Destroy Trap");
}
other.GetComponent<Trap>().destroyTrap();
Destroy(gameObject);
}
}
}
......@@ -25,7 +25,7 @@ public class PlayerControl : MonoBehaviour
public Vector3 velocity;
public int playerNumber = 1; //gibt an, ob es sich um player one, player two, etc. handelt. sollte nicht 0 sein;
KeyCode goRightKeyCode, goLeftKeyCode, jumpKeyCode;
KeyCode goRightKeyCode, goLeftKeyCode, jumpKeyCode, shootKeyCode;
void Start()
{
......@@ -35,10 +35,10 @@ public class PlayerControl : MonoBehaviour
switch (playerNumber)
{
case 1:
setKeyCodes(KeyCode.D,KeyCode.A,KeyCode.W);
setKeyCodes(KeyCode.D, KeyCode.A, KeyCode.W, KeyCode.LeftShift);
break;
case 2:
setKeyCodes(KeyCode.RightArrow, KeyCode.LeftArrow, KeyCode.UpArrow);
setKeyCodes(KeyCode.RightArrow, KeyCode.LeftArrow, KeyCode.UpArrow, KeyCode.RightShift);
break;
//TODO player 3 and 4
default:
......@@ -46,11 +46,17 @@ public class PlayerControl : MonoBehaviour
}
}
private void setKeyCodes(KeyCode right, KeyCode left, KeyCode up)
void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("BLABLDKSFJH");
}
private void setKeyCodes(KeyCode right, KeyCode left, KeyCode up, KeyCode shoot)
{
goRightKeyCode = right;
goLeftKeyCode = left;
jumpKeyCode = up;
shootKeyCode = shoot;
}
......@@ -117,6 +123,85 @@ public class PlayerControl : MonoBehaviour
_controller.move(velocity * Time.deltaTime);
/*==========Power Ups // Bullet management ===*/
if (Input.GetKeyDown(shootKeyCode))
{
Debug.Log("Shoot pressed. Can shoot: " + canShoot());
if (canShoot())
{
shoot();
coolDown();
}
}
}
/*==========Power Ups // Bullet management ===*/
public const int POWERUP_NONE = 0;
public const int POWERUP_HEALINGBULLET = 1;
public const int POWERUP_TRAPDESTROYER = 2;
private int powerUpType = POWERUP_NONE;
private bool coolingDown = false;
public float coolDownTime = 2.0f;
public GameObject healingBulletPrefab;
public GameObject trapDestroyingBulletPrefab;
public float spawnDistance = 1.0f;
public void setPowerUpType(int type)
{
powerUpType = type;
}
private void shoot()
{
float dir = Mathf.Sign(transform.localScale.x);
Vector2 pos = new Vector2(transform.position.x + dir*spawnDistance, transform.position.y);
switch (powerUpType)
{
case POWERUP_HEALINGBULLET:
GameObject bullet = Instantiate(healingBulletPrefab, pos, transform.rotation) as GameObject;
bullet.GetComponent<Bullet>().shoot(new Vector2(dir, 0));
break;
case POWERUP_TRAPDESTROYER:
GameObject trapbullet = Instantiate(trapDestroyingBulletPrefab, pos, transform.rotation) as GameObject;
trapbullet.GetComponent<Bullet>().shoot(new Vector2(dir, 0));
break;
default:
break;
}
}
private void coolDown()
{
coolingDown = true;
Invoke("coolDownOver", coolDownTime);
}
private void coolDownOver()
{
coolingDown = false;
}
private bool canShoot()
{
return (!coolingDown) && powerUpType != POWERUP_NONE;
}
}
\ No newline at end of file
using UnityEngine;
using System.Collections;
public class PowerUpScript : MonoBehaviour {
/// <summary>
/// sollte übereinstimmen mit PlayerControl.POWERUP_XXX
/// 0 == none
/// 1 == Heal
/// 2 == destroyTrap
/// </summary>
public int type;
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
other.GetComponent<PlayerControl>().setPowerUpType(type);
transform.position = new Vector2(50, 50);//TODO setze auf 1000 oder so, zur sicherheit.
}
}
}
fileFormatVersion: 2
guid: 8b906225f62e3094eb594978d51a6a8e
timeCreated: 1433445353
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -13,4 +13,9 @@ public class Trap : MonoBehaviour {
transform.position = new Vector2(50, 50);//TODO setze auf 1000 oder so, zur sicherheit.
}
}
public void destroyTrap()
{
transform.position = new Vector2(100, 100);
}
}
Markdown is supported
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