コード例 #1
0
 public CentipedeSegment[] hit(int segment)
 {//Splitting method for a hit. Not tested
     CentipedeSegment[] ret     = new CentipedeSegment[body.Length - (segment + 1)];
     CentipedeSegment[] newBody = new CentipedeSegment[segment];
     for (int i = 0; i < body.Length; i++)
     {
         if (i < newBody.Length)
         {
             newBody[i] = body[i];
         }
         if (i > newBody.Length)
         {
             ret[i - (newBody.Length + 1)] = body[i];
         }
     }
     body = newBody;
     return(ret);
 }
コード例 #2
0
ファイル: CentipedeMaster.cs プロジェクト: LanceJZ/Centipede
        public bool CheckHitSelf(CentipedeSegment other)
        {
            //for (int i = 0; i < 12; i++)
            //{
            //    if (TheCentipede[i].Enabled)
            //    {
            //        if (other != TheCentipede[i])
            //        {
            //            if (TheCentipede[i].Sphere.Intersects(other.Sphere))
            //            {
            //                return true;
            //            }
            //        }
            //    }
            //}

            return(false);
        }
コード例 #3
0
        public bool centipedeCollision(Centipede centipede, GameTime gameTime)
        {//This works I think but is kinda weird and finicky on relative positioning
            CentipedeSegment head = centipede.body[0];

            foreach (Mushroom m in level.mushrooms)
            {
                if (!centipede.recentBounce && head.position.Intersects(m.loc) && m.visible)
                {
                    if (head.velocity > 0)
                    {
                        centipede.addTurn(new Vector2(m.loc.X - 20, m.loc.Y), gameTime);
                        centipede.body[0].position.X -= head.velocity;
                    }
                    else if (head.velocity < 0)
                    {
                        centipede.addTurn(new Vector2(m.loc.X + 20, m.loc.Y), gameTime);
                        centipede.body[0].position.X -= head.velocity;
                    }
                    centipede.body[0].turn();
                    return(false);
                }
            }
            return(true);
        }
コード例 #4
0
        public void Update(GameTime gameTime)
        {//controlls most actions
            for (int segment = 0; segment < body.Length; segment++)
            {
                if (body[segment] == null && segment != 0)
                {//Creating the centipede at the begging of the game
                    if (body[segment - 1].pastSpawn())
                    {
                        body[segment]       = new CentipedeSegment(new Rectangle(290, 40, 20, 20), velocity);
                        body[segment].frame = body[segment - 1].frame + 7;
                    }
                    break;
                }
                else
                {//Standard movement
                    body[segment].update();
                    if (body[segment].position.X <0 || body[segment].position.X> rightBound - 20)
                    {//turn based on bounding/ game walls
                        if (body[segment].position.Y + 20 > bottomBound || body[segment].position.Y < topBound)
                        {
                            body[segment].turnVeritcal();
                        }
                        else
                        {
                            body[segment].turn();
                        }
                        if (segment == 0)
                        {
                            recentBounce = true;
                        }
                    }
                }
            }
            foreach (Vector2 turn in turnPoints)
            {//turning as a result of a mushroom - self clears
                for (int segment = 0; segment < body.Length; segment++)
                {
                    if (body[segment] != null)
                    {
                        if (body[segment].position.X == turn.X && body[segment].position.Y == turn.Y)
                        {
                            body[segment].turn();
                            body[segment].position.X -= body[segment].velocity;
                        }
                    }
                }
            }
            if (removeTimers.Last != null && removeTimers.ElementAt(removeTimers.Count - 1) == gameTime.ElapsedGameTime.Ticks - 100)
            {
                removeTimers.RemoveLast();
                turnPoints.RemoveLast();
            }

            if (recentBounce)
            {//stops a bug from happening when the head of the centipede shifts down a wall into a mushroom
                bounceTimer++;
                if (bounceTimer == 8)
                {
                    recentBounce = false;
                    bounceTimer  = 0;
                }
            }
        }
コード例 #5
0
 public void buildSnake()
 {
     body[0] = new CentipedeSegment(new Rectangle(290, 40, 20, 20), velocity);
 }