コード例 #1
0
ファイル: Item_Bubble.cs プロジェクト: Foda/MarioClone
        public void Pop()
        {
            if (respawnPlayer != null)
            {
                respawnPlayer.isInBubble = false;
                respawnPlayer.MakeInvinvible();
                respawnPlayer.vVelocity = Vector2.Zero;
                respawnPlayer.vPosition = Position;
                respawnPlayer = null;

                isVisible = false;
            }
        }
コード例 #2
0
ファイル: Item_Manager.cs プロジェクト: Foda/MarioClone
 public void DoCollisionPlayer(Player ply)
 {
     //Item collisions
     foreach (Item_Base item in listItem.ToArray())
     {
         if (item is Item_Mushroom)
         {
             Item_Mushroom mushroom = (Item_Mushroom)item;
             if (ply.GetRect().Intersects(mushroom.GetRect()) == true &&
                 mushroom.isWithinBlock == false)
             {
                 item.parentBlock.RemoveItem(item);
                 listItem.Remove(item);
                 ply.Grow();
             }
         }
     }
 }
コード例 #3
0
ファイル: Level.cs プロジェクト: Foda/MarioClone
        public void WallTest(ref Player ply)
        {
            if (ply.vVelocity.X == 0)
                return;

            int y1 = (int)((ply.vPosition.Y) / 16);
            int y2 = (int)((ply.vPosition.Y) / 16);

            //If we're big, also do a check in the middle
            int y3 = (int)((ply.vPosition.Y + ply.Height/2) / 16);

            int x1 = (int)(ply.vPosition.X)/ 16;
            int x2 = (int)(ply.vPosition.X + 16) / 16;

            int x3 = (int)(ply.vPosition.X + 8) / 16;

            if (tileData[x3, y1].isSlope == false)
            {
                if (ply.vVelocity.X > 0)
                {
                    if ((tileData[x2, y1].isSolid == true || tileData[x2, y2].isSolid == true ||
                         tileData[x2, y3].isSolid == true) &&
                         tileData[x2, y1].isSlope == false)
                    {
                        ply.vPosition.X = (x2 * 16) - 16;
                        ply.vVelocity.X = 0f;
                    }
                }
                else if (ply.vVelocity.X < 0)
                {
                    if ((tileData[x1, y1].isSolid == true || tileData[x1, y2].isSolid == true ||
                         tileData[x1, y3].isSolid == true) &&
                         tileData[x1, y1].isSlope == false)
                    {
                        ply.vPosition.X = (x1 * 16) + 16;
                        ply.vVelocity.X = 0f;
                    }
                }
            }
        }
コード例 #4
0
ファイル: Level.cs プロジェクト: Foda/MarioClone
        public void TestGround(ref Player ply)
        {
            for (int i = 0; i < 60; i++)
            {
                for (int n = 0; n < 50; n++)
                {
                    tileData[i, n].isLit = false;
                }
            }

            int y1 = (int)((ply.vPosition.Y + ply.Height) / 16);
            int y2 = (int)((ply.vPosition.Y + ply.Height) / 16);

            int x1 = (int)(ply.vPosition.X + 4) / 16;
            int x2 = (int)(ply.vPosition.X + 14) / 16;

            //For slopes
            int x3 = (int)(ply.vPosition.X + 8) / 16;

            if (tileData[x1, y1].isSolid == true && tileData[x1, y1].isSlope == false)
            {
                ply.airState = ConstHelper.AirState.GROUND;
                ply.isJumping = false;
            }
            else if (tileData[x2, y1].isSolid == true && tileData[x2, y1].isSlope == false)
            {
                ply.airState = ConstHelper.AirState.GROUND;
                ply.isJumping = false;
            }
            else
                ply.airState = ConstHelper.AirState.AIR;

            //DEBUG
            //tileData[x3, y2].isLit = true;

            if ((tileData[x3, y2].isSlope || tileData[x3, y2+1].isSlope) &&
                ply.isJumping == false)
            {
                int testY = 0;
                if (tileData[x3, y2].isSlope)
                    testY = y2;
                else
                    testY = y1;

                int testX = (((x3 * 16) + 16) - ((int)ply.vPosition.X + 8)) - 1;

                for (int i = 0; i < 16; i++)
                {
                    if (tileData[x3, testY].slopePts != null)
                    {
                        if (tileData[x3, testY].slopePts[testX, i] == 1)
                        {
                            ply.vVelocity.Y = 0;
                            ply.vPosition.Y = (testY * 16) - i;

                            ply.airState = ConstHelper.AirState.GROUND;
                            ply.isJumping = false;
                            break;
                        }
                    }
                }
            }
            else if (ply.airState == ConstHelper.AirState.GROUND)
            {
                if(ply.vVelocity.Y > 0)
                    ply.vVelocity.Y = 0;
                ply.vPosition.Y = (y1 * 16) - ply.Height;
            }
            else
                ply.airState = ConstHelper.AirState.AIR;

            //Test NPC collisions
            npcMan.DoCollisionPlayer(ply);

            //Test item collisions
            itemMan.DoCollisionPlayer(ply);
        }
