Commit 7d9c2dd3 by Tim Reiter

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

Conflicts: Assets/Scripts/PlayerControl.cs Assets/game.unity
parents e860e653 cb5cf6e8
<?xml version="1.0" encoding="us-ascii"?> <?xml version="1.0" encoding="us-ascii"?>
<Levels> <Levels>
<Developer StartLevel="0" /> <Developer StartLevel="0" />
<Level> <Level>
<Item prefab="Player Two" x="-3.05" y="2.06" /> <Item prefab="Start_Position" x="5" />
<Item prefab="Player One" x="-0.23" y="2.06" /> <Item prefab="Start_Position" x="-5" />
<Item prefab="Trap" x="-5.02" y="-0.57" rot="90" /> <Item prefab="Start_Position" />
<Item prefab="ground" x="1.51" y="-0.8" scalex="58.39" /> <Item prefab="ground" y="-1.5" scalex="22.78" />
<Item prefab="Turret" x="4.47" y="0.71" /> <Item prefab="ground" x="-7.5" y="-0.38" rot="90" scalex="30" />
<Item prefab="PortableFire" x="4.04" y="-0.22" scalex="0.2" scaley="0.2" /> <Item prefab="ground" x="7.5" y="-0.38" rot="90" scalex="30" />
</Level> <Item prefab="ground" x="4.69" y="-2.71" scalex="22.78" />
<Level> <Item prefab="ground" x="-4.7" y="-2.7" scalex="22.78" />
<Item prefab="PlayerStartPosition" x="5.11" y="-0.92" /> <Item prefab="ground" y="-4" scalex="60" />
<Item prefab="PortableFire" x="6.57" y="-1.3" />
<Item prefab="PortableFire" x="6.41" y="-2.37" />
<Item prefab="PortableFire" x="4.84" y="-1.68" />
</Level> </Level>
</Levels> </Levels>
fileFormatVersion: 2
guid: d0e95f1c653856b409b235f9de3f6493
timeCreated: 1433514922
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
...@@ -6,6 +6,7 @@ using UnityEngine.UI; ...@@ -6,6 +6,7 @@ using UnityEngine.UI;
public class GameMaster : MonoBehaviour { public class GameMaster : MonoBehaviour {
DeserializedLevelsLoader levelLoader; DeserializedLevelsLoader levelLoader;
public PlayerControl[] playerPrefabs;
public GameObject gameOverPanel; public GameObject gameOverPanel;
public Text rankingText; public Text rankingText;
...@@ -14,9 +15,53 @@ public class GameMaster : MonoBehaviour { ...@@ -14,9 +15,53 @@ public class GameMaster : MonoBehaviour {
levelLoader = new DeserializedLevelsLoader(); levelLoader = new DeserializedLevelsLoader();
} }
public void loadLevel() public void loadLevel(int numberOfPlayers)
{ {
levelLoader.loadLevel(); levelLoader.loadLevel();
deleteAllPlayers();
spawnPlayers(numberOfPlayers);
}
private void deleteAllPlayers()
{
foreach (GameObject player in GameObject.FindGameObjectsWithTag("Player"))
Object.Destroy(player, 0f);
}
private void spawnPlayers(int count)
{
Debug.Log("spawning " + count + " players");
GameObject[] startPositions = GameObject.FindGameObjectsWithTag("Start_Position");
if (count > startPositions.Length)
{
count = startPositions.Length;
Debug.LogError("map is capped at " + count + " players");
}
shuffle(startPositions);
for (int i = 0; i < count; i++)
{
PlayerControl player = (PlayerControl) Object.Instantiate(
playerPrefabs[i % playerPrefabs.Length],
startPositions[i].transform.position,
Quaternion.identity);
player.init(i + 1);
}
}
private static void shuffle<T>(T[] array)
{
int i = array.Length;
while (i > 1)
{
int k = Random.Range(0, i--);
T t = array[k];
array[k] = array[i];
array[i] = t;
}
} }
public void gameOver(List<string> ranking) public void gameOver(List<string> ranking)
......
...@@ -7,6 +7,7 @@ using UnityEngine.UI; ...@@ -7,6 +7,7 @@ using UnityEngine.UI;
public class Menu : MonoBehaviour public class Menu : MonoBehaviour
{ {
public GameStateTracker gameStateTracker; public GameStateTracker gameStateTracker;
public GameObject gameUI;
public GameMaster gameMaster; public GameMaster gameMaster;
public GameObject menuPanel; public GameObject menuPanel;
public GameObject p1Image, p2Image, p3Image, p4Image; public GameObject p1Image, p2Image, p3Image, p4Image;
...@@ -38,9 +39,10 @@ public class Menu : MonoBehaviour ...@@ -38,9 +39,10 @@ public class Menu : MonoBehaviour
{ {
if (numberOfRegisteredPlayers > 1 || (numberOfRegisteredPlayers > 0 && Debug.isDebugBuild)) if (numberOfRegisteredPlayers > 1 || (numberOfRegisteredPlayers > 0 && Debug.isDebugBuild))
{ {
gameUI.SetActive(true);
gameStateTracker.setNumberOfPlayers(numberOfRegisteredPlayers); gameStateTracker.setNumberOfPlayers(numberOfRegisteredPlayers);
gameStateTracker.reset(); gameStateTracker.reset();
gameMaster.loadLevel(); gameMaster.loadLevel(numberOfRegisteredPlayers);
gameObject.SetActive(false); gameObject.SetActive(false);
return true; return true;
} }
......
...@@ -5,9 +5,6 @@ using GamepadInput; ...@@ -5,9 +5,6 @@ using GamepadInput;
public class PlayerControl : MonoBehaviour public class PlayerControl : MonoBehaviour
{ {
private enum Keys : int { Left = 0, Right, Up, Down, Jump, Dash, Shoot };
private Rigidbody2D body2D; private Rigidbody2D body2D;
private Vector3 lastPos; // we make sure the last Pos is never the curPos. private Vector3 lastPos; // we make sure the last Pos is never the curPos.
private Vector2 moveDirection; private Vector2 moveDirection;
...@@ -16,7 +13,8 @@ public class PlayerControl : MonoBehaviour ...@@ -16,7 +13,8 @@ public class PlayerControl : MonoBehaviour
public LayerMask mask; public LayerMask mask;
// movement config // movement config
public float pushForce = 20f; public float pushForce = 5f;
public float pushTime = 0.5f;
public float gravity = -15f; public float gravity = -15f;
public float runSpeed = 8f; public float runSpeed = 8f;
public float groundDamping = 20f; // how fast do we change direction? higher means faster public float groundDamping = 20f; // how fast do we change direction? higher means faster
...@@ -31,44 +29,60 @@ public class PlayerControl : MonoBehaviour ...@@ -31,44 +29,60 @@ public class PlayerControl : MonoBehaviour
public float dashCompletionTime = 0.25f; public float dashCompletionTime = 0.25f;
public float dashStartSpeed = 20.0f; public float dashStartSpeed = 20.0f;
public float dashEndSpeed = 8.0f; public float dashEndSpeed = 8.0f;
public float dashCoolDown = 0.5f; public float dashCoolDown = 0.4f;
public float dashVerticalScale = 0.5f;
public float dashCollisionCoolDown = 1.5f; public float dashCollisionCoolDown = 1.5f;
[HideInInspector] [HideInInspector]
public float currentDashCoolDown = 0.0f; public float currentDashCoolDown = 0.0f;
[HideInInspector]
public bool hasLandedSinceLastDash = true;
// public float jumpWaitTime = 2.0; // public float jumpWaitTime = 2.0;
[HideInInspector] [HideInInspector]
public Vector2 pushSpeed = Vector2.zero;
[HideInInspector]
public float lastPushStart = float.NegativeInfinity;
[HideInInspector]
public float rawMovementDirection = 1; public float rawMovementDirection = 1;
//[HideInInspector] //[HideInInspector]
public float normalizedHorizontalSpeed = 0; public float normalizedHorizontalSpeed = 0;
[HideInInspector] [HideInInspector]
public Vector3 velocity; public Vector2 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;
public PlayerInputMapping inputMapping; public PlayerInputMapping inputMapping;
private controlType controls;
KeyCode[] keyCodes = new KeyCode[Keys.GetNames(typeof(Keys)).Length];
void Start() void Start()
{ {
body2D = GetComponent<Rigidbody2D>(); body2D = GetComponent<Rigidbody2D>();
}
public void init(int playerNumber)
{
this.playerNumber = playerNumber;
//in der szene muss fuer jeden spieer so ein InputMapping"nr" sein: //in der szene muss fuer jeden spieer so ein InputMapping"nr" sein:
inputMapping = GameObject.Find("InputMapping" + playerNumber).GetComponent<PlayerInputMapping>(); inputMapping = GameObject.Find("InputMapping" + playerNumber).GetComponent<PlayerInputMapping>();
GetComponent<PlayerHealth>().init(playerNumber);
} }
void OnCollisionEnter2D(Collision2D coll)
void onControllerCollider(RaycastHit2D hit)
{ {
Rigidbody2D body = hit.collider.gameObject.GetComponent<Rigidbody2D>(); if (coll.collider.tag != "Player" || !isDashing())
if (body) return;
{
//TODO abfrage " is dashing" PlayerControl other = coll.collider.gameObject.GetComponent<PlayerControl>();
body.AddForce(moveDirection * pushForce); other.setPushSpeed(currentDashDirection * pushForce);
lastDashStart = Time.time - dashCompletionTime; lastDashStart = Time.time - dashCompletionTime;
currentDashCoolDown = dashCollisionCoolDown; currentDashCoolDown = dashCollisionCoolDown;
} }
private void setPushSpeed(Vector2 pushSpeed)
{
this.pushSpeed = pushSpeed;
this.lastPushStart = Time.time;
} }
void FixedUpdate() void FixedUpdate()
...@@ -87,56 +101,46 @@ public class PlayerControl : MonoBehaviour ...@@ -87,56 +101,46 @@ public class PlayerControl : MonoBehaviour
lastDashStart = Time.time; lastDashStart = Time.time;
currentDashDirection = dashDirection; currentDashDirection = dashDirection;
currentDashCoolDown = dashCoolDown; currentDashCoolDown = dashCoolDown;
hasLandedSinceLastDash = false;
} }
if (isDashing ()) if (isDashing())
{ {
velocity = currentDashDirection * Mathf.Lerp(dashStartSpeed, dashEndSpeed, getDashTime() / dashCompletionTime); velocity = currentDashDirection * Mathf.Lerp(dashStartSpeed, dashEndSpeed, getDashTime() / dashCompletionTime);
} }
else else
{ {
velocity = body2D.velocity; bool grounded = isGrounded();
if (playerNumber == 1) if (grounded && !isDashing())
{ {
Debug.Log("is right pressed p1: "+inputMapping.isRightPressed()); hasLandedSinceLastDash = true;
} }
velocity = body2D.velocity;
if (inputMapping.isRightPressed()) if (inputMapping.isRightPressed())
{ {
//normalizedHorizontalSpeed = 1; velocity.x = runSpeed;
//if (transform.localScale.x < 0f)
// transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
//go right:
velocity = new Vector2(runSpeed,velocity.y);
//if (_controller.isGrounded)
} }
else if (inputMapping.isLeftPressed()) else if (inputMapping.isLeftPressed())
{ {
//normalizedHorizontalSpeed = -1; velocity.x = -runSpeed;
//if (transform.localScale.x > 0f)
// transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
velocity = new Vector2(-runSpeed, velocity.y);
//if (_controller.isGrounded)
} }
if (inputMapping.isJumpPressed()) if (inputMapping.isJumpPressed())
{ {
//to avoid DOUBLE JUMP //to avoid DOUBLE JUMP
if (isGrounded()) if (grounded)
{ {
velocity = new Vector2(velocity.x, targetJumpHeight); velocity.y = targetJumpHeight;
} }
} }
// apply horizontal speed smoothing it // apply horizontal speed smoothing it
var smoothedMovementFactor = isGrounded() ? groundDamping : inAirDamping; // how fast do we change direction? var smoothedMovementFactor = isGrounded() ? groundDamping : inAirDamping; // how fast do we change direction?
velocity.x = Mathf.Lerp(velocity.x,0, Time.deltaTime * smoothedMovementFactor); velocity.x = Mathf.Lerp(velocity.x, 0, Time.deltaTime * smoothedMovementFactor);
float verticalSmoothedFactor = isGrounded() ? 0 : inAirDampingVertical; float verticalSmoothedFactor = isGrounded() ? 0 : inAirDampingVertical;
if (velocity.y>0.0f) velocity.y = Mathf.Lerp(velocity.y, 0, Time.deltaTime * verticalSmoothedFactor); if (velocity.y > 0.0f) velocity.y = Mathf.Lerp(velocity.y, 0, Time.deltaTime * verticalSmoothedFactor);
/*==========Power Ups // Bullet management ===*/ /*==========Power Ups // Bullet management ===*/
if (inputMapping.isShootPressed()) if (inputMapping.isShootPressed())
...@@ -150,9 +154,15 @@ public class PlayerControl : MonoBehaviour ...@@ -150,9 +154,15 @@ public class PlayerControl : MonoBehaviour
} }
} }
float currentPushTime = Time.time - lastPushStart;
Vector2 currentPushSpeed = Vector2.zero;
if (0 <= currentPushTime && currentPushTime <= pushTime)
{
currentPushSpeed = Vector2.Lerp(pushSpeed, Vector2.zero, currentPushTime / pushTime);
}
//finally set the velocity: //finally set the velocity:
body2D.velocity = velocity; body2D.velocity = velocity + currentPushSpeed;
//update move direction after the currentposition was updated: //update move direction after the currentposition was updated:
moveDirection = (transform.position - lastPos).normalized; moveDirection = (transform.position - lastPos).normalized;
...@@ -179,43 +189,43 @@ public class PlayerControl : MonoBehaviour ...@@ -179,43 +189,43 @@ public class PlayerControl : MonoBehaviour
private void updateDashDirection() private void updateDashDirection()
{ {
float horizontalDashDirection = 0.0f; float horizontalDashDirection = 0.0f;
if (Input.GetKey (keyCodes[(int)Keys.Right])) if (inputMapping.isRightPressed())
{ {
horizontalDashDirection = 1.0f; horizontalDashDirection = 1.0f;
} }
else if (Input.GetKey (keyCodes[(int)Keys.Left])) else if (inputMapping.isLeftPressed())
{ {
horizontalDashDirection = -1.0f; horizontalDashDirection = -1.0f;
} }
float verticalDashDirection = 0.0f; float verticalDashDirection = 0.0f;
if (Input.GetKey (keyCodes[(int)Keys.Up])) if (inputMapping.isUpPressed())
{ {
verticalDashDirection = 1.0f; verticalDashDirection = 1.0f;
} }
else if (Input.GetKey (keyCodes[(int)Keys.Down])) else if (inputMapping.isDownPressed())
{ {
verticalDashDirection = -1.0f; verticalDashDirection = -1.0f;
} }
if (horizontalDashDirection != 0.0f || verticalDashDirection != 0.0f) if (horizontalDashDirection != 0.0f || verticalDashDirection != 0.0f)
dashDirection = new Vector2(horizontalDashDirection, verticalDashDirection); dashDirection = new Vector2(horizontalDashDirection, dashVerticalScale * verticalDashDirection);
} }
private float getDashTime () private float getDashTime()
{ {
return Time.time - lastDashStart; return Time.time - lastDashStart;
} }
private bool isDashing () private bool isDashing()
{ {
float dashTime = getDashTime(); float dashTime = getDashTime();
return 0 <= dashTime && dashTime < dashCompletionTime; return 0 <= dashTime && dashTime < dashCompletionTime;
} }
private bool canDash () private bool canDash()
{ {
return getDashTime() >= dashCompletionTime + currentDashCoolDown; return hasLandedSinceLastDash && getDashTime() >= dashCompletionTime + currentDashCoolDown;
} }
/*==========Power Ups // Bullet management ===*/ /*==========Power Ups // Bullet management ===*/
......
...@@ -13,13 +13,10 @@ public class PlayerHealth : MonoBehaviour { ...@@ -13,13 +13,10 @@ public class PlayerHealth : MonoBehaviour {
private GameStateTracker gameStateTracker; private GameStateTracker gameStateTracker;
private bool hasShield = false; private bool hasShield = false;
public void init(int playerNumber)
void Start()
{ {
gameStateTracker = GameObject.Find("GameMaster").GetComponent<GameStateTracker>(); //warning: geht kaputt wenn der name "Game Master" sich aendert. string healthbarName = "HealthBar" + playerNumber;
playerControl = gameObject.GetComponent<PlayerControl>(); Debug.Log(healthbarName);
string healthbarName = "HealthBar" + playerControl.playerNumber.ToString();
healthbar = GameObject.Find(healthbarName).GetComponent<Scrollbar>(); healthbar = GameObject.Find(healthbarName).GetComponent<Scrollbar>();
if (name.EndsWith("(Clone)")) if (name.EndsWith("(Clone)"))
......
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