public void GetBlock(FallingBlock block)
 {
     block.myCell = this;
     ocupied      = true;
     myBlock      = block;
     color        = block.colNum;
 }
Example #2
0
 public bool Rotate()
 {
     if (CanRotate())
     {
         FallingBlock.OffsetRotation();
         return(true);
     }
     return(false);
 }
Example #3
0
        public GravityTestForm()
        {
            // C# doin' his thing
            InitializeComponent();

            // get actual width and height
            wHeight = ClientSize.Height;
            wWidth  = ClientSize.Width;

            grid          = new Grid(Width / 30);
            _fallingBlock = new FallingBlock(30, 30, 30, Brushes.BlueViolet);
        }
Example #4
0
 private void LoadBlocks()
 {
     spawned = 0;
     do
     {
         GameObject   obj   = GameObject.Instantiate(prefab, transform.position, Quaternion.identity) as GameObject;
         FallingBlock clone = obj.GetComponent <FallingBlock>();
         obj.transform.parent = transform;
         clone.Init(startPos, this);
         objects.Enqueue(clone);
         spawned++;
     }while(spawned < MAX_BLOCKS);
 }
Example #5
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        bpm         = EditorGUILayout.FloatField("BPM", bpm);
        blockOffset = EditorGUILayout.FloatField("Block Offset", blockOffset);

        FallingBlock block = (FallingBlock)serializedObject.targetObject;

        float blockBeat = (block.transform.position.y - 0.5f * block.blockHeight - blockOffset) / block.fallSpeed / 60f * bpm;

        blockBeat = EditorGUILayout.FloatField("Block Beat", blockBeat);
        block.transform.position = new Vector3(block.transform.position.x, (0.5f * block.blockHeight + blockOffset) + (blockBeat / bpm * 60 * block.fallSpeed), block.transform.position.z);
    }
Example #6
0
        public override void BlockUpdate(World world, int x, int y)
        {
            if (world.InBounds(x, y + 1) && world.GetTile(x, y + 1).id == 0)
            {
                var fB = new FallingBlock(world, world.GetTile(x, y));
                fB.transform.position = new Vector2(x, y);

                //world.NPCs.Add(fB);
                world.SpawnEntity(fB);

                world.SetTile(new Tile(0), x, y, true, true);

                //world.UpdateOthers(x, y);
            }
        }
Example #7
0
        public void LoadLevel(String lvlName)
        {
            this.LevelName = lvlName;

            Bitmap bmp = (Bitmap)Image.FromFile(Resources.RESOURCE_PATH + "\\src\\game\\levels\\" + lvlName + ".bmp");

            levelBounds = new RectangleF(0, 0, bmp.Width * Block.WIDTH, bmp.Height * Block.HEIGHT);

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    string hexColor = bmp.GetPixel(x, y).Name.ToUpper();

                    if (hexColor != "FFFF00FF")   //Check if the pixel does not represent an empty tile (pink)
                    {
                        BaseEntity ent;
                        if (hexColor == "FF5EF6FF")
                        {
                            ent = new FallingBlock(x * Block.WIDTH, y * Block.HEIGHT, GameTextures.IceBlock);
                            Game.AddCollidableEntity(ent);
                        }
                        else if (hexColor == "FFFF2340")
                        {
                            ent = new BouncyBlock(x * Block.WIDTH, y * Block.HEIGHT, GameTextures.ArrowRight);
                            Game.AddCollidableEntity(ent);
                        }
                        else if (hexColor == "FF000000")
                        {
                            ent = new Penguin(x * Block.WIDTH, y * Block.HEIGHT);
                            Camera.GetInstance().SetActor(ent);
                            EntityController.GetInstance().SetPuppetEntity((ControllableEntity)ent);
                            Game.AddCollidableEntity(ent);
                        }
                        else if (hexColor == "FFFFFFFF")
                        {
                            ent = new Block(x * Block.WIDTH, y * Block.HEIGHT, GameTextures.SnowBlock);
                            Game.AddEntity(ent);
                        }
                        else
                        {
                            ent = new Block(x * Block.WIDTH, y * Block.HEIGHT, GameTextures.UnknowEntity);
                            Game.AddEntity(ent);
                        }
                    }
                }
            }
        }
    void PickUp(FallingBlock block)
    {
        if (block.inGrid)
        {
            block.inGrid = false;
            block.myCell.LoseBlock();
            block.myCell = null;
        }
        block.pickedUp       = true;
        block.rb.isKinematic = true;
        grabbedBlock         = block;
        block.UnSelected();
        block.rb.velocity = Vector2.zero;

        //NewSound
        AudioDirector.Instance.PlaySound(AudioDirector.Instance.pickupSound, true, transform.position.x, AudioDirector.Instance.pickupVolume, 0.2f);
    }
Example #9
0
    // Update is called once per frame
    void Update()
    {
        if (gameOver)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                SceneManager.LoadScene(0);
            }
        }

        FallingBlock fallingBlock = FindObjectOfType <FallingBlock>();

        if (fallingBlock != null)
        {
            fallingBlock.OnPlayerDeath += OnGameOver;
        }
    }
Example #10
0
 public void RotateBlockAntiClockwiseIfPossible()
 {
     if (FallingBlock == null)
     {
         return;
     }
     FallingBlock.RotateAntiClockwise();
     if (Get <Grid>().IsValidPosition(FallingBlock))
     {
         Get <Soundbank>().BlockMoved.Play();
     }
     else
     {
         FallingBlock.RotateClockwise();
         Get <Soundbank>().BlockCouldNotMove.Play();
     }
 }
Example #11
0
    public void ConnectWithBlock(FallingBlock block)
    {
        // Remove the falling block component and add the bucket block component
        GameObject blockObj    = block.gameObject;
        float      blockHeight = block.blockHeight;

        Object.Destroy(block);
        BucketBlock newBlock = blockObj.AddComponent <BucketBlock>();

        newBlock.blockHeight = blockHeight;

        // Add this to the blocks list
        blocks.Add(newBlock);
        newBlock.transform.position = blockStackParent.transform.position + nextBlockRelativePosition + new Vector3(0, 0.5f * blockHeight, 0);
        newBlock.transform.parent   = blockStackParent;
        nextBlockRelativePosition   = new Vector3(nextBlockRelativePosition.x, nextBlockRelativePosition.y + blockHeight, nextBlockRelativePosition.z);
        blockStackTotalHeight      += blockHeight;
    }
        public void ConvertFrozenBlockToFallingOrColorBlock(FrozenBlock aBlock)
        {
            AbstractBlock blockBeneath = myGridBundle.Container.GetBlockAtPosition(aBlock.GetPosition() + new Point(0, -1));
            AbstractBlock newBlock;

            if (blockBeneath.AllowsFalling())
            {
                newBlock = new FallingBlock(myGridBundle, aBlock.GetColor());
                ((FallingBlock)newBlock).CanChain = true;
            }
            else
            {
                newBlock = new ColorBlock(myGridBundle, aBlock.GetColor(), true);
            }

            myGridBundle.Container.SetBlock(aBlock.GetPosition(), newBlock);
            newBlock.LoadContent();
        }
