Esempio n. 1
0
        public GameOverScreen(Game1 game, SpriteBatch spriteBatch, AnimatedSprite Sp)
        {
            this.game = game;
            this.spriteBatch = spriteBatch;
            this.Sprite = Sp;

            spriteFont = game.Content.Load<SpriteFont>("menufont");
            image = game.Content.Load<Texture2D>("blood");
            string[] menuItems = { "Restart Game", "End Game" };
            menuComponent = new MenuComponent(game, spriteBatch, spriteFont, menuItems);
            game.Components.Add(menuComponent);
            imageRec = new Rectangle(0, 0, game.Window.ClientBounds.Width, game.Window.ClientBounds.Height);

            // Start Bat placement into list
            rand = new Random();

            for (int i = 0; i < 60; i++)
            {
                Bat b = new Bat(game, spriteBatch, Sprite);
                b.Position = new Vector2(400 + (float)(-50 + rand.NextDouble() * 100),
                                         200 + (float)(-50 + rand.NextDouble() * 100));
                b.speed = 20f + (float)rand.NextDouble() * 40.0f;
                ListOBats.Add(b);
                game.Components.Add(b);
            }
            for (int j = 0; j < 60; j++)
            {
                ListOBats[j].batList = ListOBats;
            }
            // end bat placement into list
        }
Esempio n. 2
0
        public bool IsInBoidNeighborhood(Bat other, float minDistance, float maxDistance, float cosMaxAngle)
        {
            if (other == this)
            {
                return false;
            }
            else
            {
                Vector2 offset = other.Position - this.Position;
                float distanceSquared = offset.LengthSquared();

                // definitely in neighborhood if inside minDistance circle
                if (distanceSquared < (minDistance * minDistance))
                {
                    return true;
                }
                else
                {
                    // definitely not in neighborhood if outside maxDistance circle
                    if (distanceSquared > (maxDistance * maxDistance))
                    {
                        return false;
                    }
                    else
                    {
                        // otherwise, test angular offset from forward axis
                        Vector2 unitOffset = offset / (float)Math.Sqrt(distanceSquared);
                        float forwardness = Vector2.Dot((cohereTraj + sepTraj + alignTraj), unitOffset);
                        return forwardness > cosMaxAngle;
                    }
                }
            }
        }