Пример #1
0
        void CheckCollison(int x, int y,Game1 game)
        {
            keyboardState = Keyboard.GetState();
            // Console.WriteLine("Checking collison");
            if ((50 * x) < game.player.position.X + (game.player.PlayerTexture.Width) /2 && (50 * x) + 50 > game.player.position.X &&
                 (50 * y) < game.player.position.Y + (game.player.PlayerTexture.Height) /2 && (50 * y) + 50 > game.player.position.Y)
            {

                if (keyboardState.IsKeyDown(Keys.W))
                {
                    game.player.position.Y += game.player.speed * 2;
                }
                if (keyboardState.IsKeyDown(Keys.S))
                {
                    game.player.position.Y -= game.player.speed * 2;
                }
                if (keyboardState.IsKeyDown(Keys.D))
                {
                    game.player.position.X -= game.player.speed * 2;
                }
                if (keyboardState.IsKeyDown(Keys.A))
                {
                    game.player.position.X += game.player.speed * 2;
                }
            }
        }
Пример #2
0
        public void Update(GameTime gameTime, Game1 game)
        {
            center = new Vector2((game.player.position.X + (game.player.PlayerTexture.Width / 2) - (game.width / 2)),
                (game.player.position.Y + (game.player.PlayerTexture.Height / 2)) - (game.height / 2));

            transform = Matrix.CreateScale(new Vector3(scale, scale, 1)) * Matrix.CreateTranslation(new Vector3(-center.X, -center.Y, 0));
        }
Пример #3
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (Game1 game = new Game1())
     {
         game.Run();
     }
 }
Пример #4
0
        public void Draw(SpriteBatch spriteBatch, Game1 game)
        {
            for (int x = 0; x < tileMap.GetLength(1); x++)
            {
                for (int y = 0; y < tileMap.GetLength(0); y++)
                {
                    spriteBatch.Draw(tiles[tileMap[x, y]], new Vector2(50 * x, 50 * y), Color.White);
                    //Console.WriteLine(tiles[tileMap[x, y]]);

                    if(tileMap[x,y] == 4)
                    {
                        CheckCollison(x, y, game);
                    }

                }

            }
        }
Пример #5
0
        public void Update(GameTime gameTime, Game1 game)
        {
            ms = Mouse.GetState();
            keyboardState = Keyboard.GetState();
            direction = new Vector2((float)Math.Cos(rotation), (float)(Math.Sin(rotation)));
            mousePosition = new Vector2(ms.X, ms.Y);
            worldPosition = Vector2.Transform(mousePosition, Matrix.Invert(game.camera.transform));

            // updates the collider
            playerRect = new Rectangle((int)position.X, (int)position.X, PlayerTexture.Width, PlayerTexture.Height);
            origin = new Vector2(position.X + (playerRect.Width / 2) , position.Y + (playerRect.Height / 2));

            if(worldPosition.X > origin.X)
            {

                spriteEffect = SpriteEffects.None;
            }
            if (worldPosition.X < origin.X)
            {

                spriteEffect = SpriteEffects.FlipHorizontally;

            }
            // inputs
            if (keyboardState.IsKeyDown(Keys.W))
            {
                position.Y -= speed;
            }
            if (keyboardState.IsKeyDown(Keys.S))
            {
                position.Y += speed;
            }
            if (keyboardState.IsKeyDown(Keys.D))
            {
                position.X += speed;
            }
            if (keyboardState.IsKeyDown(Keys.A))
            {
                position.X -= speed;
            }
        }