Example #13
0
    private void SpawnBlock()
    {
        MemorySpace[]      memorySpaces    = GameObject.FindObjectsOfType <MemorySpace>();
        List <MemorySpace> availableSpaces = new List <MemorySpace>();
        List <MemorySpace> specialSpaces   = new List <MemorySpace>();


        for (int i = 0; i < memorySpaces.Length; i++)
        {
            if (!memorySpaces[i].occupied && !memorySpaces[i].locked && !memorySpaces[i].doNotSpawn)
            {
                availableSpaces.Add(memorySpaces[i]);
            }
            if (!memorySpaces[i].occupied && !memorySpaces[i].locked && memorySpaces[i].doNotSpawn)
            {
                specialSpaces.Add(memorySpaces[i]);
            }
        }

        if (availableSpaces.Count < 1)
        {
            availableSpaces = specialSpaces;
        }

        canSpawn = true;
        if (availableSpaces.Count < 1)
        {
            on       = false;
            canSpawn = false;
            return;
        }
        int         chosenMemorySpace = UnityEngine.Random.Range(0, availableSpaces.Count);
        MemorySpace memSpace          = availableSpaces[chosenMemorySpace];

        memSpace.Lock();
        FallingBlock fallingBlock = Instantiate(fallingBlockPrefab, memSpace.transform.position + spawnHeight * Vector3.up, Quaternion.identity);

        fallingBlock.setValue(UnityEngine.Random.Range(1, 8));
        fallingBlock.setTargetHeight(memSpace.transform.position.y);
    }
Example #14
0
        public void OnUserAction(GameKey key)
        {
            if (FallingBlock == null)
            {
                return;
            }

            if (key == GameKey.LEFT)
            {
                if (FallingBlock.CanMove(GameSide.Left, Field))
                {
                    FallingBlock.Move(GameSide.Left);
                }
            }

            if (key == GameKey.RIGHT)
            {
                if (FallingBlock.CanMove(GameSide.Right, Field))
                {
                    FallingBlock.Move(GameSide.Right);
                }
            }

            if (key == GameKey.DOWN)
            {
                if (FallingBlock.CanMove(GameSide.Down, Field))
                {
                    FallingBlock.Move(GameSide.Down);
                }
            }

            if (key == GameKey.SPACE)
            {
                if (FallingBlock.CanTurn(Field))
                {
                    FallingBlock.Turn();
                }
            }
        }
Example #15
0
    IEnumerator BlocksFallDownDomino(float _waitTime)
    {
        if (blocksFolders.Count <= 0)
        {
            yield break;
        }

        /*for (int i = 0; i < blocksFolder.transform.childCount; i++)
         * {
         *      yield return new WaitForSeconds(_waitTime);
         *      FallingBlock _block = blocksFolder.transform.GetChild(i).GetComponent<FallingBlock>();
         *      _block.canFall = true;
         * }*/
        GameObject _blocksFolder = blocksFolders[blocksFolders.Count - 1];

        if (blockNr >= _blocksFolder.transform.childCount)
        {
            //InstantiateBlocks();
            //blockNr = 0;

            InstantiateBlocks();
            blockNr         = 0;
            shouldBlockWait = false;
            //amountOfBlockfoldersSpawned++;
            yield break;
        }

        else
        {
            shouldBlockWait = true;
            FallingBlock _block = _blocksFolder.transform.GetChild(blockNr).GetComponent <FallingBlock>();
            _block.canFall = true;
            yield return(new WaitForSeconds(_waitTime));

            blockNr++;
            shouldBlockWait = false;
        }
    }
Example #16
0
 public bool CanMoveRight()
 {
     if (FallingBlock != null)
     {
         for (var row = 0; row <= 3; row++)
         {
             for (var column = 3; column >= 0; column += -1)
             {
                 if (FallingBlock.FilledCell(column, row))
                 {
                     var pt = BlockToBoard(new CellPoint(row, column));
                     if (pt.Column.Equals(Columns - 1) ||
                         Cells[new CellPoint(pt.Row, pt.Column + 1).ToString()].Fixed)
                     {
                         return(false);
                     }
                 }
             }
         }
         return(true);
     }
     return(false);
 }
