Commit f5910d4e by Tim Reiter

Merge branch 'master' of ssh://git.breab.org:2222/gamejam-gpn15/dyingIsMainstream

Conflicts: Assets/Prefabs/Player.prefab Assets/Scripts/PlayerControl.cs Assets/game.unity
parents e8f95484 ca2eb01f
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);
}
}
}
......@@ -28,7 +28,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, dashKeyCode;
KeyCode goRightKeyCode, goLeftKeyCode, jumpKeyCode, dashKeyCode, shootKeyCode;
private Rigidbody2D rigidbody;
void Start()
......@@ -40,10 +40,12 @@ public class PlayerControl : MonoBehaviour
switch (playerNumber)
{
case 1:
setKeyCodes(KeyCode.D, KeyCode.A, KeyCode.W, KeyCode.S);
setKeyCodes(KeyCode.D, KeyCode.A, KeyCode.W, KeyCode.S, KeyCode.LeftShift);
break;
case 2:
setKeyCodes(KeyCode.RightArrow, KeyCode.LeftArrow, KeyCode.UpArrow, KeyCode.DownArrow);
setKeyCodes(KeyCode.RightArrow, KeyCode.LeftArrow, KeyCode.UpArrow, KeyCode.DownArrow, KeyCode.RightShift);
break;
//TODO player 3 and 4
default:
......@@ -51,17 +53,21 @@ public class PlayerControl : MonoBehaviour
}
}
private void setKeyCodes(KeyCode right, KeyCode left, KeyCode up, KeyCode dash)
private void setKeyCodes(KeyCode right, KeyCode left, KeyCode up, KeyCode dash, KeyCode shoot)
{
goRightKeyCode = right;
goLeftKeyCode = left;
jumpKeyCode = up;
dashKeyCode = dash;
shootKeyCode = shoot;
}
void onControllerCollider(RaycastHit2D hit)
{
//// bail out on plain old ground hits
//if (hit.normal.y == 1f)
// return;
......@@ -70,7 +76,7 @@ public class PlayerControl : MonoBehaviour
if (body)
{
//TODO abfrage " is dashing"
body.AddForce(_controller.getDirectionOfMovement()*pushForce);
body.AddForce(_controller.getDirectionOfMovement() * pushForce);
//TODO set is dashing to false
}
......@@ -111,13 +117,13 @@ public class PlayerControl : MonoBehaviour
//if (_controller.isGrounded)
}
if (canDash && Input.GetKey (dashKeyCode))
if (canDash && Input.GetKey(dashKeyCode))
{
float direction = Mathf.Sign (transform.localScale.x);
float direction = Mathf.Sign(transform.localScale.x);
if (normalizedHorizontalSpeed != 0)
{
// player pressed a movement button so prefer the new direction
direction = Mathf.Sign (normalizedHorizontalSpeed);
direction = Mathf.Sign(normalizedHorizontalSpeed);
}
normalizedHorizontalSpeed = 5 * direction;
......@@ -144,10 +150,83 @@ 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();
}
}
}
void EnableDash()
{
canDash = true;
}
/*==========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);
}
}
No preview for this file type
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