コード例 #1
0
ファイル: NPC_Manager.cs プロジェクト: Foda/MarioClone
        public void WallTestNPC(NPC_Base spr, Tile[,] tileData)
        {
            int y1 = (int)((spr.Position.Y + (spr.Source.Height - 16)) / 16);
            //int y2 = (int)(((spr.Position.Y + 16)) / 16);

            int x1 = (int)(spr.Position.X - 2) / 16;
            int x2 = (int)(spr.Position.X + 16) / 16;

            if (spr.isMovingLeft == false)
            {
                if (tileData[x2, y1].isSolid == true)
                {
                    spr.Position.X = (x2 * 16) - 16;
                    spr.HandleCollision(ConstHelper.CollisionDir.RIGHT, "wall");
                }
            }
            else
            {
                if (tileData[x1, y1].isSolid == true)
                {
                    spr.Position.X = (x1 * 16) + 16;
                    spr.HandleCollision(ConstHelper.CollisionDir.LEFT, "wall");
                }
            }
        }
コード例 #2
0
ファイル: NPC_Manager.cs プロジェクト: Foda/MarioClone
        public void TestCeilingNPC(NPC_Base spr, Tile[,] tileData, List<Block> blocks)
        {
            if (spr.vVelocity.Y < 0)
            {
                int y1 = (int)((spr.Position.Y) / 16);

                int x1 = (int)(spr.Position.X + 4) / 16;
                int x2 = (int)(spr.Position.X + 14) / 16;

                if (tileData[x1, y1].isSolid == true)
                {
                    spr.vVelocity.Y = 0;
                    spr.Position.Y = (y1 * 16) + 16;
                }
                else if (tileData[x2, y1].isSolid == true)
                {
                    spr.vVelocity.Y = 0;
                    spr.Position.Y = (y1 * 16) + 16;
                }
            }

            foreach (NPC_Base npc in listNPC.ToArray())
            {
                if (npc is NPC_Turtle)
                {
                    NPC_Turtle turtle = (NPC_Turtle)npc;
                    foreach (Block blockTest in blocks)
                    {
                        if (turtle.GetRect().Intersects(blockTest.GetRect()) &&
                            turtle.isShell && turtle.isHeld == false)
                        {
                            blockTest.HandleCollision(ConstHelper.CollisionDir.DOWN, "shell");
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: NPC_Manager.cs プロジェクト: Foda/MarioClone
        public void TestGroundNPC(NPC_Base spr, Tile[,] tileData)
        {
            int y1 = (int)((spr.Position.Y + spr.Height) / 16);

            int x1 = (int)(spr.Position.X + 4) / 16;
            int x2 = (int)(spr.Position.X + 14) / 16;

            if (tileData[x1, y1].isSolid == true)
            {
                spr.airState = ConstHelper.AirState.GROUND;
            }
            else if (tileData[x2, y1].isSolid == true)
            {
                spr.airState = ConstHelper.AirState.GROUND;
            }
            else
            {
                if (spr is NPC_Turtle)
                {
                    NPC_Turtle turtle = (NPC_Turtle)spr;
                    if (turtle.isRed == true && turtle.isShell == false)
                    {
                        if (turtle.airState == ConstHelper.AirState.GROUND)
                        {
                            turtle.isMovingLeft = !turtle.isMovingLeft;
                            turtle.FlipHorz = !turtle.FlipHorz;
                        }
                    }
                    else
                        spr.airState = ConstHelper.AirState.AIR;
                }
                else
                    spr.airState = ConstHelper.AirState.AIR;
            }

            if (spr.airState == ConstHelper.AirState.GROUND)
            {
                spr.Position.Y = (y1 * 16) - spr.Source.Height;
                spr.vVelocity.Y = 0;
            }
            else
                spr.airState = ConstHelper.AirState.AIR;
        }
コード例 #4
0
ファイル: NPC_Manager.cs プロジェクト: Foda/MarioClone
        public void TestGroundNPC(NPC_Base spr, Tile[,] tileData)
        {
            int y1 = (int)((spr.Position.Y + spr.Height) / 16);

            int x1 = (int)(spr.Position.X + 4) / 16;
            int x2 = (int)(spr.Position.X + 14) / 16;

            if (tileData[x1, y1].isSolid == true)
            {
                spr.airState = Phys_Const.AirState.GROUND;
            }
            else if (tileData[x2, y1].isSolid == true)
            {
                spr.airState = Phys_Const.AirState.GROUND;
            }
            else
                spr.airState = Phys_Const.AirState.AIR;

            if (spr.airState == Phys_Const.AirState.GROUND)
            {
                spr.Position.Y = (y1 * 16) - spr.Source.Height;
                spr.vVelocity.Y = 0;
            }
            else
                spr.airState = Phys_Const.AirState.AIR;
        }