Example #17
0
        public Color GetCellColor(CellPoint p)
        {
            var output = Color.Transparent;

            if (Cells[p.Row + "," + p.Column].Fixed)
            {
                output = Cells[p.Row + "," + p.Column].Color;
            }
            else
            {
                if (FallingBlock != null && CellIsInsideBlock(p.Row, p.Column))
                {
                    var pt = BoardToBlock(p);

                    if (FallingBlock.FilledCell(pt.Column, pt.Row))
                    {
                        output = FallingBlock.Color;
                    }
                }
            }

            return(output);
        }
    private void OnCollisionStay2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "Block" &&
            (Input.GetKey(left) || Input.GetKey(right)))
        {
            pushing = 2;
            pushTimer++;
            if (pushTimer > 5)
            {
                FallingBlock block = coll.gameObject.GetComponent <FallingBlock>();

                if (block.inGrid &&
                    !Grid.me.grid[(int)block.myCell.gridPos.x, (int)block.myCell.gridPos.y + 1].ocupied &&
                    !Grid.me.grid[(int)block.myCell.gridPos.x + facing, (int)block.myCell.gridPos.y].ocupied)
                {
                    block.inGrid = false;
                    block.myCell.LoseBlock();
                    block.myCell         = null;
                    block.rb.isKinematic = false;
                    block.rb.AddForce(Vector2.right * facing * 2f, ForceMode2D.Impulse);
                }
            }
        }
    }
 void Start()
 {
     fallingBlock = fallingBlock.GetComponent<FallingBlock>();
 }
 public void LoseBlock()
 {
     ocupied = false;
     myBlock = null;
     color   = -1;
 }
        private IEnumerator AttackSequence()
        {
            Input.Rumble(RumbleStrength.Strong, RumbleLength.Medium);
            StartShaking(0.4f);
            yield return((object)0.4f);

            if (!chillOut)
            {
                canActivate = true;
            }
            base.StopPlayerRunIntoAnimation = false;
            bool    slowing = false;
            float   speed2  = 0f;
            Vector2 speeds  = variableSpeeds[speedIdx];

            while (true)
            {
                if (!chillOut)
                {
                    speed2 = Calc.Approach(speed2, speeds.X, speeds.Y * Engine.DeltaTime);
                }
                else if (slowing || ((Entity)this).CollideCheck <SolidTiles>(base.Position + crushDir * 256f))
                {
                    speed2 = Calc.Approach(speed2, 24f, 500f * Engine.DeltaTime * 0.25f);
                    if (!slowing)
                    {
                        slowing = true;
                        Alarm.Set(this, 0.5f, delegate
                        {
                            face.Play("hurt", false, false);
                            currentMoveLoopSfx.Stop(true);
                            TurnOffImages();
                        }, Alarm.AlarmMode.Oneshot);
                    }
                }
                else
                {
                    speed2 = Calc.Approach(speed2, speeds.X, speeds.Y * Engine.DeltaTime);
                }
                if (!((crushDir.X == 0f) ? MoveVCheck(speed2 * crushDir.Y * Engine.DeltaTime) : MoveHCheck(speed2 * crushDir.X * Engine.DeltaTime)))
                {
                    if (Scene.OnInterval(0.02f))
                    {
                        Vector2 position;
                        float   direction;
                        if (crushDir == Vector2.UnitX)
                        {
                            position  = new Vector2(Left + 1f, Calc.Random.Range(Top + 3f, Bottom - 3f));
                            direction = 3.14159274f;
                        }
                        else if (crushDir == -Vector2.UnitX)
                        {
                            position  = new Vector2(Right - 1f, Calc.Random.Range(Top + 3f, Bottom - 3f));
                            direction = 0f;
                        }
                        else if (crushDir == Vector2.UnitY)
                        {
                            position  = new Vector2(Calc.Random.Range(Left + 3f, Right - 3f), Top + 1f);
                            direction = -1.57079637f;
                        }
                        else
                        {
                            position  = new Vector2(Calc.Random.Range(Left + 3f, Right - 3f), Bottom - 1f);
                            direction = 1.57079637f;
                        }
                        //level.Particles.Emit(P_Crushing, position, direction);
                    }
                    yield return((object)null);

                    continue;
                }
                break;
            }
            FallingBlock fallingBlock = CollideFirst <FallingBlock>(base.Position + crushDir);

            if (fallingBlock != null)
            {
                fallingBlock.Triggered = true;
            }
            if (crushDir == -Vector2.UnitX)
            {
                Vector2 value = new Vector2(0f, 2f);
                for (int i = 0; (float)i < Height / 8f; i++)
                {
                    Vector2 vector = new Vector2(Left - 1f, Top + 4f + (float)(i * 8));
                    if (!Scene.CollideCheck <Water>(vector) && Scene.CollideCheck <Solid>(vector))
                    {
                        //SceneAs<Level>().ParticlesFG.Emit(P_Impact, vector + value, 0f);
                        //SceneAs<Level>().ParticlesFG.Emit(P_Impact, vector - value, 0f);
                    }
                }
            }
            else if (crushDir == Vector2.UnitX)
            {
                Vector2 value2 = new Vector2(0f, 2f);
                for (int j = 0; (float)j < Height / 8f; j++)
                {
                    Vector2 vector2 = new Vector2(Right + 1f, Top + 4f + (float)(j * 8));
                    if (!Scene.CollideCheck <Water>(vector2) && Scene.CollideCheck <Solid>(vector2))
                    {
                        //SceneAs<Level>().ParticlesFG.Emit(P_Impact, vector2 + value2, 3.14159274f);
                        //SceneAs<Level>().ParticlesFG.Emit(P_Impact, vector2 - value2, 3.14159274f);
                    }
                }
            }
            else if (crushDir == -Vector2.UnitY)
            {
                Vector2 value3 = new Vector2(2f, 0f);
                for (int k = 0; (float)k < Width / 8f; k++)
                {
                    Vector2 vector3 = new Vector2(Left + 4f + (float)(k * 8), Top - 1f);
                    if (!Scene.CollideCheck <Water>(vector3) && Scene.CollideCheck <Solid>(vector3))
                    {
                        //SceneAs<Level>().ParticlesFG.Emit(P_Impact, vector3 + value3, 1.57079637f);
                        //SceneAs<Level>().ParticlesFG.Emit(P_Impact, vector3 - value3, 1.57079637f);
                    }
                }
            }
            else if (crushDir == Vector2.UnitY)
            {
                Vector2 value4 = new Vector2(2f, 0f);
                for (int l = 0; (float)l < Width / 8f; l++)
                {
                    Vector2 vector4 = new Vector2(Left + 4f + (float)(l * 8), Bottom + 1f);
                    if (!Scene.CollideCheck <Water>(vector4) && Scene.CollideCheck <Solid>(vector4))
                    {
                        //SceneAs<Level>().ParticlesFG.Emit(P_Impact, vector4 + value4, -1.57079637f);
                        //SceneAs<Level>().ParticlesFG.Emit(P_Impact, vector4 - value4, -1.57079637f);
                    }
                }
            }
            Audio.Play("event:/game/06_reflection/crushblock_impact", Center);
            level.DirectionalShake(crushDir, 0.3f);
            Input.Rumble(RumbleStrength.Medium, RumbleLength.Medium);
            StartShaking(0.4f);
            base.StopPlayerRunIntoAnimation = true;
            SoundSource sfx = currentMoveLoopSfx;

            currentMoveLoopSfx.Param("end", 1f);
            currentMoveLoopSfx = null;
            Alarm.Set(this, 0.5f, delegate
            {
                sfx.RemoveSelf();
            }, Alarm.AlarmMode.Oneshot);
            crushDir = Vector2.Zero;
            TurnOffImages();
            if (!chillOut)
            {
                face.Play("hurt", false, false);
                returnLoopSfx.Play("event:/game/06_reflection/crushblock_return_loop", null, 0f);
                yield return((object)0.4f);

                float speed            = 0f;
                float waypointSfxDelay = 0f;
                while (returnStack.Count > 0)
                {
                    yield return((object)null);

                    speedIdx = 0;
                    base.StopPlayerRunIntoAnimation = false;
                    MoveState moveState = returnStack[returnStack.Count - 1];
                    speed             = Calc.Approach(speed, 60f, 160f * Engine.DeltaTime);
                    waypointSfxDelay -= Engine.DeltaTime;
                    if (moveState.Direction.X != 0f)
                    {
                        MoveTowardsX(moveState.From.X, speed * Engine.DeltaTime);
                    }
                    if (moveState.Direction.Y != 0f)
                    {
                        MoveTowardsY(moveState.From.Y, speed * Engine.DeltaTime);
                    }
                    if ((moveState.Direction.X == 0f || ExactPosition.X == moveState.From.X) && (moveState.Direction.Y == 0f || ExactPosition.Y == moveState.From.Y))
                    {
                        speed = 0f;
                        returnStack.RemoveAt(returnStack.Count - 1);
                        base.StopPlayerRunIntoAnimation = true;
                        if (returnStack.Count <= 0)
                        {
                            face.Play("idle", false, false);
                            returnLoopSfx.Stop(true);
                            if (waypointSfxDelay <= 0f)
                            {
                                Audio.Play("event:/game/06_reflection/crushblock_rest", Center);
                            }
                        }
                        else if (waypointSfxDelay <= 0f)
                        {
                            Audio.Play("event:/game/06_reflection/crushblock_rest_waypoint", Center);
                        }
                        waypointSfxDelay = 0.1f;
                        StartShaking(0.2f);
                        yield return((object)0.2f);
                    }
                }
            }
        }
    void GrabDeal()
    {
        if (Input.GetKeyDown(grabButton) && grabbedBlock == null && selectedBlock == null)
        {
            justPressedGrabTimer = .0833334f;
        }
        if (Input.GetKeyDown(grabButton) || justPressedGrabTimer > 0)
        {
            if (grabbedBlock == null)
            {
                if (selectedBlock != null)
                {
                    justPressedGrabTimer = 0;
                    PickUp(selectedBlock.transform.parent.GetComponent <FallingBlock>());
                }
            }
            else
            {
                //throw block
                //NewSound
                AudioDirector.Instance.PlaySound(AudioDirector.Instance.throwSound, true, transform.position.x, AudioDirector.Instance.throwVolume, 0.2f);

                grabbedBlock.pickedUp       = false;
                grabbedBlock.rb.isKinematic = false;

                grabbedBlock.rb.velocity = new Vector2(rb.velocity.x * .5f, rb.velocity.y * .2f);
                if (!Input.GetKey(down))
                {
                    grabbedBlock.justThrownTimer = .1f;
                    if (Input.GetKey(up))
                    {
                        if (!(Input.GetKey(right) || Input.GetKey(left)))
                        {
                            grabbedBlock.rb.AddForce(new Vector2(0f, 12f), ForceMode2D.Impulse);
                        }
                        else
                        {
                            grabbedBlock.rb.AddForce(new Vector2(4f * facing, 12f), ForceMode2D.Impulse);
                        }
                    }
                    else
                    {
                        grabbedBlock.rb.AddForce(new Vector2(5f * facing, 10f), ForceMode2D.Impulse);
                    }
                }
                else
                {
                    grabbedBlock.transform.position = (Vector2)transform.position + new Vector2(0f, 0.5f);
                    transform.position       = ((Vector2)transform.position + new Vector2(0f, 1.5f));
                    rb.velocity              = new Vector2(rb.velocity.x, 0);
                    grabbedBlock.rb.velocity = Vector2.zero;

                    if (!onFloor)
                    {
                        grabbedBlock.rb.AddForce(new Vector2(0f, -8f), ForceMode2D.Impulse);
                        blockJumped = true;
                        rb.AddForce(new Vector2(0f, 12f), ForceMode2D.Impulse);
                    }
                }
                grabbedBlock = null;
            }
        }
    }
