Beispiel #1
0
        public bool GonnaCollide(Player player, List <Player> gamePlayersList)
        {
            Vector3 furtherPos = GetFurtherPosition(player);

            Rectangle hitBox = Rectangle.GetHitBox(furtherPos, player.direction);

            if (CollisionManager.CollideWithMap(furtherPos, player.direction, mapObstacles))
            {
                return(true);
            }

            foreach (Player collisionTestPlayer in gamePlayersList)
            {
                if (!collisionTestPlayer.isAlive)
                {
                    continue;
                }

                if (player != collisionTestPlayer && CollisionManager.CollideWithTrail(furtherPos, player.direction, collisionTestPlayer.currentTrail))
                {
                    return(true);
                }

                if (player != collisionTestPlayer && hitBox.CollideWithRectancle(collisionTestPlayer.hitBox))
                {
                    return(true);
                }

                foreach (TrailSector trailSector in collisionTestPlayer.trailHistory)
                {
                    if (collisionTestPlayer != player || !trailSector.isFirstOnHistory)
                    {
                        if (CollisionManager.CollideWithTrail(furtherPos, player.direction, trailSector))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Prepares the next frame for rendering.
        /// </summary>
        /// <remarks>
        /// Place your control logic here. This is the place to respond to user input,
        /// update object positions etc.
        /// </remarks>
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            if (Keyboard[OpenTK.Input.Key.Escape])
            {
                this.Exit();
                return;
            }

            foreach (Player player in gamePlayers)
            {
                if (!player.isAlive)
                {
                    continue;
                }

                if (player.isHumanPlayer)
                {
                    player.updatePlayerPos(Keyboard, e.Time, cameraMode);
                }
                else
                {
                    ai.Think(player, gamePlayers);
                    player.updatePlayerPos(null, e.Time, cameraMode);
                }


                if (CollisionManager.CollideWithMap(player, myMap.mapObstacles))
                {
                    player.Die();
                }

                foreach (Player collisionTestPlayer in gamePlayers)
                {
                    if (!collisionTestPlayer.isAlive)
                    {
                        continue;
                    }

                    if (player != collisionTestPlayer && CollisionManager.CollideWithTrail(player, collisionTestPlayer.currentTrail))
                    {
                        player.Die();
                    }

                    if (player != collisionTestPlayer && player.hitBox.CollideWithRectancle(collisionTestPlayer.hitBox))
                    {
                        player.Die();
                        collisionTestPlayer.Die();
                    }

                    foreach (TrailSector trailSector in collisionTestPlayer.trailHistory)
                    {
                        if (collisionTestPlayer == player && trailSector.isFirstOnHistory)
                        {
                            continue;
                        }

                        if (CollisionManager.CollideWithTrail(player, trailSector))
                        {
                            player.Die();
                        }
                    }
                }
            }
        }