Beispiel #1
0
    public void UnregisterPickup(TargetObject pickupCollected)
    {
        if (pickupCollected.gameMode != gameMode)
        {
            return;
        }

        // removes the pickup from the list, so that we can keep track of how many are left on the map
        if (pickupCollected.gameMode == GameMode.Laps)
        {
            pickupCollected.active = false;

            LapObject lapObject = (LapObject)pickupCollected;

            if (!lapObject.finishLap)
            {
                return;
            }

            if (!lapObject.lapOverNextPass)
            {
                TimeDisplay.OnUpdateLap();
                lapObject.lapOverNextPass = true;
                return;
            }

            if (NumberOfActivePickupsRemaining() != 0)
            {
                return;
            }

            ReachCheckpoint(0);
            ResetPickups();
            TimeDisplay.OnUpdateLap();
        }
        else if (pickupCollected.gameMode == GameMode.GetTime)
        {
            if (pickupCollected is LapObject)
            {
                ReachCheckpoint(0);
            }
            else
            {
                ReachCheckpoint(NumberOfPickupsRemaining - 1);
            }
        }
        else
        {
            ReachCheckpoint(NumberOfPickupsRemaining - 1);
            Pickups.Remove(pickupCollected);
            if (gameMode == GameMode.Laps)
            {
                KartGame.Track.TimeDisplay.OnUpdateLap();
            }
        }
    }