Example #23
0
    void OnTriggerEnter2D(Collider2D triggerCollider)
    {
        if (!triggerCollider.CompareTag("Falling Block"))
        {
            return;
        }

        // Verifica si el bloque con el que hace colisión pertenece a la paleta de colores
        GameObject fallingBlockGameObject = GameObject.FindGameObjectWithTag("Falling Block");

        FallingBlock fallingBlock = fallingBlockGameObject.GetComponent <FallingBlock>();

        Color32 color = fallingBlock.color;

        if (_colours.Contains(color))
        {
            // Verifica que el color no esté en el score
            if (score.scores.Select(i =>
                                    i.GetComponent <MeshRenderer>().material.color)
                .Any(_color => ((Color32)_color).Equals(color)))
            {
                return;
            }

            FindObjectOfType <AudioManager>().Play("ScoreAudio");

            score.score++;

            if (health.health < 5)
            {
                health.health++;
            }

            MeshRenderer rend = score.scores[score.score - 1].GetComponent <MeshRenderer>();

            rend.material.color = new Color32(color.r, color.g, color.b, 255);

            Debug.Log(score.score);

            if (score.score == score.totalScore)
            {
                Loader.NextScene();
            }

            return;
        }


        FindObjectOfType <AudioManager>().Play("DamageAudio");

        health.health--;

        if (health.health != 0)
        {
            return;
        }
        health.hearts[0].sprite = health.emptyHeart;

        FindObjectOfType <AudioManager>().Stop("Theme_02");
        FindObjectOfType <AudioManager>().Play("Theme_01");

        Destroy(gameObject);

        Loader.Load(Loader.Scene.GameOver);
    }
        private IEnumerator AttackSequence()
        {
            Input.Rumble(RumbleStrength.Strong, RumbleLength.Medium);
            StartShaking(0.4f);
            yield return(0.4f);

            bool flag = !chillOut;

            if (flag)
            {
                canActivate = true;
            }
            StopPlayerRunIntoAnimation = false;
            bool   slowing = false;
            float  speed   = 0f;
            Action som     = null; // = null wasn't there

            while (true)
            {
                if (!chillOut)
                {
                    speed = Calc.Approach(speed, CrushSpeed, CrushAccel * Engine.DeltaTime); // was speed, 240f, 500f
                }
                else
                {
                    if (slowing || CollideCheck <SolidTiles>(Position + crushDir * 256f))
                    {
                        speed = Calc.Approach(speed, 12f, CrushAccel * Engine.DeltaTime * 0.25f); // was speed, 24f, 500f

                        if (!slowing)
                        {
                            slowing = true;
                            float  duration = 0.5f;
                            Action onComplete;
                            if ((onComplete = som) == null)
                            {
                                onComplete = som = delegate()
                                {
                                    face.Play("hurt", false, false);
                                    currentMoveLoopSfx.Stop(true);
                                    TurnOffImages();
                                };
                            }
                            Alarm.Set(this, duration, onComplete, Alarm.AlarmMode.Oneshot);
                        }
                    }
                    else
                    {
                        speed = Calc.Approach(speed, CrushSpeed, CrushAccel * Engine.DeltaTime); // was speed, 240f, 500f
                    }
                }
                bool hit;
                if (crushDir.X != 0f)
                {
                    hit = MoveHCheck(speed * crushDir.X * Engine.DeltaTime);
                }
                else
                {
                    hit = MoveVCheck(speed * crushDir.Y * Engine.DeltaTime);
                }

                if (hit)
                {
                    break;
                }

                if (Scene.OnInterval(0.02f))
                {
                    Vector2 at;
                    float   dir;
                    if (crushDir == Vector2.UnitX)
                    {
                        at  = new Vector2(Left + 1f, Calc.Random.Range(Top + 3f, Bottom - 3f));
                        dir = 3.14159274f;
                    }
                    else
                    {
                        if (crushDir == -Vector2.UnitX)
                        {
                            at  = new Vector2(Right - 1f, Calc.Random.Range(Top + 3f, Bottom - 3f));
                            dir = 0f;
                        }
                        else
                        {
                            if (crushDir == Vector2.UnitY)
                            {
                                at  = new Vector2(Calc.Random.Range(Left + 3f, Right - 3f), Top + 1f);
                                dir = -1.57079637f;
                            }
                            else
                            {
                                at  = new Vector2(Calc.Random.Range(Left + 3f, Right - 3f), Bottom - 1f);
                                dir = 1.57079637f;
                            }
                        }
                    }
                    level.Particles.Emit(CrushBlock.P_Crushing, at, dir);
                    at = default;
                }
                yield return(null);
            }

            FallingBlock fallingBlock = CollideFirst <FallingBlock>(Position + crushDir);

            if (fallingBlock != null)
            {
                fallingBlock.Triggered = true;
            }

            if (crushDir == -Vector2.UnitX)
            {
                Vector2 add = new Vector2(0f, 2f);
                int     i   = 0;
                while (i < Height / 8f)
                {
                    Vector2 at2    = new Vector2(Left - 1f, Top + 4f + i * 8);
                    bool    flag13 = !Scene.CollideCheck <Water>(at2) && Scene.CollideCheck <Solid>(at2);
                    if (flag13)
                    {
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, at2 + add, 0f);
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, at2 - add, 0f);
                    }
                    at2 = default;
                    int num = i;
                    i = num + 1;
                }
                add = default;
            }
            else
            {
                if (crushDir == Vector2.UnitX)
                {
                    Vector2 add2 = new Vector2(0f, 2f);
                    int     j    = 0;
                    while (j < Height / 8f)
                    {
                        Vector2 at3    = new Vector2(Right + 1f, Top + 4f + j * 8);
                        bool    flag15 = !Scene.CollideCheck <Water>(at3) && Scene.CollideCheck <Solid>(at3);
                        if (flag15)
                        {
                            SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, at3 + add2, 3.14159274f);
                            SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, at3 - add2, 3.14159274f);
                        }
                        at3 = default;
                        int num = j;
                        j = num + 1;
                    }
                    add2 = default;
                }
                else
                {
                    bool flag16 = crushDir == -Vector2.UnitY;
                    if (flag16)
                    {
                        Vector2 add3 = new Vector2(2f, 0f);
                        int     k    = 0;
                        while (k < Width / 8f)
                        {
                            Vector2 at4    = new Vector2(Left + 4f + k * 8, Top - 1f);
                            bool    flag17 = !Scene.CollideCheck <Water>(at4) && Scene.CollideCheck <Solid>(at4);
                            if (flag17)
                            {
                                SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, at4 + add3, 1.57079637f);
                                SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, at4 - add3, 1.57079637f);
                            }
                            at4 = default;
                            int num = k;
                            k = num + 1;
                        }
                        add3 = default;
                    }
                    else
                    {
                        bool flag18 = crushDir == Vector2.UnitY;
                        if (flag18)
                        {
                            Vector2 add4 = new Vector2(2f, 0f);
                            int     l    = 0;
                            while (l < Width / 8f)
                            {
                                Vector2 at5    = new Vector2(Left + 4f + l * 8, Bottom + 1f);
                                bool    flag19 = !Scene.CollideCheck <Water>(at5) && Scene.CollideCheck <Solid>(at5);
                                if (flag19)
                                {
                                    SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, at5 + add4, -1.57079637f);
                                    SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, at5 - add4, -1.57079637f);
                                }
                                at5 = default;
                                int num = l;
                                l = num + 1;
                            }
                            add4 = default;
                        }
                    }
                }
            }
            Audio.Play("event:/game/06_reflection/crushblock_impact", Center);
            level.DirectionalShake(crushDir, 0.3f);
            Input.Rumble(RumbleStrength.Medium, RumbleLength.Medium);
            StartShaking(0.4f);
            StopPlayerRunIntoAnimation = true;
            SoundSource sfx = currentMoveLoopSfx;

            currentMoveLoopSfx.Param("end", 1f);
            currentMoveLoopSfx = null;
            Alarm.Set(this, 0.5f, delegate
            {
                sfx.RemoveSelf();
            }, Alarm.AlarmMode.Oneshot);
            crushDir = Vector2.Zero;
            TurnOffImages();
            bool flag20 = !chillOut;

            if (flag20)
            {
                face.Play("hurt", false, false);
                returnLoopSfx.Play("event:/game/06_reflection/crushblock_return_loop", null, 0f);
                yield return(0.4f);

                float speed2           = 0f;
                float waypointSfxDelay = 0f;
                while (returnStack.Count > 0)
                {
                    yield return(null);

                    StopPlayerRunIntoAnimation = false;
                    CustomCrushBlock.MoveState ret = returnStack[returnStack.Count - 1];
                    speed2            = Calc.Approach(speed2, ReturnSpeed, ReturnAccel * Engine.DeltaTime);
                    waypointSfxDelay -= Engine.DeltaTime;
                    bool flag21 = ret.Direction.X != 0f;
                    if (flag21)
                    {
                        MoveTowardsX(ret.From.X, speed2 * Engine.DeltaTime);
                    }
                    bool flag22 = ret.Direction.Y != 0f;
                    if (flag22)
                    {
                        MoveTowardsY(ret.From.Y, speed2 * Engine.DeltaTime);
                    }
                    bool atTarget = (ret.Direction.X == 0f || ExactPosition.X == ret.From.X) && (ret.Direction.Y == 0f || ExactPosition.Y == ret.From.Y);
                    bool flag23   = atTarget;
                    if (flag23)
                    {
                        speed2 = 0f;
                        returnStack.RemoveAt(returnStack.Count - 1);
                        StopPlayerRunIntoAnimation = true;
                        bool flag24 = returnStack.Count <= 0;
                        if (flag24)
                        {
                            face.Play("idle", false, false);
                            returnLoopSfx.Stop(true);
                            bool flag25 = waypointSfxDelay <= 0f;
                            if (flag25)
                            {
                                Audio.Play("event:/game/06_reflection/crushblock_rest", Center);
                            }
                        }
                        else
                        {
                            if (waypointSfxDelay <= 0f)
                            {
                                Audio.Play("event:/game/06_reflection/crushblock_rest_waypoint", Center);
                            }
                        }
                        waypointSfxDelay = 0.1f;
                        StartShaking(0.2f);
                        yield return(0.2f);
                    }
                    ret = default;
                }
            }
            yield break;
        }
