Commit c18dcf06 by Tim Reiter
parents 158637e4 c73f6fd0
fileFormatVersion: 2
guid: 3d31e8f63f3ce8f44943e5e4cca3b056
timeCreated: 1433457524
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 8c880442b4c4b4240a660c8aa3dd4da4
timeCreated: 1433458310
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GameStateTracker : MonoBehaviour {
private int numberOfPlayers;
/// <summary>
/// Numbers of Player ranked 4th to winner
/// </summary>
private int fourthPlayer;
private int thirdPlayer;
private int secondPlayer;
private int winnerPlayer;
private List<string> ranking;
void Awake()
{
ranking = new List<string>();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void setNumberOfPlayers(int players)
{
numberOfPlayers = players;
}
public void playerDied(string name)
{
if (!ranking.Contains(name))
{
ranking.Add(name);
}
if (ranking.Count >= numberOfPlayers - 1)
{
gameOver();
}
}
public void gameOver()
{
Time.timeScale = 0.0f;
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
string loser = "";
foreach (GameObject p in players){
if (p.GetComponent<PlayerHealth>().getCurrentHealth() > 0)
{
loser = p.name;
break;
}
}
if (string.IsNullOrEmpty(loser))
{
Debug.LogError("No loser found");
loser = "None";
}
else
{
ranking.Add(loser);
}
Debug.Log("Ranking: ");
for (int i = 0; i < ranking.Count; i++)
{
Debug.Log((i+1) + "th: " + ranking[i]);
}
//Ranking enthält an erster stelle den gewinner (der als erster gestorben ist) und dann absteigend die danach als String.
}
}
fileFormatVersion: 2
guid: 6420b29453e1bf744941e7bec3f7d443
timeCreated: 1433438590
guid: dc91e7f992ec0f845bc2a960c166515b
timeCreated: 1433456333
licenseType: Free
MonoImporter:
serializedVersion: 2
......
......@@ -12,8 +12,13 @@ public class PlayerControl : MonoBehaviour
public float groundDamping = 20f; // how fast do we change direction? higher means faster
public float inAirDamping = 5f;
public float targetJumpHeight = 2f;
public bool canDash = true;
public float dashCoolDown = 0.25f;
public float lastDashStart = float.NegativeInfinity;
public float currentDashDirection = 0.0f;
public float dashDirection = 1.0f;
public float dashCompletionTime = 0.25f;
public float dashStartSpeed = 20.0f;
public float dashEndSpeed = 8.0f;
public float dashCoolDown = 0.5f;
// public float jumpWaitTime = 2.0;
[HideInInspector]
......@@ -93,82 +98,97 @@ public class PlayerControl : MonoBehaviour
if (_controller.isGrounded)
velocity.y = 0;
if (Input.GetKey(goRightKeyCode))
{
normalizedHorizontalSpeed = 1;
if (transform.localScale.x < 0f)
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
//if (_controller.isGrounded)
}
else if (Input.GetKey(goLeftKeyCode))
if (Input.GetKey (goRightKeyCode))
{
normalizedHorizontalSpeed = -1;
if (transform.localScale.x > 0f)
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
//if (_controller.isGrounded)
dashDirection = 1.0f;
}
else
else if (Input.GetKey (goLeftKeyCode))
{
normalizedHorizontalSpeed = 0;
//if (_controller.isGrounded)
dashDirection = -1.0f;
}
if (canDash && Input.GetKey(dashKeyCode))
if (canDash () && Input.GetKey (dashKeyCode))
{
float direction = Mathf.Sign(transform.localScale.x);
if (normalizedHorizontalSpeed != 0)
{
// player pressed a movement button so prefer the new direction
direction = Mathf.Sign(normalizedHorizontalSpeed);
}
normalizedHorizontalSpeed = 5 * direction;
canDash = false;
Invoke("EnableDash", dashCoolDown);
lastDashStart = Time.time;
currentDashDirection = dashDirection;
}
if (Input.GetKeyDown(jumpKeyCode))
if (isDashing ())
{
//to avoid DOUBLE JUMP
if (_controller.isGrounded)
{
velocity.y = Mathf.Sqrt(2f * targetJumpHeight * -gravity);
}
velocity.x = Mathf.Lerp(currentDashDirection * dashStartSpeed, currentDashDirection * dashEndSpeed, getDashTime() / dashCompletionTime);
velocity.y = 0;
}
// apply horizontal speed smoothing it
var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping; // how fast do we change direction?
velocity.x = Mathf.Lerp(velocity.x, normalizedHorizontalSpeed * rawMovementDirection * runSpeed, Time.deltaTime * smoothedMovementFactor);
// apply gravity before moving
velocity.y += gravity * Time.deltaTime;
_controller.move(velocity * Time.deltaTime);
/*==========Power Ups // Bullet management ===*/
if (Input.GetKeyDown(shootKeyCode))
else
{
if (Input.GetKey(goRightKeyCode))
{
normalizedHorizontalSpeed = 1;
if (transform.localScale.x < 0f)
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
//if (_controller.isGrounded)
}
else if (Input.GetKey(goLeftKeyCode))
{
normalizedHorizontalSpeed = -1;
if (transform.localScale.x > 0f)
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
//if (_controller.isGrounded)
}
else
{
normalizedHorizontalSpeed = 0;
//if (_controller.isGrounded)
}
if (Input.GetKey (jumpKeyCode))
{
//to avoid DOUBLE JUMP
if (_controller.isGrounded)
{
velocity.y = Mathf.Sqrt(2f * targetJumpHeight * -gravity);
}
}
// apply horizontal speed smoothing it
var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping; // how fast do we change direction?
velocity.x = Mathf.Lerp(velocity.x, normalizedHorizontalSpeed * rawMovementDirection * runSpeed, Time.deltaTime * smoothedMovementFactor);
// apply gravity before moving
velocity.y += gravity * Time.deltaTime;
/*==========Power Ups // Bullet management ===*/
if (Input.GetKeyDown(shootKeyCode))
{
Debug.Log("Shoot pressed. Can shoot: " + canShoot());
if (canShoot())
{
shoot();
coolDown();
shoot();
coolDown();
}
}
}
_controller.move(velocity * Time.deltaTime);
}
private float getDashTime ()
{
return Time.time - lastDashStart;
}
private bool isDashing ()
{
float dashTime = getDashTime();
return 0 <= dashTime && dashTime < dashCompletionTime;
}
void EnableDash()
private bool canDash ()
{
canDash = true;
return getDashTime() >= dashCompletionTime + dashCoolDown;
}
/*==========Power Ups // Bullet management ===*/
......@@ -229,4 +249,4 @@ public class PlayerControl : MonoBehaviour
return (!coolingDown) && powerUpType != POWERUP_NONE;
}
}
\ No newline at end of file
}
......@@ -10,12 +10,17 @@ public class PlayerHealth : MonoBehaviour {
private bool alive = true;
public Scrollbar healthbar;
private bool hasShield = false;
// Update is called once per frame
void Update () {
if (alive && currentHealth <= 0)
{
Debug.Log("Player " + name + " dead.");
alive = false;
GameObject.Find("GameStateTracker").GetComponent<GameStateTracker>().playerDied(name);
Destroy(gameObject);
}
}
......@@ -24,16 +29,6 @@ public class PlayerHealth : MonoBehaviour {
return currentHealth;
}
/// <summary>
/// Setzt Gesundheit auf bestimmten Wert, aber nicht mehr als maxHealth von dem Player.
/// </summary>
/// <param name="newHealth"></param>
public void setHealth(float newHealth)
{
currentHealth = (newHealth > maxHealth) ? maxHealth : newHealth;
updateHealthbar();
}
//updated die ui healthbar.
private void updateHealthbar()
{
......@@ -49,9 +44,15 @@ public class PlayerHealth : MonoBehaviour {
/// <param name="h"></param>
public void changeHealthBy(float h)
{
if (hasShield && h < 0) return;
currentHealth += h;
if (currentHealth > maxHealth) currentHealth = maxHealth;
updateHealthbar();
}
public void setShield(bool s) {
Debug.Log("Shield " + s + " accepted");
hasShield = s;
}
}
using UnityEngine;
using System.Collections;
public class ShieldScript : MonoBehaviour {
PlayerHealth parentHealth;
public float shieldingTime = 10;
// Use this for initialization
void Start()
{
Invoke("stopShielding", shieldingTime);
}
void OnTriggerEnter2D(Collider2D other)
{
PlayerHealth oldHealth = parentHealth;
if (other.tag == "Player")
{
parentHealth = other.GetComponent<PlayerHealth>();
transform.position = other.transform.position; //hier schon position setzen
transform.parent = other.transform;
Debug.Log("Set shield from shield");
parentHealth.setShield(true);
}
if (oldHealth != null && oldHealth != parentHealth) oldHealth.setShield(false);
}
void stopShielding()
{
Destroy(gameObject);
}
}
fileFormatVersion: 2
guid: c80458a4e231f0a4189ac96ec41a353b
timeCreated: 1433457908
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
public class Spikes : MonoBehaviour {
float damage; //the amount of damage the spikes make.
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "Player")
{
//TODO: do damage
}
}
}
......@@ -4,18 +4,30 @@ using System.Collections;
public class Trap : MonoBehaviour {
public int damagePoints = 10;
public float respawnTime = 5.0f;
// used to store the position while the trap is deactivated
private Vector2 realPosition;
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
other.GetComponent<PlayerHealth>().changeHealthBy(-damagePoints);
transform.position = new Vector2(50, 50);//TODO setze auf 1000 oder so, zur sicherheit.
destroyTrap();
}
}
public void destroyTrap()
{
realPosition = transform.position;
transform.position = new Vector2(100, 100);
Invoke("Activate", respawnTime);
}
void Activate()
{
transform.position = realPosition;
}
}
fileFormatVersion: 2
guid: f61139bec6a9c264593ee2c032bf7bbb
timeCreated: 1433457789
licenseType: Free
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 0
lightmap: 0
rGBM: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 1
textureType: 8
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
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