Example #1
0
    private void Update()
    {
        if (timer > timeBeforeRepair)
        {
            timer = 0;
            foreach (var playerToRepair in playersInsideTrigger)
            {
                if (playerToRepair.currenthealth < playerToRepair.maxHealth)
                {
                    GlobalMediator.SendMessage(GameEvents.PLAYER_REPAIRED, new PlayerData {
                        id = playerToRepair.playerNumber
                    });
                }
            }
        }
        else
        {
            timer += Time.deltaTime;
        }

        if (playersInsideTrigger.Count == 0)
        {
            timer = 0;
        }
    }
Example #2
0
    public void Charging(Vector2 inputDirection)
    {
        if (!isCharging)
        {
            isCharging = true;
            chargeDisplay.SetActive(true);
            GlobalMediator.SendMessage(GameEvents.PLAYER_CHARGE_START, new PlayerData
            {
                id = playerNumber,
            });
        }

        chargePower += chargePowerIncrement * Time.deltaTime;
        if (chargePower > maxChargePower)
        {
            chargePower = maxChargePower;
        }
        chargeDisplay.transform.localScale = new Vector3(0.1f * chargePower, 1, 1);

        if (aimDirection != inputDirection && inputDirection != Vector2.zero && Vector2.Dot(Vector2.up, inputDirection.normalized) > 0)
        {
            aimDirection = inputDirection;
            Vector3 direction = inputDirection;
            float   angle     = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
            chargeDisplay.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        }
        // Aiming with inputMessage.leftStick;
        // Locks Aiming to set angles
    }
 private void GoToBed()
 {
     GlobalMediator.SendMessage(GameEvents.PLAYER_SLEEP, new PlayerData
     {
         id = playerNumber,
     });
 }
Example #4
0
    public void ReleaseCharge(Vector2 inputDirection)
    {
        isCharging = false;

        if (chargePower < minChargePower)
        {
            chargePower = minChargePower;
        }
        chargeDisplay.SetActive(false);
        if (Vector2.Dot(Vector2.up, inputDirection.normalized) < 0)
        {
            Reset();
            GlobalMediator.SendMessage(GameEvents.PLAYER_CHARGE_CANCELLED, new PlayerData
            {
                id = playerNumber,
            });
            return;
        }

        rigi.AddForce(aimDirection * chargePower, ForceMode2D.Impulse);



        GlobalMediator.SendMessage(GameEvents.PLAYER_CHARGE_RELEASED, new PlayerChargeReleaseData
        {
            id            = playerNumber,
            releasedPower = chargePower
        });
    }
Example #5
0
    public static void RecieveEvents(GameEvents events, GeneralData data)
    {
        foreach (GameEvents item in Enum.GetValues(typeof(GameEvents)))
        {
            if (events.HasFlag(item) == false)
            {
                continue;
            }

            switch (item)
            {
            case GameEvents.GAME_STARTED:
                GlobalMediator.SendMessage(GameEvents.LEVEL_START, new LevelStartData {
                    levelIndex = currentLevel
                });
                break;

            case GameEvents.LEVEL_WON:
                currentLevel++;
                LeanTween.moveY(cam, cam.transform.position.y + oneLevelHeight, 1.2f).setEaseInOutBack().setDelay(2.25f).setOnComplete(() => GlobalMediator.SendMessage(GameEvents.LEVEL_START, new LevelStartData {
                    levelIndex = currentLevel
                }));
                break;

            case GameEvents.RESET_GAME:
                //  LeanTween.moveY(cam, firstLevelYPos, 1.2f).setEaseInOutBack().setDelay(0.1f);
                break;

            default:
                break;
            }
        }
    }
Example #6
0
    private void FixedUpdate()
    {
        if (isMounted && mountedPlayer != null)
        {
            var hit = Physics2D.CircleCast(transform.position, circleRaduis, Vector2.up, rayDistance, mask);

            if (hit)
            {
                if (!WallOver)
                {
                    WallOver = true;
                    GlobalMediator.SendMessage(GameEvents.PLAYER_FORCE_DISMOUNT, new PlayerData
                    {
                        id = mountedPlayer.GetComponent <Player>().playerNumber,
                    });
                }
            }
            else
            {
                if (WallOver)
                {
                    WallOver = false;
                    //Send so we can't go to the direction
                }
            }
        }
        else
        {
            WallOver = false;
        }
    }