Example #25
0
        protected IEnumerator CeaseMovement()
        {
            attackCoroutine.Cancel();
            FallingBlock fallingBlock = CollideFirst <FallingBlock>(Position + crushDir);

            if (fallingBlock != null)
            {
                fallingBlock.Triggered = true;
            }
            if (crushDir == -Vector2.UnitX)
            {
                Vector2 value = new Vector2(0f, 2f);
                for (int i = 0; i < Height / 8f; i++)
                {
                    Vector2 vector = new Vector2(Left - 1f, Top + 4f + (i * 8));
                    if (!Scene.CollideCheck <Water>(vector) && Scene.CollideCheck <Solid>(vector))
                    {
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, vector + value, 0f);
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, vector - value, 0f);
                    }
                }
            }
            else if (crushDir == Vector2.UnitX)
            {
                Vector2 value2 = new Vector2(0f, 2f);
                for (int j = 0; j < Height / 8f; j++)
                {
                    Vector2 vector2 = new Vector2(Right + 1f, Top + 4f + (j * 8));
                    if (!Scene.CollideCheck <Water>(vector2) && Scene.CollideCheck <Solid>(vector2))
                    {
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, vector2 + value2, (float)Math.PI);
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, vector2 - value2, (float)Math.PI);
                    }
                }
            }
            else if (crushDir == -Vector2.UnitY)
            {
                Vector2 value3 = new Vector2(2f, 0f);
                for (int k = 0; k < Width / 8f; k++)
                {
                    Vector2 vector3 = new Vector2(Left + 4f + (k * 8), Top - 1f);
                    if (!Scene.CollideCheck <Water>(vector3) && Scene.CollideCheck <Solid>(vector3))
                    {
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, vector3 + value3, (float)Math.PI / 2f);
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, vector3 - value3, (float)Math.PI / 2f);
                    }
                }
            }
            else if (crushDir == Vector2.UnitY)
            {
                Vector2 value4 = new Vector2(2f, 0f);
                for (int l = 0; l < Width / 8f; l++)
                {
                    Vector2 vector4 = new Vector2(Left + 4f + (l * 8), Bottom + 1f);
                    if (!Scene.CollideCheck <Water>(vector4) && Scene.CollideCheck <Solid>(vector4))
                    {
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, vector4 + value4, -(float)Math.PI / 2f);
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, vector4 - value4, -(float)Math.PI / 2f);
                    }
                }
            }
            Audio.Play("event:/game/06_reflection/crushblock_impact", Center);
            level.DirectionalShake(crushDir);
            Input.Rumble(RumbleStrength.Medium, RumbleLength.Medium);
            StartShaking(0.4f);
            StopPlayerRunIntoAnimation = true;
            SoundSource sfx = currentMoveLoopSfx;

            currentMoveLoopSfx.Param("end", 1f);
            currentMoveLoopSfx = null;
            Alarm.Set(this, 0.5f, delegate {
                sfx.RemoveSelf();
            });
            crushDir = Vector2.Zero;
            TurnOffImages();
            if (chillOut)
            {
                yield break;
            }
            face.Play("hurt");
            returnLoopSfx.Play("event:/game/06_reflection/crushblock_return_loop");
            yield return(0.4f);

            face.Play("idle");
            returnLoopSfx.Stop();
            Audio.Play("event:/game/06_reflection/crushblock_rest", Center);
        }
 void Start()
 {
     fallingBlock = fallingBlock.GetComponent <FallingBlock>();
 }
