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 { ...@@ -7,10 +7,6 @@ public class Bullet : MonoBehaviour {
public bool destroyTrap = false; public bool destroyTrap = false;
public int speed = 5; public int speed = 5;
// Use this for initialization
void Start () {
}
/// <summary> /// <summary>
/// Das aufrufen, wenn die Kugel wirklich losgeschossen werden soll. /// Das aufrufen, wenn die Kugel wirklich losgeschossen werden soll.
...@@ -21,18 +17,19 @@ public class Bullet : MonoBehaviour { ...@@ -21,18 +17,19 @@ public class Bullet : MonoBehaviour {
GetComponent<Rigidbody2D>().velocity = (float)speed*direction.normalized; 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); other.GetComponent<PlayerHealth>().changeHealthBy(healingPoints);
Destroy(gameObject);
} }
if (other.tag == "Trap") else if (destroyTrap && other.tag == "Trap")
{ {
//Zerstöre Falle other.GetComponent<Trap>().destroyTrap();
Debug.Log("TODO Destroy Trap"); Destroy(gameObject);
} }
Destroy(gameObject);
} }
} }
...@@ -28,7 +28,7 @@ public class PlayerControl : MonoBehaviour ...@@ -28,7 +28,7 @@ public class PlayerControl : MonoBehaviour
public Vector3 velocity; public Vector3 velocity;
public int playerNumber = 1; //gibt an, ob es sich um player one, player two, etc. handelt. sollte nicht 0 sein; 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; private Rigidbody2D rigidbody;
void Start() void Start()
...@@ -40,28 +40,34 @@ public class PlayerControl : MonoBehaviour ...@@ -40,28 +40,34 @@ public class PlayerControl : MonoBehaviour
switch (playerNumber) switch (playerNumber)
{ {
case 1: case 1:
setKeyCodes(KeyCode.D, KeyCode.A, KeyCode.W, KeyCode.S);
setKeyCodes(KeyCode.D, KeyCode.A, KeyCode.W, KeyCode.S, KeyCode.LeftShift);
break; break;
case 2: case 2:
setKeyCodes(KeyCode.RightArrow, KeyCode.LeftArrow, KeyCode.UpArrow, KeyCode.DownArrow);
setKeyCodes(KeyCode.RightArrow, KeyCode.LeftArrow, KeyCode.UpArrow, KeyCode.DownArrow, KeyCode.RightShift);
break; break;
//TODO player 3 and 4 //TODO player 3 and 4
default: default:
break; break;
} }
} }
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; goRightKeyCode = right;
goLeftKeyCode = left; goLeftKeyCode = left;
jumpKeyCode = up; jumpKeyCode = up;
dashKeyCode = dash; dashKeyCode = dash;
shootKeyCode = shoot;
} }
void onControllerCollider(RaycastHit2D hit) void onControllerCollider(RaycastHit2D hit)
{ {
//// bail out on plain old ground hits //// bail out on plain old ground hits
//if (hit.normal.y == 1f) //if (hit.normal.y == 1f)
// return; // return;
...@@ -70,7 +76,7 @@ public class PlayerControl : MonoBehaviour ...@@ -70,7 +76,7 @@ public class PlayerControl : MonoBehaviour
if (body) if (body)
{ {
//TODO abfrage " is dashing" //TODO abfrage " is dashing"
body.AddForce(_controller.getDirectionOfMovement()*pushForce); body.AddForce(_controller.getDirectionOfMovement() * pushForce);
//TODO set is dashing to false //TODO set is dashing to false
} }
...@@ -87,7 +93,7 @@ public class PlayerControl : MonoBehaviour ...@@ -87,7 +93,7 @@ public class PlayerControl : MonoBehaviour
if (_controller.isGrounded) if (_controller.isGrounded)
velocity.y = 0; velocity.y = 0;
if (Input.GetKey(goRightKeyCode)) if (Input.GetKey(goRightKeyCode))
{ {
normalizedHorizontalSpeed = 1; normalizedHorizontalSpeed = 1;
...@@ -111,13 +117,13 @@ public class PlayerControl : MonoBehaviour ...@@ -111,13 +117,13 @@ public class PlayerControl : MonoBehaviour
//if (_controller.isGrounded) //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) if (normalizedHorizontalSpeed != 0)
{ {
// player pressed a movement button so prefer the new direction // player pressed a movement button so prefer the new direction
direction = Mathf.Sign (normalizedHorizontalSpeed); direction = Mathf.Sign(normalizedHorizontalSpeed);
} }
normalizedHorizontalSpeed = 5 * direction; normalizedHorizontalSpeed = 5 * direction;
...@@ -139,15 +145,88 @@ public class PlayerControl : MonoBehaviour ...@@ -139,15 +145,88 @@ public class PlayerControl : MonoBehaviour
var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping; // how fast do we change direction? var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping; // how fast do we change direction?
velocity.x = Mathf.Lerp(velocity.x, normalizedHorizontalSpeed * rawMovementDirection * runSpeed, Time.deltaTime * smoothedMovementFactor); velocity.x = Mathf.Lerp(velocity.x, normalizedHorizontalSpeed * rawMovementDirection * runSpeed, Time.deltaTime * smoothedMovementFactor);
// apply gravity before moving // apply gravity before moving
velocity.y += gravity * Time.deltaTime; velocity.y += gravity * Time.deltaTime;
_controller.move(velocity * Time.deltaTime); _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() void EnableDash()
{ {
canDash = true; 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 { ...@@ -13,4 +13,9 @@ public class Trap : MonoBehaviour {
transform.position = new Vector2(50, 50);//TODO setze auf 1000 oder so, zur sicherheit. 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