Example #1
0
        public void loadContent(SpriteBatch spriteBatch)
        {
            this.spriteBatch = spriteBatch;

            texture2d = XNAGame.Content.Load <Texture2D>("ashshowpic");

            wallTexture = XNAGame.Content.Load <Texture2D>("historic-front-street");

            enemyTexture = new Texture2D(XNAGame.GraphicsDevice, 1, 1);
            enemyTexture.SetData(new Microsoft.Xna.Framework.Color[] { Microsoft.Xna.Framework.Color.White });
            player = new Player(0, 400, 60, 48, new Microsoft.Xna.Framework.Rectangle(0, 0, 60, 86), Microsoft.Xna.Framework.Color.White, XNAGame, 0);

            Enemy enemy2 = new Enemy(700, 650, 60, 48, new Microsoft.Xna.Framework.Rectangle(0, 0, 60, 86), Microsoft.Xna.Framework.Color.Green, XNAGame, 1);

            enemy           = new Enemy(300, 400, 60, 48, new Microsoft.Xna.Framework.Rectangle(0, 0, 60, 86), Microsoft.Xna.Framework.Color.Red, XNAGame, 0);
            reserveredEnemy = new Enemy(1200, 390, 60, 48, new Microsoft.Xna.Framework.Rectangle(0, 0, 60, 86), Microsoft.Xna.Framework.Color.Cyan, XNAGame, 0);
            Item       item    = new Item(80, 600, 40, 40, Microsoft.Xna.Framework.Color.White, XNAGame);
            WallBounds bounds  = new WallBounds(0, 759, 3000, 60, Microsoft.Xna.Framework.Color.White, XNAGame);
            WallBounds bounds2 = new WallBounds(-60, 0, 60, 808, Microsoft.Xna.Framework.Color.White, XNAGame);
            Wall       wall    = new Wall(0, 0, 3000, 380, new Microsoft.Xna.Framework.Rectangle(0, 180, 890, 52), Microsoft.Xna.Framework.Color.White, XNAGame);
            Floor      floor1  = new Floor(0, 350, 3000, 500, Microsoft.Xna.Framework.Color.Gray, XNAGame);

            objects.Add(floor1);
            objects.Add(bounds2);
            objects.Add(bounds);
            objects.Add(wall);
            objects.Add(item);
            objects.Add(reserveredEnemy);
            objects.Add(enemy2);
            objects.Add(enemy);

            objects.Add(player);

            wall.setTexture(wallTexture);


            foreach (GameObject go in objects)
            {
                go.load(spriteBatch);
            }
        }
Example #2
0
    /// <summary>
    /// Adds the given wall boundaries to the collection of walls to create.
    /// </summary>
    /// <exception cref="InvalidOperationException">Thrown if this object is no longer taking walls to create.</exception>
    public void AddWall(RecBounds b)
    {
        if (currentWallsState != InitializeWallsState.TakingWalls)
        {
            throw new System.InvalidOperationException("This object is no longer taking walls!");
        }

        WallBounds.Add(b);

        //If the wall is close enough to the edge and the level wraps around horizontally, duplicate it.
        if (WrapX)
        {
            float left  = b.center.x - b.extents.x,
                  right = b.center.x + b.extents.x;

            //If the wall is near the left edge, put a wall on the right.
            if (Mathf.Abs(left - (levelBounds.center.x - levelBounds.extents.x)) <= 1.0f)
            {
                MirroredWallBounds.Add(new RecBounds(b.center + new Vector2(WorldConstants.Size.x, 0.0f), b.size));
                //If the level also wraps vertically, put the wall above and below.
                if (WrapY)
                {
                    MirroredWallBounds.Add(new RecBounds(b.center + new Vector2(WorldConstants.Size.x, -WorldConstants.Size.y), b.size));
                    MirroredWallBounds.Add(new RecBounds(b.center + new Vector2(WorldConstants.Size.x, WorldConstants.Size.y), b.size));
                }
            }
            //If the wall is near the right edge, put a wall on the left.
            if (Mathf.Abs(right - (levelBounds.center.x + levelBounds.extents.x)) <= 1.0f)
            {
                MirroredWallBounds.Add(new RecBounds(b.center + new Vector2(-WorldConstants.Size.x, 0.0f), b.size));
                //If the level also wraps vertically, put the wall above and below.
                if (WrapY)
                {
                    MirroredWallBounds.Add(new RecBounds(b.center + new Vector2(-WorldConstants.Size.x, -WorldConstants.Size.y), b.size));
                    MirroredWallBounds.Add(new RecBounds(b.center + new Vector2(-WorldConstants.Size.x, WorldConstants.Size.y), b.size));
                }
            }
        }
        //Do the same for vertical wrapping.
        if (WrapY)
        {
            float bottom = b.center.y - b.extents.y,
                  top    = b.center.y + b.extents.y;
            //If the wall is near the bottom edge, put a wall on the top.
            if (Mathf.Abs(bottom - (levelBounds.center.y - levelBounds.extents.y)) <= 1.0f)
            {
                MirroredWallBounds.Add(new RecBounds(b.center + new Vector2(0.0f, WorldConstants.Size.y), b.size));
                //If the level also wraps horizontally, put the wall to the left and right.
                if (WrapX)
                {
                    MirroredWallBounds.Add(new RecBounds(b.center - new Vector2(-WorldConstants.Size.x, WorldConstants.Size.y), b.size));
                    MirroredWallBounds.Add(new RecBounds(b.center + new Vector2(WorldConstants.Size.x, WorldConstants.Size.y), b.size));
                }
            }
            //If the wall is near the top edge, put a wall on the bottom.
            if (Mathf.Abs(top - (levelBounds.center.y + levelBounds.extents.y)) <= 1.0f)
            {
                MirroredWallBounds.Add(new RecBounds(b.center + new Vector2(0.0f, -WorldConstants.Size.y), b.size));
                //If the level also wraps horizontally, put the wall to the left and right.
                if (WrapX)
                {
                    MirroredWallBounds.Add(new RecBounds(b.center + new Vector2(WorldConstants.Size.x, -WorldConstants.Size.y), b.size));
                    MirroredWallBounds.Add(new RecBounds(b.center + new Vector2(-WorldConstants.Size.x, -WorldConstants.Size.y), b.size));
                }
            }
        }
    }