Example #27
0
 internal static void LandParticles(On.Celeste.FallingBlock.orig_LandParticles orig, FallingBlock self)
 {
     if (self is FancyFallingBlock)
     {
         for (int x = 2; x <= self.Width; x += 4)
         {
             //Move bottom to top
             for (int y = (int)self.Height - 2; y >= 0; y -= 4)
             {
                 if (self.CollidePoint(new Vector2(self.X + x, self.Y + y)))
                 {
                     if (self.Scene.CollideCheck <Solid>(new Vector2(self.X + x, self.Y + y + 3)))
                     {
                         self.SceneAs <Level>().ParticlesFG.Emit(P_FallDustA, 1, new Vector2(self.X + x, self.Y + y), Vector2.One * 4f, -(float)Math.PI / 2f);
                         float direction = (!(x < self.Width / 2f)) ? 0f : ((float)Math.PI);
                         self.SceneAs <Level>().ParticlesFG.Emit(P_LandDust, 1, new Vector2(self.X + x, self.Y + y), Vector2.One * 4f, direction);
                     }
                     break;
                 }
             }
         }
     }
     else
     {
         orig(self);
     }
 }
Example #28
0
        private IEnumerator AttackSequence(bool hurt)
        {
            CreateMoveState();
            string animDir = Enum.GetName(typeof(ArrowDir), dir);

            ActivateTiles(dir);
            ActivateParticles();
            Input.Rumble(RumbleStrength.Strong, RumbleLength.Medium);
            StartShaking(0.4f);

            Audio.Play(CustomSFX.game_melvin_seen_player, Center, "hurt", Util.ToInt(hurt));
            eye.Play("target", true);
            yield return(.3f);

            currentMoveLoopSfx.Play(CustomSFX.game_melvin_move_loop);
            yield return(.3f);

            eye.Play("target" + animDir, true);

            StopPlayerRunIntoAnimation = false;
            float speed = 0f;

            while (true)
            {
                speed = Calc.Approach(speed, 240f, 500f * Engine.DeltaTime);

                bool flag = ((crushDir.X == 0f) ? MoveVCheck(speed * crushDir.Y * Engine.DeltaTime) : MoveHCheck(speed * crushDir.X * Engine.DeltaTime));
                if (Top >= (level.Bounds.Bottom + 32))
                {
                    RemoveSelf();
                    yield break;
                }
                if (flag)
                {
                    break;
                }
                if (Scene.OnInterval(0.02f))
                {
                    Vector2 position;
                    float   direction;
                    if (crushDir == Vector2.UnitX)
                    {
                        position  = new Vector2(Left + 1f, Calc.Random.Range(Top + 3f, Bottom - 3f));
                        direction = (float)Math.PI;
                    }
                    else if (crushDir == -Vector2.UnitX)
                    {
                        position  = new Vector2(Right - 1f, Calc.Random.Range(Top + 3f, Bottom - 3f));
                        direction = 0f;
                    }
                    else if (crushDir == Vector2.UnitY)
                    {
                        position  = new Vector2(Calc.Random.Range(Left + 3f, Right - 3f), Top + 1f);
                        direction = -(float)Math.PI / 2f;
                    }
                    else
                    {
                        position  = new Vector2(Calc.Random.Range(Left + 3f, Right - 3f), Bottom - 1f);
                        direction = (float)Math.PI / 2f;
                    }
                    level.Particles.Emit(SwitchGate.P_Behind, position, direction);
                }
                yield return(null);
            }

            FallingBlock fallingBlock = CollideFirst <FallingBlock>(Position + crushDir);

            if (fallingBlock != null)
            {
                fallingBlock.Triggered = true;
            }
            if (crushDir == -Vector2.UnitX)
            {
                Vector2 offset = new Vector2(0f, 2f);
                for (int y = 0; y < Height / 8f; y++)
                {
                    Vector2 pos = new Vector2(Left - 1f, Top + 4f + (y * 8));
                    if (!Scene.CollideCheck <Water>(pos) && Scene.CollideCheck <Solid>(pos))
                    {
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, pos + offset, 0f);
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, pos - offset, 0f);
                    }
                }
            }
            else if (crushDir == Vector2.UnitX)
            {
                Vector2 offset = new Vector2(0f, 2f);
                for (int y = 0; y < Height / 8f; y++)
                {
                    Vector2 pos = new Vector2(Right + 1f, Top + 4f + y * 8);
                    if (!Scene.CollideCheck <Water>(pos) && Scene.CollideCheck <Solid>(pos))
                    {
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, pos + offset, (float)Math.PI);
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, pos - offset, (float)Math.PI);
                    }
                }
            }
            else if (crushDir == -Vector2.UnitY)
            {
                Vector2 offset = new Vector2(2f, 0f);
                for (int x = 0; x < Width / 8f; x++)
                {
                    Vector2 pos = new Vector2(Left + 4f + x * 8, Top - 1f);
                    if (!Scene.CollideCheck <Water>(pos) && Scene.CollideCheck <Solid>(pos))
                    {
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, pos + offset, (float)Math.PI / 2f);
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, pos - offset, (float)Math.PI / 2f);
                    }
                }
            }
            else if (crushDir == Vector2.UnitY)
            {
                Vector2 offset = new Vector2(2f, 0f);
                for (int x = 0; x < Width / 8f; x++)
                {
                    Vector2 pos = new Vector2(Left + 4f + x * 8, Bottom + 1f);
                    if (!Scene.CollideCheck <Water>(pos) && Scene.CollideCheck <Solid>(pos))
                    {
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, pos + offset, -(float)Math.PI / 2f);
                        SceneAs <Level>().ParticlesFG.Emit(CrushBlock.P_Impact, pos - offset, -(float)Math.PI / 2f);
                    }
                }
            }

            Audio.Play(CustomSFX.game_melvin_impact, Center);
            level.DirectionalShake(crushDir);
            Input.Rumble(RumbleStrength.Medium, RumbleLength.Medium);
            StartShaking(0.4f);
            StopPlayerRunIntoAnimation = true;

            SoundSource sfx = currentMoveLoopSfx;

            currentMoveLoopSfx.Param("end", 1f);
            currentMoveLoopSfx = null;
            Alarm.Set(this, 0.5f, () => sfx.RemoveSelf());

            eye.Play("targetReverse" + animDir, true);
            crushDir = Vector2.Zero;
            returnLoopSfx.Play(SFX.game_06_crushblock_return_loop);
            yield return(.4f);

            speed = 0f;
            float waypointSfxDelay = 0f;

            while (returnStack.Count > 0)
            {
                yield return(null);

                StopPlayerRunIntoAnimation = false;
                MoveState moveState = returnStack[returnStack.Count - 1];
                speed             = Calc.Approach(speed, 60f, 160f * Engine.DeltaTime);
                waypointSfxDelay -= Engine.DeltaTime;
                if (moveState.Direction.X != 0f)
                {
                    MoveTowardsX(moveState.From.X, speed * Engine.DeltaTime);
                }
                if (moveState.Direction.Y != 0f)
                {
                    MoveTowardsY(moveState.From.Y, speed * Engine.DeltaTime);
                }
                if ((moveState.Direction.X != 0f && ExactPosition.X != moveState.From.X) || (moveState.Direction.Y != 0f && ExactPosition.Y != moveState.From.Y))
                {
                    continue;
                }

                speed = 0f;
                returnStack.RemoveAt(returnStack.Count - 1);
                StopPlayerRunIntoAnimation = true;
                if (returnStack.Count <= 0)
                {
                    if (waypointSfxDelay <= 0f)
                    {
                        returnLoopSfx.Stop();
                        Audio.Play(SFX.game_06_crushblock_rest, Center);
                    }
                }
                else if (waypointSfxDelay <= 0f)
                {
                    Audio.Play(SFX.game_06_crushblock_rest_waypoint, Center);
                }
                waypointSfxDelay = 0.1f;
                StartShaking(0.2f);
                yield return(0.2f);
            }

            triggered = false;
        }
