Partygame is only available as a video, due to WebGL and UNet conflicts.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
#region Variables & Properties
private GameManager instance;
public GameManager Instance
{
get
{
return instance;
}
}
private byte activePlayers = 1;
private byte playerID = 1;
#endregion
#region Methods
private void Awake()
{
if(instance == null)
{
instance = this;
}
else
{
Destroy(this);
return;
}
}
#endregion
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using TMPro;
public class UIManager : NetworkBehaviour
{
[SerializeField]
private TMP_Text roundTimeCounter;
[SerializeField]
private TMP_Text freezeTimeCounter;
private Round roundManagement;
private void Start()
{
if (isLocalPlayer)
{
UpdateUI();
}
}
private void Update()
{
if (isLocalPlayer)
{
UpdateUI();
}
}
[ServerCallback]
private void UpdateUI()
{
roundTimeCounter.text = $"RoundTime: {roundManagement.RoundTime.ToString()}";
freezeTimeCounter.text = $"FreezeTime: {((int)roundManagement.FreezeTime).ToString()}";
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum MenuStates
{
Default = 0,
MainMenu = 1,
OptionsMenu = 2,
StatsMenu = 3,
InGame = 4
}
public enum SoundNames
{
Jump = 1,
Attack,
Footsteps,
Landing,
Death,
Hit,
FireTrap,
SwingingTrap,
PickUp
}
public enum SpawnType
{
Character,
PowerUP
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.Networking;
using UnityEngine.UI;
public class Round : NetworkBehaviour
{
//private Stats roundStats;
private bool roundRunning = false;
private bool statsUIIsActive = false;
[SerializeField]
private TMP_Text roundTimeCounter;
[SerializeField]
private TMP_Text freezeTimeCounter;
[SerializeField]
private GameObject statsPanel;
private Player[] myPlayers;
[SyncVar(hook = "OnFreezeTimeChanged")]
private float freezeTime = 3f;
public float FreezeTime
{
get
{
return freezeTime;
}
}
[SyncVar(hook = "OnRoundTimeChanged")]
private int roundTime = 120;
public int RoundTime
{
get
{
return roundTime;
}
set
{
roundTime = value;
}
}
private void OnEnable()
{
myPlayers = FindObjectsOfType();
}
private void Start()
{
if (isClient)
{
statsPanel.SetActive(statsUIIsActive);
OnRoundTimeChanged(roundTime);
OnFreezeTimeChanged(freezeTime);
}
FreezPlayers();
}
private void Update()
{
RoundUpdate();
}
private void RoundUpdate()
{
if (!FreezeCooldown() && !roundRunning && roundTime > 0)
{
StartCoroutine(StartRound());
UnFreezePlayers();
return;
}
else if (!statsUIIsActive && roundTime <= 0)
{
CallStatsUI();
}
}
private void CallStatsUI()
{
statsUIIsActive = true;
statsPanel.SetActive(statsUIIsActive);
Time.timeScale = 0f;
}
private void OnRoundTimeChanged(int value)
{
roundTime = value;
roundTimeCounter.text = $"RoundTime: {roundTime.ToString()}";
}
private void OnFreezeTimeChanged(float value)
{
freezeTime = value;
freezeTimeCounter.text = $"FreezeTime: {((int)freezeTime).ToString()}";
}
private bool FreezeCooldown()
{
if (freezeTime > 0)
{
// Block all Keyboard Input
// UI Overlay
//freezeTimeCounter.text = $"FreezeTime: {((int)freezeTime).ToString()}";
Debug.Log($"RestTime: {(int)freezeTime}");
freezeTime -= Time.deltaTime;
return true;
}
else
{
return false;
}
}
private void FreezPlayers()
{
foreach (Player myPlayer in myPlayers)
{
myPlayer.KeyBoardInputBlocked = true;
}
}
private void UnFreezePlayers()
{
foreach (Player myPlayer in myPlayers)
{
myPlayer.KeyBoardInputBlocked = false;
}
}
public void QuitTheGameForGood()
{
Application.Quit();
}
private IEnumerator StartRound()
{
roundRunning = true;
while (RoundTime > 0)
{
// Update UI
//roundTimeCounter.text = $"RoundTime: {roundTime.ToString()}";
//Debug.Log(RoundTime);
yield return new WaitForSecondsRealtime(1);
RoundTime--;
}
roundRunning = false;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Spawn : NetworkBehaviour
{
private Transform spawnPoint;
[SerializeField]
private SpawnType spawnType;
[SerializeField]
private PowerUP[] spawnObject;
private GameObject objectInstance;
[SerializeField]
private float respawnTime;
private bool respawnBlocked = false;
[SerializeField]
private bool objectCollected = false;
[SerializeField]
private bool hasWarmUpTime;
private void OnEnable()
{
spawnPoint = GetComponent();
}
private void Start()
{
if(!hasWarmUpTime)
{
CmdSpawnThisFuckinObject();
}
}
private void Update()
{
if (objectInstance == null && !respawnBlocked && !objectCollected)
{
StartCoroutine("InitiateSpawnProcess");
}
if (objectInstance != null && objectCollected)
{
Destroy(objectInstance);
}
}
[Command]
private void CmdSpawnThisFuckinObject()
{
int index = Random.Range(0, spawnObject.Length);
objectInstance = Instantiate(spawnObject[index].gameObject, spawnPoint.position, Quaternion.identity);
NetworkServer.Spawn(objectInstance);
}
private IEnumerator InitiateSpawnProcess()
{
respawnBlocked = true;
yield return new WaitForSeconds(respawnTime);
CmdSpawnThisFuckinObject();
respawnBlocked = false;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundManager : MonoBehaviour
{
private static SoundManager instance;
public static SoundManager Instance
{
get
{
return instance;
}
}
[SerializeField]
Sound[] sounds;
private void Awake()
{
if (instance == null)
{
instance = this;
}
else
{
Destroy(this);
return;
}
}
public void PlaySound(AudioSource _source, SoundNames _soundName)
{
for (int i = 0; i < sounds.Length; i++)
{
if (sounds[i].name == _soundName)
{
_source.clip = sounds[i].soundClip;
_source.PlayOneShot(sounds[i].soundClip, sounds[i].clipVolume);
if (sounds[i].randomize)
{
_source.volume = sounds[i].clipVolume * (1 + Random.Range(-sounds[i].randomSeed, sounds[i].randomSeed));
_source.pitch = sounds[i].clipPitch * (1 + Random.Range(-sounds[i].randomSeed, sounds[i].randomSeed));
}
else
{
_source.volume = sounds[i].clipVolume;
_source.pitch = -0.1f;
}
}
}
//Debug.Log(_source.isPlaying);
//Debug.Log($"Sound \"{sounds[i].name}\" played");
}
#region OldStuff
/*
[SerializeField]
private AudioSource sfxSource;
[SerializeField]
private AudioSource musicSource;
[SerializeField]
private AudioClip[] footsteps;
[SerializeField]
private AudioClip[] musicClips;
private AudioClip jumpSound;
[SerializeField]
private MenuStates activeMenuState;
private void Awake()
{
activeMenuState = MenuStates.MainMenu;
}
public void InitSounds()
{
if (sfxSource != null && sfxSource.GetComponent())
{
sfxSource = GetComponent();
}
sfxSource.Stop();
if (musicSource.GetComponent())
{
musicSource = GetComponent();
}
musicSource.Stop();
}
public void PlayMusic(MenuStates _activeMenuState)
{
musicSource.Stop();
if(musicClips == null)
{
return;
}
else if(!musicClips[(int)_activeMenuState])
{
_activeMenuState = MenuStates.Default;
}
musicSource.clip = musicClips[(int)_activeMenuState];
musicSource.Play();
}*/
#endregion
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerSound : MonoBehaviour
{
private AudioSource audioSource;
private void Awake()
{
audioSource = GetComponent();
}
public void JumpSound()
{
SoundManager.Instance.PlaySound(audioSource, SoundNames.Jump);
}
public void FootStepSound()
{
SoundManager.Instance.PlaySound(audioSource, SoundNames.Footsteps);
}
public void LandingSound()
{
SoundManager.Instance.PlaySound(audioSource, SoundNames.Landing);
}
public void AttackSound()
{
SoundManager.Instance.PlaySound(audioSource, SoundNames.Attack);
}
public void DeathSound()
{
SoundManager.Instance.PlaySound(audioSource, SoundNames.Death);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Sound
{
public SoundNames name;
public AudioClip soundClip;
[Range(0, 1f)]
public float clipVolume = 0.7f;
[Range(0.9f, 1.1f)]
public float clipPitch = 1f;
[Range(0f, 0.2f)]
public float randomSeed = 0f;
public bool randomize = false;
}
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class Player : NetworkBehaviour
{
#region Variables & Properties
private InputController myInputCotroller;
private MovementController myMovementController;
private CombatController myCombatController;
private Round myRound;
private Rigidbody2D myRigidbody;
[SyncVar(hook = "OnLocalScaleSet")]
private Vector3 syncScale;
public Vector3 SyncScale
{
get { return syncScale; }
}
#region Power Ups
private int attackSpeedboost = 2;
public int AttackSpeedBoost
{
get
{
return attackSpeedboost;
}
set
{
attackSpeedboost = value;
}
}
private int shieldBoost = 4;
public int ShieldBoost
{
get
{
return shieldBoost;
}
set
{
shieldBoost = value;
}
}
private int explosionBoost = 8;
public int ExplosionBoost
{
get
{
return explosionBoost;
}
set
{
explosionBoost = value;
}
}
private int crowdControlBoost = 16;
public int CrowdControlBoost
{
get
{
return crowdControlBoost;
}
set
{
crowdControlBoost = value;
}
}
private int powerUp;
public int PowerUp
{
get
{
return powerUp;
}
set
{
powerUp = value;
}
}
public void UnSetPowerUp(int powerUp)
{
PowerUp &= ~powerUp;
}
public void UnSetAttackSpeed()
{
//Debug.Log("UnSet Attack Speed");
PowerUp &= ~AttackSpeedBoost;
}
#endregion
//Init Werte:
[SerializeField]
private float attackSpeed, movementSpeed, jumpForce;
[SerializeField]
private float respawnTime;
private float originalGravityScale;
public float AttackSpeed
{
get
{
if ((powerUp & attackSpeedboost) > 0)
{
Invoke("UnSetAttackSpeed", 2f);
return attackSpeed * 0.5f;
}
return attackSpeed;
}
}
//Gore Array für TodesSplatter
[SerializeField]
private Object[] bodyParts;
[SerializeField]
private ParticleSystem myParticleSystem;
Object bodyPart;
private bool lookRight;
private bool isJumping;
[SyncVar]
private bool keyBoardInputBlocked = false;
public bool KeyBoardInputBlocked
{
get { return keyBoardInputBlocked; }
set { keyBoardInputBlocked = value; }
}
private Vector2 targetPosition;
private Vector2 spawnPoint;
#endregion
#region Methods
private void Start()
{
myInputCotroller = GetComponent();
myMovementController = GetComponent();
myCombatController = GetComponent();
myRigidbody = this.gameObject.GetComponent();
spawnPoint = this.transform.position;
originalGravityScale = this.gameObject.GetComponent().gravityScale;
if (isServer)
{
syncScale = transform.localScale;
}
lookRight = true;
}
private void Update()
{
if (!keyBoardInputBlocked)
{
if (isLocalPlayer)
{
isJumping = myInputCotroller.JumpingInput();
targetPosition = myInputCotroller.AimInput();
myCombatController.UpdateCombatController();
myMovementController.ControlJumping(isJumping, jumpForce);
}
if (myInputCotroller.MouseClickInput() && isLocalPlayer)
{
myCombatController.Attack(this, myInputCotroller.AimInput());
}
}
LookDirection(targetPosition.x);
}
private void FixedUpdate()
{
if (!keyBoardInputBlocked)
{
if (isLocalPlayer)
{
float horizontalInput = myInputCotroller.HorizontalInput();
myMovementController.ControlMovement(movementSpeed, horizontalInput);
}
}
}
public void LookDirection(float horizontal)
{
if (horizontal > this.transform.position.x && !lookRight || horizontal < this.transform.position.x && lookRight)
{
lookRight = !lookRight;
Vector2 theScale = transform.localScale;
theScale.x *= -1;
if (isLocalPlayer)
{
CmdSetLocalScale(theScale);
}
}
}
[ClientRpc]
private void RpcDeactivateBecauseDeath()
{
GetComponent().DeathSound();
myRigidbody.velocity = Vector2.zero;
myRigidbody.gravityScale = 0f;
this.gameObject.GetComponent().enabled = false;
this.gameObject.GetComponent().enabled = false;
this.gameObject.GetComponent().enabled = false;
}
[ClientRpc]
private void RpcReactivateForRespawn()
{
this.transform.position = spawnPoint;
this.gameObject.GetComponent().enabled = true;
this.gameObject.GetComponent().enabled = true;
this.gameObject.GetComponent().enabled = true;
myRigidbody.gravityScale = originalGravityScale;
}
private void OnLocalScaleSet(Vector3 scale)
{
syncScale = scale;
transform.localScale = scale;
}
[Command]
private void CmdSetLocalScale(Vector3 scale)
{
syncScale = scale;
}
private IEnumerator SetPlayerToSpawnPoint()
{
keyBoardInputBlocked = true;
RpcDeactivateBecauseDeath();
yield return new WaitForSeconds(respawnTime);
RpcReactivateForRespawn();
keyBoardInputBlocked = false;
}
private void CallClientRpcForBodyParts()
{
RpcSpawnBodyParts();
}
[ClientRpc]
private void RpcSpawnBodyParts()
{
Object currentGore;
Object currentBlood;
foreach (Object bodyPart in bodyParts)
{
currentGore = Instantiate(bodyPart, this.transform.position, Quaternion.identity);
NetworkServer.Spawn((GameObject)currentGore);
}
currentBlood = Instantiate(myParticleSystem.gameObject, this.transform.position, Quaternion.identity);
NetworkServer.Spawn((GameObject)currentBlood);
}
#endregion
#region CollisionDetection
[ServerCallback]
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Arrow" || collision.gameObject.tag == "Trap")
{
if (!((powerUp & shieldBoost) > 0))
{
CallClientRpcForBodyParts();
StartCoroutine("SetPlayerToSpawnPoint");
}
else
{
UnSetPowerUp(shieldBoost);
}
}
}
#endregion
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InputController : MonoBehaviour
{
public bool JumpingInput()
{
return Input.GetKeyDown(KeyCode.Space);
}
public float HorizontalInput()
{
return Input.GetAxis("Horizontal");
}
public Vector2 AimInput()
{
Vector2 targetPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
return targetPosition;
}
public bool MouseClickInput()
{
return Input.GetKeyDown(KeyCode.Mouse0);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class MovementController : MonoBehaviour
{
private Rigidbody2D myRigidbody;
private Animator myAnimator;
[SerializeField]
private LayerMask whatIsJumpable;
[SerializeField]
private Transform[] groundPoints;
[SerializeField]
private float groundCheckRadius = 0.15f;
[SerializeField]
private bool airborneBecauseJumping = false;
private void Start()
{
myAnimator = GetComponent();
myRigidbody = GetComponent();
}
public void ControlMovement(float movementSpeed, float horizontalInput)
{
if (horizontalInput < 0f || horizontalInput > 0f)
{
myAnimator.SetBool("isRunning", true);
}
else
{
myAnimator.SetBool("isRunning", false);
}
Vector2 tempForce = new Vector2(horizontalInput * movementSpeed * Time.deltaTime, myRigidbody.velocity.y);
ApplyMovement(tempForce);
}
public void ControlJumping(bool isJumping, float jumpForce)
{
if (isJumping && IsGrounded())
{
ApplyJumping(jumpForce);
myAnimator.SetBool("isJumping", true);
airborneBecauseJumping = true;
}
else if (IsGrounded())
{
myAnimator.SetBool("isJumping", false);
myAnimator.SetBool("isFalling", false);
airborneBecauseJumping = false;
}
else if (!airborneBecauseJumping && !IsGrounded())
{
myAnimator.SetBool("isFalling", true);
}
}
public void ApplyMovement(Vector2 movementForce)
{
myRigidbody.velocity = movementForce;
}
public void ApplyJumping(float jumpForce)
{
myRigidbody.AddForce(new Vector2(0f, jumpForce));
}
private bool IsGrounded()
{
if (myRigidbody.velocity.y <= 0.1f)
{
foreach (Transform point in groundPoints)
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundCheckRadius, whatIsJumpable);
for (int i = 0; i < colliders.Length; i++)
{
if (colliders[i].gameObject != this.gameObject)
{
return true;
}
}
}
}
return false;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class BloodSplatter : NetworkBehaviour
{
private void Start()
{
NetworkServer.UnSpawn(this.gameObject);
Destroy(this.gameObject, 2);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class CombatController : NetworkBehaviour
{
[SerializeField]
private GameObject[] projectilePrefab;
private Projectile currentProjectile;
private float attackCooldown = -1.0f;
private Player myPlayer;
private Animator myAnimator;
[SerializeField]
private Transform projectileSpwanPoint;
private void Start()
{
myPlayer = GetComponent();
myAnimator = GetComponent();
}
public void UpdateCombatController()
{
if (attackCooldown >= 0) attackCooldown -= Time.deltaTime;
}
///
/// Checks if Player is allowed to shoot considering attackspeed
///
/// Player that executes the action
///
private bool AttackAllowedCheck(Player executingPlayer)
{
if (attackCooldown >= 0)
{
return false;
}
return true;
}
///
/// Attack function initializes a projectile with its given launchspeed, considering the attackspeed that the player has
///
/// Player that executes the action
/// Vector3 Worldposition of cursor --> camera.ScreenToWorldPoint(new Vector3(mousePosition.x,mousePosition.y,0))
public void Attack(Player executingPlayer, Vector3 mousePosition) //ExecutingPlayer mit Playerscript wechseln
{
//Vector3 shotDirection = Vector3.Normalize(mousePosition - executingPlayer.transform.position);
if (AttackAllowedCheck(executingPlayer))
{
Vector3 shootingDirection = (mousePosition - projectileSpwanPoint.position).normalized;
myAnimator.SetTrigger("attack");
if ((myPlayer.PowerUp & myPlayer.ExplosionBoost) > 0)
{
//Explosive Arrow
CmdSpawnArrow(1, shootingDirection);
myPlayer.UnSetPowerUp(myPlayer.ExplosionBoost);
}
else if ((myPlayer.PowerUp & myPlayer.CrowdControlBoost) > 0)
{
//CrowdControll Arrow
CmdSpawnArrow(2, shootingDirection);
myPlayer.UnSetPowerUp(myPlayer.CrowdControlBoost);
}
else
{
//Standard Arrow
CmdSpawnArrow(0, shootingDirection);
}
//currentProjectile.LaunchProjectile(shootingDirection);
attackCooldown = executingPlayer.AttackSpeed;
}
}
[Command]
private void CmdSpawnArrow(int index, Vector3 shootingDirection)
{
if (index < projectilePrefab.Length && projectilePrefab[index] != null)
{
Quaternion arrowRotation = Quaternion.identity;
currentProjectile = Instantiate(projectilePrefab[index], projectileSpwanPoint.position, Quaternion.identity).GetComponent();
if (myPlayer.transform.localScale.x < 0)
arrowRotation = Quaternion.Euler(0f, 0f, 180f);
currentProjectile.transform.rotation = arrowRotation;
currentProjectile.LaunchProjectile(shootingDirection);
NetworkServer.Spawn(currentProjectile.gameObject);
}
else return;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Projectile : NetworkBehaviour
{
[SerializeField]
private float projectileLaunchSpeed = 400.0f;
[SerializeField]
private float timeToProjectileDestruction = 2.0f;
Coroutine projectileDestructionRoutine;
[SerializeField]
private Rigidbody2D projectileBody2D;
public Rigidbody2D AccessProjectileBody2D { get { return projectileBody2D; } }
private void Start()
{
//projectileDestructionRoutine = StartCoroutine(DestroyProjectile(this.gameObject));
}
public void LaunchProjectile(Vector3 shotDirection)
{
projectileBody2D.MoveRotation(Quaternion.LookRotation(shotDirection));
projectileBody2D.AddForce(shotDirection * projectileLaunchSpeed);
}
///
/// Destroys the Projectile after timeToProjectileDestruction has run out
///
/// The GameObject that should be destroyed
///
/*private IEnumerator DestroyProjectile(GameObject projectileToDestroy)
{
Destroy(projectileToDestroy, timeToProjectileDestruction);
yield break;
}*/
[ServerCallback]
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag != "PickUp")
{
NetworkServer.UnSpawn(this.gameObject);
Destroy(this.gameObject, 0.05f);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class PowerUP : NetworkBehaviour
{
[SerializeField]
private Player myPlayer;
//einkommentieren sobald Merge erfolgreich
//private Weapon myWeapon;
//[SerializeField]
//private GameObject explosionWeapon;
//[SerializeField]
//private GameObject crowdControlWeapon;
[SerializeField]
private int powerUpType;
[SerializeField]
private float powerUpTimer = 10f;
// Verhalten nach erhalten der Eigenschaften muss noch implementiert werden
private void OnTriggerEnter2D(Collider2D collision)
{
if (myPlayer = collision.GetComponent())
{
switch (powerUpType)
{
case 2: SetAttackSpeed(); break;
case 4: SetShield(); break;
case 8: SetExplosion(); break;
case 16: SetCrowdControl(); break;
}
NetworkServer.UnSpawn(gameObject);
Destroy(this.gameObject);
}
}
private void SetAttackSpeed()
{
myPlayer.PowerUp |= myPlayer.AttackSpeedBoost;
//Debug.Log("AttackSpeed Power Up");
}
private void SetShield()
{
myPlayer.PowerUp |= myPlayer.ShieldBoost;
//Debug.Log("Shield Power Up");
}
private void SetExplosion()
{
myPlayer.PowerUp |= myPlayer.ExplosionBoost;
//Debug.Log("Explosion Power Up");
}
private void SetCrowdControl()
{
myPlayer.PowerUp |= myPlayer.CrowdControlBoost;
//Debug.Log("Kraut Kontrolle Power Up");
}
//Unset Methode. Muss nach entsprechender Zeit / Verhalten aufgerufen werden
}