コード例 #5
0
ファイル: Level.cs プロジェクト: Foda/MarioClone
        public void TestCeiling(ref Player ply)
        {
            if (ply.vVelocity.Y < 0)
            {
                int y1 = (int)((ply.vPosition.Y) / 16);

                int x1 = (int)(ply.vPosition.X) / 16;
                int x2 = (int)(ply.vPosition.X + 14) / 16;

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

            if (ply.GetRect().Intersects(blockTest[0].GetRect()) == true &&
                ply.vVelocity.Y < 0 &&
                ply.vPosition.Y > blockTest[0].GetWorldPosition().Y + 16)
            {
                blockTest[0].HandleCollision(ConstHelper.CollisionDir.DOWN, "player");
            }
        }
コード例 #6
0
ファイル: NPC_Manager.cs プロジェクト: Foda/MarioClone
        public void DoCollisionPlayer(Player ply)
        {
            foreach (NPC_Base npc in listNPC.ToArray())
            {
                if(npc.GetRect().Intersects(ply.GetRect()) &&
                    (ply.airState == ConstHelper.AirState.GROUND ||
                    ply.vVelocity.Y < 0) &&
                    npc.isDeadly == true)
                {
                    if (ply.isBig)
                        ply.Shrink();
                    else
                    {
                        //Isszzz Ded D:
                        ply.isInBubble = true;
                        currentLevel.bubble.SetPlayer(ply);
                    }
                }
                else
                {
                    if (npc is NPC_Goomba)
                    {
                        NPC_Goomba goomba = (NPC_Goomba)npc;
                        if ((ply.GetRect().Intersects(goomba.GetRect()) == true) &&
                            ply.vVelocity.Y > 0.05f &&
                            goomba.isSquished == false &&
                            (ply.vPosition.Y + ply.Height/2 <= goomba.Position.Y))
                        {
                            goomba.HandleCollision(ConstHelper.CollisionDir.UP, "player");
                            ply.DoJump();

                            //Do PFX
                            //Play SFX
                            //Add score
                            //Add multiplyer
                        }

                        if (goomba.Remove)
                            listNPC.Remove(goomba);
                    }

                    if (npc is NPC_LilTurtle)
                    {
                        NPC_LilTurtle lt = (NPC_LilTurtle)npc;
                        if ((ply.GetRect().Intersects(lt.GetRect()) == true) &&
                            ply.vVelocity.Y > 0.05f &&
                            lt.isSquished == false &&
                            (ply.vPosition.Y + ply.Height / 2 <= lt.Position.Y))
                        {
                            lt.HandleCollision(ConstHelper.CollisionDir.UP, "player");
                            ply.DoJump();
                        }

                        if (lt.Remove)
                            listNPC.Remove(lt);
                    }

                    if (npc is NPC_Turtle)
                    {
                        NPC_Turtle turtle = (NPC_Turtle)npc;

                        if (turtle.Collide)
                        {
                            foreach (NPC_Base npcHit in listNPC.ToArray())
                            {
                                if (turtle.isShell && turtle.vVelocity.X != 0)
                                {
                                    if (npcHit.GetRect().Intersects(turtle.GetRect()) == true)
                                        npcHit.HandleCollision(ConstHelper.CollisionDir.DOWN, "turtle");
                                }
                                else if (turtle.isShell)
                                {
                                    //Handle the lil'turtle jumping back into his shell
                                    if (npcHit.GetRect().Intersects(turtle.GetRect()) == true &&
                                        npcHit is NPC_LilTurtle &&
                                        npcHit.isDeadly)
                                    {
                                        npcHit.HandleCollision(ConstHelper.CollisionDir.DOWN, "turtle_static");
                                        turtle.isShell = false;
                                        turtle.isDeadly = true;
                                        turtle.vVelocity = Vector2.Zero;
                                        turtle.Height = 26;
                                    }
                                }
                            }

                            if ((ply.GetRect().Intersects(turtle.GetRect()) == true) &&
                                ply.vVelocity.Y > 0 && turtle.isShell == false &&
                                (ply.vPosition.Y + ply.Height/2 <= turtle.Position.Y))
                            {
                                turtle.HandleCollision(ConstHelper.CollisionDir.UP, "player");
                                ply.DoJump();
                            }
                            else if ((ply.GetRect().Intersects(turtle.GetRect()) == true) &&
                                turtle.isShell == true)
                            {
                                //Do this so that the shell stops if jumped on, otherwise kick that shit
                                if (ply.airState == ConstHelper.AirState.AIR &&
                                    (ply.vPosition.Y + 8 <= turtle.Position.Y))
                                {
                                    turtle.HandleCollision(ConstHelper.CollisionDir.UP, "player");
                                    ply.DoJump(true);
                                }
                                else
                                {
                                    if (ply.canGrab == true && (turtle.vVelocity.X < 2 && turtle.vVelocity.X > -2))
                                        ply.GrabShell(turtle);
                                    else if (ply.airState == ConstHelper.AirState.GROUND)
                                        turtle.KickShell(ply.vVelocity.X);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: Item_Bubble.cs プロジェクト: Foda/MarioClone
 public void SetPlayer(Player ply)
 {
     respawnPlayer = ply;
     isVisible = true;
 }