Exemple #1
0
        public static Map ReadFile(string filename, Texture2D TileSheet,Texture2D AnimatedTileSheet, Game1 game)
        {
            Int32 x = 0;
            Int32 y = 0;
            int largestWidth = 0;
            ArrayList tmp = new ArrayList();
            ArrayList tmp2 = new ArrayList();

            using (StreamReader sReader = new StreamReader(filename))
            {
                while (sReader.Peek() >= 0)
                {
                    x = 0;
                    foreach (char c in sReader.ReadLine())
                    {
            switch (c)
                        {
                            case '#':
                                tmp2.Add(new Sprite(game,TileSheet,game.GetSpriteBatch(),new Vector2(x*32, y*32), TileType.Ground));
                                break;
                            case '$':
                                tmp2.Add(new Sprite(game,TileSheet, game.GetSpriteBatch(), new Vector2(x*32, y*32), TileType.Water));
                                break;
                            case '&':
                                tmp2.Add(new Sprite(game, TileSheet, game.GetSpriteBatch(), new Vector2(x * 32, y * 32), TileType.Goo));
                                break;
                            case '%':
                                tmp2.Add(new Sprite(game, TileSheet, game.GetSpriteBatch(), new Vector2(x * 32, y * 32), TileType.Rocks));
                                break;
                            case '^':
                                tmp2.Add(new Sprite(game, TileSheet, game.GetSpriteBatch(), new Vector2(x * 32, y * 32), TileType.Spikes));
                                break;
                            case '2':
                                tmp2.Add(new Sprite(game, TileSheet, game.GetSpriteBatch(), new Vector2(x * 32, y * 32), TileType.Life));
                                break;
                            case '1':
                                tmp2.Add(new Sprite(game, TileSheet, game.GetSpriteBatch(), new Vector2(x * 32, y * 32), TileType.Key));
                                break;
                            case '3':
                                tmp.Add(new AnimatedSprite(game, AnimatedTileSheet, game.GetSpriteBatch(), new Vector2(x * 32, y * 32), TileType.NPC_ground));
                                break;
                            case '4':
                                tmp.Add(new AnimatedSprite(game, AnimatedTileSheet, game.GetSpriteBatch(), new Vector2(x * 32, y * 32), TileType.NPC_Flyer));
                                break;
                            case '\t':
                                x += 7;
                                break;
                            default:
                                // Char is whitespace or non recognised tile, ignore.
                                break;
                        }

                        x += 1;
                    }

                    if (x > largestWidth) {
                        largestWidth = x;
                    }

                    y += 1;
                }
            }
            Map tempMap = new Map(tmp2,tmp,largestWidth * 32,game);
            return tempMap;
        }
Exemple #2
0
        public void Update(GameTime gameTime, Map level,Player player)
        {
            // To prevent the character moving on for ever
            direction.X = 0;
            direction.Y = 0;

            this.keyboard ();

            int calc1 = (int)level.Position.X - (game.Window.ClientBounds.Width / 2);
            int calc2 = (int)player.MapLocation.X - (game.Window.ClientBounds.Width / 2);

            if ((direction.X == 1) && (calc1 >= 0))//(changeVector.X >= 0) &&
            {
                changeVect.X = calc1 * -1;// 0;//(level.Position.X-(Window.ClientBounds.Width / 2))
                changeVect.Y = direction.Y * speed.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;

            }
            else if ((calc2 <= -(level.Width)) && (direction.X == -1))
            {
                changeVect.X = (level.Width + calc2) * -1;// calculation;// *-1;// 0;//
                changeVect.Y = direction.Y * speed.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;

            }
            else
            {
                changeVect = direction * speed * (float)gameTime.ElapsedGameTime.TotalSeconds;

            }
        }
Exemple #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch 	= new SpriteBatch (GraphicsDevice);

            // Create a rendertarget that matches the back buffer's dimensions, does not generate mipmaps automatically
            // (the Reach profile requires power of 2 sizing in order to do that), uses an RGBA color format, and
            // has no depth buffer or stencil buffer.

            renderTarget 	= new RenderTarget2D (GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth,GraphicsDevice.PresentationParameters.BackBufferHeight, false, SurfaceFormat.Color, DepthFormat.None);

            TileSheet 			= Content.Load<Texture2D>("tilesheet.png");
            font 				= Content.Load<SpriteFont>("spriteFont1");
            animatedTilesheet 	= Content.Load<Texture2D>("AnimationTiles.png");

            fps 				= new FPSCounterComponent(this,spriteBatch,font);
            level 				= MapLoader.ReadFile("./Content/map.txt", TileSheet,animatedTilesheet, this);
            glasses 			= new GlassesUI(this, spriteBatch);
            player				= new Player(this);
            Vector2 playerPos 	= new Vector2(
                (this.Window.ClientBounds.Width / 2 ) - 16,
                (this.Window.ClientBounds.Height / 2) - 32
                );

            this.controls = new Controls(this,glasses);

            player.Initalise(this,animatedTilesheet,spriteBatch,playerPos);
            bkgnd.Initialise(Content.Load<Texture2D>("Background2"),800);

            Components.Add(fps);
        }