Example #7
0
    private void FixedUpdate()
    {
        // var hit = Physics2D.CircleCast(transform.position + Vector3.up, circleRaduis, Vector2.down, rayDistance, mask);

        var hit = Physics2D.OverlapCircle(transform.position + (Vector3.up * cirlceOffsetY), circleRaduis, mask);

        if (hit)
        {
            if (!isGrounded)
            {
                isGrounded = true;
                GlobalMediator.SendMessage(GameEvents.PLAYER_GROUND_CHECK, new GroundCheckData
                {
                    id         = playerNumber,
                    isGrounded = true
                });
            }
        }
        else
        {
            if (isGrounded)
            {
                isGrounded = false;
                GlobalMediator.SendMessage(GameEvents.PLAYER_GROUND_CHECK, new GroundCheckData
                {
                    id         = playerNumber,
                    isGrounded = false
                });
            }
        }
    }
Example #8
0
 private void DismountPlayer()
 {
     if (mountedPlayer)
     {
         GlobalMediator.SendMessage(GameEvents.PLAYER_GOT_DISMOUNTED, new PlayerData
         {
             id = mountedPlayer.GetComponent <Player>().playerNumber
         });
     }
     mountedPlayer = null;
     isRiding      = false;
 }
    public static void RecieveEvent(GameEvents events, GeneralData data)
    {
        foreach (GameEvents item in Enum.GetValues(typeof(GameEvents)))
        {
            if (events.HasFlag(item) == false)
            {
                continue;
            }

            switch (item)
            {
            case GameEvents.PLAYER_INPUT:
                PlayerInputData pInData = (PlayerInputData)data;
                if (pInData.key_respawn)
                {
                    GlobalMediator.SendMessage(GameEvents.RESTART_LEVEL);
                    //timer += Time.deltaTime;
                    ////if (timer > 1.5f)
                    ////{
                    ////    Debug.Log("restart level");
                    ////    timer = 0;

                    ////    return;
                    ////}
                }
                else
                {
                    //timer = 0;
                }
                break;

            case GameEvents.PLAYER_SLEEP:
                AwakePlayers--;
                if (AwakePlayers == 0)
                {
                    //Using leantween as a timer
                    LeanTween.value(1, 2, 2f).setOnComplete(() =>
                    {
                        if (AwakePlayers == 0)
                        {
                            Debug.Log("SLEPT FOR 2 SEC");
                            GlobalMediator.SendMessage(GameEvents.RESTART_LEVEL);
                        }
                    });
                }
                break;

            case GameEvents.PLAYER_REPAIRED:
                AwakePlayers = 2;
                break;
            }
        }
    }
 public void RespawnPlayers()
 {
     GlobalMediator.SendMessage(GameEvents.PLAYER_RESPAWN, new PlayerRespawnData
     {
         id       = 1,
         position = player1SpawnPoint.position
     });
     GlobalMediator.SendMessage(GameEvents.PLAYER_RESPAWN, new PlayerRespawnData
     {
         id       = 2,
         position = player2SpawnPoint.position
     });
 }
Example #11
0
 private void MountPlayer(GameObject bottomPlayer)
 {
     if ((GetComponent <Rigidbody2D>().velocity.y > 0) || !bottomPlayer.GetComponent <Movement>().isGrounded)
     {
         return;
     }
     mountedPlayer      = bottomPlayer.transform;
     transform.position = mountedPlayer.position + new Vector3(0, yOffset, 0);
     isRiding           = true;
     GlobalMediator.SendMessage(GameEvents.PLAYER_GOT_MOUNTED, new PlayerGotMountedData
     {
         id            = bottomPlayer.GetComponent <Player>().playerNumber,
         playerMounted = transform
     });
 }
