Beispiel #1
0
        public GameController(ContentManager Content, GraphicsDeviceManager graphics)
        {
            camera = new Camera(graphics.GraphicsDevice.Viewport);
            level = new Level();
            content = Content;
            currentPlayerForm = PlayerForm.Square;

            Tiles.Content = Content;

            level.Generate(new int[,]
            {
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
                {0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,9},
                {1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,0,1,1,0,0,1,1,0,0,1,1,0,0,0,1,1,1,0,1,1,1,1,1,0,0,0,1,1},
            }, 48);

            // If new game, load this player texture.
            playerTexture = Content.Load<Texture2D>("PlayerSquare");

            playerSimulation = new PlayerSimulation();
            playerView = new PlayerView(camera, playerSimulation);
        }
Beispiel #2
0
        public void Collision(Rectangle newRectangle, int xOffset, int yOffset, Camera camera)
        {
            Vector2 position = camera.getVisualCoords(player.getPosition());
            Rectangle rectangle = new Rectangle((int)position.X, (int)position.Y, 32, 32);

            if (rectangle.TouchTop(newRectangle))
            {
                position.Y = newRectangle.Y - rectangle.Height;

                player.TouchingFloor = true;
                player.CanJump = true;
                player.CanJumpAgain = true;
            }

            if (rectangle.TouchLeft(newRectangle))
            {
                position.X = newRectangle.X - rectangle.Width;
                player.speed.X = -0.05f;

            }
            if (rectangle.TouchRight(newRectangle))
            {
                position.X = newRectangle.X + newRectangle.Width;
                player.speed.X = 0.05f;
            }

            if (rectangle.TouchBottom(newRectangle))
            {
                player.speed.Y = 0.5f;
            }

            if (position.X < 0)
            {
                position.X = 0 + rectangle.Width;
                player.speed.X = 0.05f;
            }

            if (position.X > xOffset - rectangle.Width)
            {
                position.X = xOffset - rectangle.Width;
                player.speed.X = -0.05f;
            }

            // If player falls, set IsAlive to false. Use this later to fix game over etc.
            if (position.Y > yOffset - rectangle.Height)
            {
                player.IsAlive = false;
                position.Y = yOffset - rectangle.Height;
                Console.WriteLine("Player alive: " + player.IsAlive);
            }

            // If player leaves top of a rectangle.
            if(position.X > newRectangle.X + newRectangle.Width)
            {
                player.TouchingFloor = false;
                player.CanJump = false;
            }
        }
Beispiel #3
0
 public PlayerView(Camera newCamera, PlayerSimulation newPlayerSimulation)
 {
     camera = newCamera;
     playerSimulation = newPlayerSimulation;
 }