Beispiel #2
0
    public void UnregisterPickup(TargetObject pickupCollected)
    {
        if (pickupCollected.gameMode != gameMode)
        {
            return;
        }

        // removes the pickup from the list, so that we can keep track of how many are left on the map
        if (pickupCollected.gameMode == GameMode.Laps)
        {
            pickupCollected.active = false;
            LapObject lapObject = (LapObject)pickupCollected;

            if (!lapObject.finishLap)
            {
                return;                     //Si el objeto no es la linea de meta no ejecuta las siguientes lineas
            }
            if (!lapObject.lapOverNextPass) //La primera vez que pasa por linea de meta, actualiza las vueltas e incia el tiempo
            {
                TimeDisplay.OnUpdateLap();
                if (configuration.activeObjects)
                {
                    textRank.gameObject.SetActive(true);
                }
                Item.SetActive(true);
                lapObject.lapOverNextPass = true;
                return;
            }

            if (NumberOfActivePickupsRemaining() != 0)
            {
                return;
            }
            ReachCheckpoint(0, isTimed, lapObject.TimeGained);
            ResetPickups();
            TimeDisplay.OnUpdateLap();
            if (isTimed)
            {
                TimeManager.OnAdjustTime(lapObject.TimeGained);
            }
        }
        else
        {
            ReachCheckpoint(NumberOfPickupsRemaining - 1, isTimed, 0);
            Pickups.Remove(pickupCollected);
            if (gameMode == GameMode.Laps)
            {
                KartGame.Track.TimeDisplay.OnUpdateLap();
            }
        }
    }
        // Update the game state
        // Called every frame
        // <timeStep> time in seconds since last frame
        protected async override void OnUpdate(float timeStep)
        {
            base.OnUpdate(timeStep);

            // Shield
            foreach (Character c in Characters)
            {
                c.ShieldNode.Position = c.ShieldUp ? c.WorldNode.Position : new Vector3(1000, 10000, -1000);
            }

            // Pickups
            foreach (Character c in Characters)
            {
                foreach (Pickup p in Pickups.ToList())
                {
                    if (c.Collides(p))
                    {
                        if (p.PickUp(c))
                        {
                            if (c is CharacterPlayer)
                            {
                                PlaySound("sounds/effects/pop.ogg", false);
                            }
                            p.WorldNode.Remove();
                            Pickups.Remove(p);

                            c.WorldNode.GetComponent <StaticSprite2D>().Sprite = c.PlayerSpriteAttack;
                        }
                    }
                }
            }

            // Bullets
            foreach (Bullet b in Bullets.ToList())
            {
                if (b.WorldNode.IsDeleted)
                {
                    continue;
                }

                if (b.WorldNode.Position2D.Length > 50f)
                {
                    b.WorldNode.Remove();
                    Bullets.Remove(b);
                    continue;
                }

                bool deleted = false;
                b.WorldNode.SetPosition2D(b.WorldNode.Position2D + (b.Direction * bulletSpeed * timeStep));

                foreach (Character c in Characters)
                {
                    if (b.Owner == c)
                    {
                        continue;
                    }
                    if (c.Collides(b))
                    {
                        c.Hit(b);
                        b.WorldNode.Remove();
                        Bullets.Remove(b);
                        deleted = true;
                        break;
                    }
                }

                if (deleted)
                {
                    continue;
                }

                foreach (WorldObject o in collisionObjects)
                {
                    if (b.WorldNode.IsDeleted || o.WorldNode.IsDeleted)
                    {
                        continue;
                    }

                    if (o.Collides(b))
                    {
                        b.WorldNode.Remove();
                        Bullets.Remove(b);
                        break;
                    }
                }
            }

            // PlayerCharacter may have to be loaded from saved game
            if (PlayerCharacter != null)
            {
                PlayerCharacter.Input.W         = Input.GetKeyDown(Key.W);
                PlayerCharacter.Input.A         = Input.GetKeyDown(Key.A);
                PlayerCharacter.Input.S         = Input.GetKeyDown(Key.S);
                PlayerCharacter.Input.D         = Input.GetKeyDown(Key.D);
                PlayerCharacter.Input.F         = Input.GetKeyDown(Key.F);
                PlayerCharacter.Input.Space     = Input.GetKeyPress(Key.Space);
                PlayerCharacter.Input.LeftClick = Input.GetKeyDown(Key.E);


                Vector2 mousePosition = new Vector2(Input.MousePosition.X, Input.MousePosition.Y);
                Vector2 resolution    = new Vector2(Graphics.Width, Graphics.Height);
                Vector2 mouseUV       = ((2f * mousePosition) - resolution) / resolution.Y;
                mouseUV.Y *= -1f;
                PlayerCharacter.Input.MousePosition = mouseUV;

                foreach (Character c in Characters.ToList())
                {
                    // Death
                    if (c.Health <= 0)
                    {
                        // sound effect
                        // create new node to play sound from, as character will be removed
                        var node = new Scene().CreateChild();
                        node.Position = c.Position;
                        PlaySound("sounds/effects/death.ogg", false);

                        c.WorldNode.Remove();
                        Characters.Remove(c);

                        if (c.LastBullet.Owner is CharacterPlayer)
                        {
                            if (hardcore)
                            {
                                PlayerCharacter.Score += 150;
                            }
                            else
                            {
                                PlayerCharacter.Score += 100;
                            }
                        }

                        if (Characters.Count == 1 && Characters.First() == PlayerCharacter)
                        {
                            gameover      = true;
                            timer.Enabled = false;
                            HandleWin();
                        }
                        else if (c == PlayerCharacter)
                        {
                            gameover      = true;
                            timer.Enabled = false;
                            HandleLose();
                        }

                        continue;
                    }

                    c.UpdateCollision(collisionObjects);
                    c.Update(timeStep);
                }

                PlayerCharacter.Input.LeftClick = false;

                if (Input.GetKeyDown(Key.F1) && !schaubMode)
                {
                    Save("latest.txt");
                    var saved = new Text()
                    {
                        Value = "Game Saved"
                    };

                    saved.SetColor(Color.Cyan);
                    saved.SetFont(font: ResourceCache.GetFont("fonts/FiraSans-Regular.otf"), size: 15);
                    saved.VerticalAlignment   = VerticalAlignment.Center;
                    saved.HorizontalAlignment = HorizontalAlignment.Center;

                    InvokeOnMain(() => { UI.Root.AddChild(saved); });
                    await Task.Delay(500);

                    try
                    {
                        InvokeOnMain(() =>
                        {
                            try { UI.Root.RemoveChild(saved); }
                            catch { return; }
                        });
                    }
                    catch { return; }
                }

                if (Input.GetKeyDown(Key.F2))
                {
                    timer.Enabled = false;
                    Restart();
                }
            }
        }