Example #12
0
    // Update is called once per frame
    void Update()
    {
        // if (Gamepad.current.buttonSouth.wasPressedThisFrame)
        // {
        //     AkSoundEngine.PostEvent("player_repair", this.gameObject);
        // }

        // if (!allowedToMove) return;
        GlobalMediator.SendMessage(GameEvents.PLAYER_INPUT, new PlayerInputData
        {
            id          = playerNumber,
            axis        = inputs.Player.Movement.ReadValue <Vector2>(),
            key_charge  = holdingCharge,
            key_respawn = inputs.Player.Respawn.triggered,
        });
    }
Example #13
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!active)
        {
            return;
        }
        if (collision.CompareTag("Player"))
        {
            playersInGoal++;

            if (playersInGoal == necessaryPeopleInGoal)
            {
                active = false;
                GlobalMediator.SendMessage(GameEvents.LEVEL_WON);
            }
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag(tagToTriggerOn))
        {
            if (!objectsInside.Contains(collision.gameObject))
            {
                objectsInside.Add(collision.gameObject);
            }

            GlobalMediator.SendMessage(eventsToTrigger, new PlayerTriggerBoxData
            {
                id              = playerNumber,
                enterExit       = true,
                collidingObject = collision.gameObject
            });
        }
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.CompareTag(tagToTriggerOn) && collision.transform != transform.parent)
        {
            objectsInside.Remove(collision.gameObject);

            if (objectsInside.Count == 0)
            {
                GlobalMediator.SendMessage(eventsToTrigger, new PlayerTriggerBoxData
                {
                    id              = playerNumber,
                    enterExit       = false,
                    collidingObject = collision.gameObject
                });
            }
        }
    }
Example #16
0
    public void OnMediatorMessageReceived(GameEvents events, GeneralData data)
    {
        if (data is PlayerInputData inputMessage)
        {
            if (inputMessage.id != playerNumber || sleeping)
            {
                return;
            }

            if (inputMessage.key_charge)
            {
                if (alowedToCharge)
                {
                    Charging(inputMessage.axis);
                }
            }
            else
            {
                if (isCharging)
                {
                    ReleaseCharge(inputMessage.axis);
                }
            }
        }
        if (events.HasFlag(GameEvents.PLAYER_GROUND_CHECK))
        {
            if (data is GroundCheckData groundCheckData)
            {
                if (playerNumber == groundCheckData.id)
                {
                    alowedToCharge = groundCheckData.isGrounded;

                    if (groundCheckData.isGrounded)
                    {
                        if (chargePower > powerDamageThresholdWhenHittingFloor)
                        {
                            GlobalMediator.SendMessage(GameEvents.PLAYER_TAKE_DAMAGE, new PlayerData
                            {
                                id = playerNumber,
                            });
                        }
                        Reset();
                    }
                }
            }
        }

        if (events.HasFlag(GameEvents.PLAYER_IS_MOUNTING))
        {
            if (data is PlayerTriggerBoxData isMounting)
            {
                if (playerNumber == isMounting.id)
                {
                    alowedToCharge = isMounting.enterExit;
                }
            }
        }
        if (events.HasFlag(GameEvents.PLAYER_GOT_MOUNTED))
        {
            if (data is PlayerData isMounted)
            {
                if (playerNumber == isMounted.id)
                {
                    alowedToCharge = true;
                }
            }
        }
        if (events.HasFlag(GameEvents.PLAYER_SLEEP))
        {
            if (data is PlayerData isSleeping)
            {
                if (playerNumber == isSleeping.id)
                {
                    sleeping = true;
                }
            }
        }
        if (events.HasFlag(GameEvents.PLAYER_REPAIRED))
        {
            if (data is PlayerData isSleeping)
            {
                if (playerNumber == isSleeping.id)
                {
                    sleeping = false;
                }
            }
        }
        if (events.HasFlag(GameEvents.PLAYER_RESPAWN))
        {
            if (data is PlayerData tagData)
            {
                if (tagData.id == playerNumber)
                {
                    sleeping       = false;
                    alowedToCharge = true;
                }
            }
        }
    }
 private void Start()
 {
     GlobalMediator.SendMessage(GameEvents.GAME_STARTED);
 }