Example #29
0
        public void Update(GameTime gameTime, KeyboardState lastKeyState, MouseState lastMouseState, bool chatting)
        {
            MouseState mouseState = Mouse.GetState();
            bool       playerTeam = MainPlayer.PlayerTeam.Name == "Red Team";

            if (online)
            {
                foreach (KeyValuePair <int, Player> entry in PlayerIndex.ToArray())
                {
                    if (!chatting)
                    {
                        entry.Value.Update(gameTime, lastKeyState, lastMouseState, DrawBlockOutline, entry.Value == MainPlayer);
                    }
                    else
                    {
                        entry.Value.Update(gameTime, lastKeyState, lastMouseState, DrawBlockOutline, false);
                    }
                }
            }
            foreach (KeyValuePair <int, Mob> entry in MobIndex.ToArray())
            {
                entry.Value.Update(gameTime, WorldMap);
            }
            foreach (KeyValuePair <int, ItemDrop> entry in DropIndex.ToArray())
            {
                entry.Value.Update(gameTime, WorldMap, MainPlayer.Items, new Vector2(MainPlayer.X + MainPlayer.BoundWidth, MainPlayer.Y + MainPlayer.BoundHeight), playerTeam);
            }
            foreach (KeyValuePair <int, FallingBlock> entry in FallingBlockIndex.ToArray())
            {
                FallingBlock fallingBlock = entry.Value;
                fallingBlock.Update(gameTime, WorldMap);
                if (fallingBlock.CanDestroy)
                {
                    Universal.TryDictRemove(FallingBlockIndex, entry.Key);
                }
            }
            if (ServerMode == GameMode.TeamDeathmatch || ServerMode == GameMode.CaptureTheFlag)
            {
                RedTent.Update(gameTime, WorldMap, MainPlayer.Items, MainPlayer.Position, playerTeam);
                BlueTent.Update(gameTime, WorldMap, MainPlayer.Items, MainPlayer.Position, playerTeam);
            }
            foreach (GameObject gameObject in objectList.ToArray())
            {
                gameObject.Update(gameTime);
                if (gameObject.Dead)
                {
                    objectList.Remove(gameObject);
                }
            }

            int  blockX       = (camera.CX + mouseState.X) / 16;
            int  blockY       = (camera.CY + mouseState.Y) / 16;
            Item selectedItem = MainPlayer.SelectedItem;

            if (MainPlayer.Motion != Vector2.Zero ||
                mouseState.LeftButton != lastMouseState.LeftButton ||
                mouseState.RightButton != lastMouseState.RightButton || blockX != lastBlockX || blockY != lastBlockY)
            {
                DrawBlockOutline = false;
                if (blockX >= 0 && blockX < WorldMap.Width &&
                    blockY >= 0 && blockY < WorldMap.Height &&
                    Vector2.Distance(new Vector2(MainPlayer.X + MainPlayer.BoundWidth, MainPlayer.Y + MainPlayer.BoundHeight / 2), new Vector2(camera.CX + mouseState.X, camera.CY + mouseState.Y)) <= Universal.TILE_SIZE * Universal.PLACE_DISTANCE)
                {
                    if (mouseState.RightButton == ButtonState.Pressed && WorldMap.Tiles[0, blockX, blockY].ID >= 0)
                    {
                        DrawBlockOutline = true;
                    }
                    else if (selectedItem.Type == ItemType.Block && mouseState.RightButton == ButtonState.Released && WorldMap.Tiles[0, blockX, blockY].ID == -1)
                    {
                        if (blockX >= 0 && blockX < WorldMap.Width)
                        {
                            if (blockY - 1 >= 0 && WorldMap.Tiles[0, blockX, blockY - 1].ID >= 0)
                            {
                                DrawBlockOutline = true;
                            }
                            if (blockY + 1 < WorldMap.Height && WorldMap.Tiles[0, blockX, blockY + 1].ID >= 0)
                            {
                                DrawBlockOutline = true;
                            }
                        }
                        if (blockY >= 0 && blockY < WorldMap.Height)
                        {
                            if (blockX - 1 >= 0 && WorldMap.Tiles[0, blockX - 1, blockY].ID >= 0)
                            {
                                DrawBlockOutline = true;
                            }
                            if (blockX + 1 < WorldMap.Width && WorldMap.Tiles[0, blockX + 1, blockY].ID >= 0)
                            {
                                DrawBlockOutline = true;
                            }
                        }
                        if (blockX == 0 || blockX == WorldMap.Width - 1 ||
                            blockY == 0 || blockY == WorldMap.Height - 1)
                        {
                            DrawBlockOutline = true;
                        }
                    }
                }
            }

            if (network != null &&
                (mouseState.RightButton != lastMouseState.RightButton || blockX != lastBlockX || blockY != lastBlockY))
            {
                network.SendHitBlock(DrawBlockOutline, mouseState.X, mouseState.Y);
            }

            lastBlockX = blockX;
            lastBlockY = blockY;

            if (!MainPlayer.RespawnInterval.IsRunning)
            {
                camera.Position = MainPlayer.Position;
            }
            if (camera.X < Universal.SCREEN_WIDTH / 2)
            {
                camera.X = Universal.SCREEN_WIDTH / 2;
            }
            else if (camera.X > WorldMap.Width * Universal.TILE_SIZE - Universal.SCREEN_WIDTH / 2)
            {
                camera.X = WorldMap.Width * Universal.TILE_SIZE - Universal.SCREEN_WIDTH / 2;
            }
            if (camera.Y < Universal.SCREEN_HEIGHT / 2)
            {
                camera.Y = Universal.SCREEN_HEIGHT / 2;
            }
            else if (camera.Y > WorldMap.Height * Universal.TILE_SIZE - Universal.SCREEN_HEIGHT / 2)
            {
                camera.Y = WorldMap.Height * Universal.TILE_SIZE - Universal.SCREEN_HEIGHT / 2;
            }

            WorldMap.CheckRender();
        }
