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" />
<Item prefab="ground" x="4.69" y="-2.71" scalex="22.78" />
<Item prefab="ground" x="-4.7" y="-2.7" scalex="22.78" />
<Item prefab="ground" y="-4" scalex="60" />
</Level> </Level>
<Level> </Levels>
<Item prefab="PlayerStartPosition" x="5.11" y="-0.92" />
<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>
</Levels>
\ No newline at end of file
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)
{
if (coll.collider.tag != "Player" || !isDashing())
return;
PlayerControl other = coll.collider.gameObject.GetComponent<PlayerControl>();
other.setPushSpeed(currentDashDirection * pushForce);
lastDashStart = Time.time - dashCompletionTime;
currentDashCoolDown = dashCollisionCoolDown;
}
void onControllerCollider(RaycastHit2D hit) private void setPushSpeed(Vector2 pushSpeed)
{ {
Rigidbody2D body = hit.collider.gameObject.GetComponent<Rigidbody2D>(); this.pushSpeed = pushSpeed;
if (body) this.lastPushStart = Time.time;
{
//TODO abfrage " is dashing"
body.AddForce(moveDirection * pushForce);
lastDashStart = Time.time - dashCompletionTime;
currentDashCoolDown = dashCollisionCoolDown;
}
} }
void FixedUpdate() void FixedUpdate()
...@@ -84,75 +98,71 @@ public class PlayerControl : MonoBehaviour ...@@ -84,75 +98,71 @@ public class PlayerControl : MonoBehaviour
if (canDash() && inputMapping.isDashPressed()) if (canDash() && inputMapping.isDashPressed())
{ {
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;
} }
if (inputMapping.isRightPressed())
{
//normalizedHorizontalSpeed = 1;
//if (transform.localScale.x < 0f)
// transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
velocity = body2D.velocity;
if (inputMapping.isRightPressed())
{
velocity.x = runSpeed;
}
else if (inputMapping.isLeftPressed())
{
velocity.x = -runSpeed;
}
//go right: if (inputMapping.isJumpPressed())
velocity = new Vector2(runSpeed,velocity.y); {
//to avoid DOUBLE JUMP
if (grounded)
{
velocity.y = targetJumpHeight;
}
}
//if (_controller.isGrounded) // apply horizontal speed smoothing it
} var smoothedMovementFactor = isGrounded() ? groundDamping : inAirDamping; // how fast do we change direction?
else if (inputMapping.isLeftPressed()) velocity.x = Mathf.Lerp(velocity.x, 0, Time.deltaTime * smoothedMovementFactor);
{
//normalizedHorizontalSpeed = -1;
//if (transform.localScale.x > 0f)
// transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
velocity = new Vector2(-runSpeed, velocity.y); float verticalSmoothedFactor = isGrounded() ? 0 : inAirDampingVertical;
//if (_controller.isGrounded) if (velocity.y > 0.0f) velocity.y = Mathf.Lerp(velocity.y, 0, Time.deltaTime * verticalSmoothedFactor);
}
if (inputMapping.isJumpPressed()) /*==========Power Ups // Bullet management ===*/
{ if (inputMapping.isShootPressed())
//to avoid DOUBLE JUMP
if (isGrounded())
{
velocity = new Vector2(velocity.x, targetJumpHeight);
}
}
// apply horizontal speed smoothing it
var smoothedMovementFactor = isGrounded() ? groundDamping : inAirDamping; // how fast do we change direction?
velocity.x = Mathf.Lerp(velocity.x,0, Time.deltaTime * smoothedMovementFactor);
float verticalSmoothedFactor = isGrounded() ? 0 : inAirDampingVertical;
if (velocity.y>0.0f) velocity.y = Mathf.Lerp(velocity.y, 0, Time.deltaTime * verticalSmoothedFactor);
/*==========Power Ups // Bullet management ===*/
if (inputMapping.isShootPressed())
{
Debug.Log("Shoot pressed. Can shoot: " + canShoot());
if (canShoot())
{ {
shoot(); Debug.Log("Shoot pressed. Can shoot: " + canShoot());
coolDown(); if (canShoot())
{
shoot();
coolDown();
}
} }
}
} }
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;
...@@ -163,7 +173,7 @@ public class PlayerControl : MonoBehaviour ...@@ -163,7 +173,7 @@ public class PlayerControl : MonoBehaviour
{ {
Vector2 playerPos = new Vector2(transform.position.x, transform.position.y); Vector2 playerPos = new Vector2(transform.position.x, transform.position.y);
Vector2 groundPos = new Vector2(groundCheck.position.x, groundCheck.position.y); Vector2 groundPos = new Vector2(groundCheck.position.x, groundCheck.position.y);
bool result = Physics2D.Linecast(playerPos, groundPos, mask); bool result = Physics2D.Linecast(playerPos, groundPos, mask);
if (result) if (result)
{ {
Debug.DrawLine(playerPos, groundPos, Color.green, 0.5f, false); Debug.DrawLine(playerPos, groundPos, Color.green, 0.5f, false);
...@@ -178,44 +188,44 @@ public class PlayerControl : MonoBehaviour ...@@ -178,44 +188,44 @@ 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