Exemple #1
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 #2
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);
        }