Example #30
0
 public bool AddFallingBlock(int id, FallingBlock fallingBlock)
 {
     return(FallingBlockIndex.TryAdd(id, fallingBlock));
 }
Example #31
0
        public void Update(float msElapsed)
        {
            if (RestartInterval.Left > 1 || !RestartInterval.IsRunning)
            {
                foreach (KeyValuePair <int, Player> entry in PlayerIndex.ToArray())
                {
                    Player player = entry.Value;
                    player.Update(msElapsed, WorldMap, RedTent.Position, BlueTent.Position);
                    if (player.Y >= WorldMap.Height * Universal.TILE_SIZE - Universal.TILE_SIZE * 3)
                    {
                        network.SendKilledPlayer(-1, entry.Key, player);
                        player.DeathAction(false);
                        network.SendServerMove(entry.Key, player);
                        player.RespondMove = false;
                        network.CheckWinCondition();
                    }
                }
                foreach (KeyValuePair <int, Mob> entry in MobIndex.ToArray())
                {
                    if (entry.Value.Dead)
                    {
                        foreach (ItemDrop drop in entry.Value.Drops)
                        {
                            int id = 0;
                            foreach (KeyValuePair <int, ItemDrop> dropEntry in DropIndex.ToArray())
                            {
                                if (dropEntry.Key == id)
                                {
                                    id++;
                                }
                            }
                            DropIndex.TryAdd(id, drop);
                        }
                        network.SendRemoveMob(entry.Key, entry.Value.Drops);
                        Universal.TryDictRemove(MobIndex, entry.Key);
                    }
                    else
                    {
                        entry.Value.Update(msElapsed, WorldMap);
                    }
                }
                foreach (KeyValuePair <int, ItemDrop> entry in DropIndex.ToArray())
                {
                    entry.Value.Update(msElapsed, WorldMap);
                }
                foreach (KeyValuePair <int, FallingBlock> entry in FallingBlockIndex.ToArray())
                {
                    FallingBlock fallingBlock = entry.Value;
                    fallingBlock.Update(msElapsed, WorldMap);
                    if (Math.Abs(fallingBlock.DY) > 70)
                    {
                        foreach (KeyValuePair <int, Mob> mobEntry in MobIndex.ToArray())
                        {
                            Mob mob = mobEntry.Value;
                            if (fallingBlock.CollideBox.Intersects(mob.CollideBox))
                            {
                                mob.Damage(2);
                                network.SendHitMob(mobEntry.Key, 2);
                            }
                        }
                        foreach (KeyValuePair <int, Player> playerEntry in PlayerIndex.ToArray())
                        {
                            Player targetPlayer = playerEntry.Value;
                            if (fallingBlock.CollideBox.Intersects(targetPlayer.CollideBox))
                            {
                                targetPlayer.Damage(2);
                                network.SendHitPlayer(playerEntry.Key, 2, targetPlayer.DX, targetPlayer.DY);
                                if (targetPlayer.HP <= 0)
                                {
                                    Player killer;
                                    if (fallingBlock.PlayerID != playerEntry.Key &&
                                        PlayerIndex.TryGetValue(fallingBlock.PlayerID, out killer) &&
                                        (targetPlayer.PlayerTeam.Name == "No Team" || killer.PlayerTeam.Name != targetPlayer.PlayerTeam.Name))
                                    {
                                        killer.Kills++;
                                        network.SendKilledPlayer(fallingBlock.PlayerID, playerEntry.Key, targetPlayer);
                                    }
                                    else
                                    {
                                        network.SendKilledPlayer(-1, playerEntry.Key, targetPlayer);
                                    }
                                    targetPlayer.DeathAction(false);
                                    network.SendServerMove(playerEntry.Key, targetPlayer);
                                    targetPlayer.RespondMove = false;
                                    network.CheckWinCondition();
                                }
                            }
                        }
                    }
                    if (fallingBlock.CanDestroy)
                    {
                        network.SendRemoveFallingBlock(entry.Key);
                        Universal.TryDictRemove(FallingBlockIndex, entry.Key);
                    }
                }
                if (ServerMode == GameMode.TeamDeathmatch || ServerMode == GameMode.CaptureTheFlag)
                {
                    RedTent.Update(msElapsed, WorldMap);
                    BlueTent.Update(msElapsed, WorldMap);
                }
            }

            TimeRemaining.Update(msElapsed);
            RestartInterval.Update(msElapsed);
        }