Ejemplo n.º 1
0
 public AgentSprite(CatAndMouseGame game, Texture2D texture, Vector2 position, UserSprite target, GridCell[,] gridCell, Graph graph)
     : base(game, texture, position)
 {
     this.target = target;
     this.gridCell = gridCell;
     this.graph = graph;
 }
Ejemplo n.º 2
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Texture2D kanyeTexture = Content.Load<Texture2D>("kanye");
            Texture2D taylorTexture = Content.Load<Texture2D>("taylor");

            // Load the font for writing text
            // Arial should be installed on all Windows computers by default
            textFont = Content.Load<SpriteFont>("Arial");

            // Mouse initialization
            int taylorX = r.Next(0, graphics.PreferredBackBufferWidth - taylorTexture.Width);
            int taylorY = r.Next(0, graphics.PreferredBackBufferHeight - taylorTexture.Height);
            Vector2 taylorPosition = new Vector2(taylorX, taylorY);
            taylorSprite = new UserSprite(this, taylorTexture, taylorPosition);

            // Cat initialization
            int kanyeX;
            int kanyeY;
            Vector2 kanyePosition;
            // We want to ensure that there's a minimum distance between the kanye and the taylor
            // We don't want the case where the player starts the game and is immediately caught
            do
            {
                kanyeX = r.Next(0, graphics.PreferredBackBufferWidth - kanyeTexture.Width);
                kanyeY = r.Next(0, graphics.PreferredBackBufferHeight - kanyeTexture.Height);
                kanyePosition = new Vector2(kanyeX, kanyeY);
            } while ((kanyePosition - taylorPosition).Length() < SPAWN_MINIMUM_DISTANCE);
            kanyeSprite = new AgentSprite(this, kanyeTexture, kanyePosition, taylorSprite, grid, graph);

            foreach (GridCell gc in grid)
            {
                this.Components.Add(gc);
            }

            // Add these sprites to the game ComponentCollection
            // This ensures that the Draw and Update methods are called consistently
            this.Components.Add(taylorSprite);
            this.Components.Add(kanyeSprite);
        }