コード例 #1
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();
             }
         }
     }
 }
コード例 #2
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");
            }
        }
コード例 #3
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);
                                }
                            }
                        }
                    }
                }
            }
        }