コード例 #1
0
        public void Update(GameTime gameTime, CameraOperator cameraOperator)
        {
            TerrainChunk firstChunk = _chunks[0];
            if (firstChunk.LastVertex.X.ToPixels() <
                cameraOperator.Camera.Viewport.Projection.BoundingBox.TopLeft.X)
            {
                firstChunk.BodyPosition = _chunks[_chunks.Length - 1].LastVertex;
                firstChunk.Heights = Noise.Generate(TerrainChunk.HeightCount);

                Array.Copy(_chunks, 1, _chunks, 0, _chunks.Length - 1);
                _chunks[_chunks.Length - 1] = firstChunk;
            }
        }
コード例 #2
0
        public void Update(GameTime gameTime, CameraOperator cameraOperator)
        {
            TerrainChunk firstChunk = _chunks[0];

            if (firstChunk.LastVertex.X.ToPixels() <
                cameraOperator.Camera.Viewport.Projection.BoundingBox.TopLeft.X)
            {
                firstChunk.BodyPosition = _chunks[_chunks.Length - 1].LastVertex;
                firstChunk.Heights      = Noise.Generate(TerrainChunk.HeightCount);

                Array.Copy(_chunks, 1, _chunks, 0, _chunks.Length - 1);
                _chunks[_chunks.Length - 1] = firstChunk;
            }
        }
コード例 #3
0
        public Play(Game game)
            : base(game)
        {
            Cursor = new Cursor();
            Debug = new Debug(game, World, this);
            Entities = new Entities(World, this);
            Terrain = new Terrain(game.GraphicsDevice, World);
            CameraOperator = new CameraOperator(game.GraphicsDevice.Viewport.Bounds);
            HUD = new HUD();
            Background =
                new Background(new Vector2(game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height));

            Wait.Until(time => Tweening.Tween(
                start: 0f,
                end: 1f,
                progress: time.Alive/2f,
                step: value => Factor = value,
                scale: TweenScales.Quadratic));
        }
コード例 #4
0
 public void Update(GameTime gameTime, CameraOperator cameraOperator, World world)
 {
     _sprite.Body.Center = Input.Mouse.Position;
     if (_mouseJoint != null)
     {
         if (Input.Mouse.IsButtonDown(Input.Mouse.MouseButton.Left))
         {
             _mouseJoint.WorldAnchorB = cameraOperator.Camera.PositionOnWorld(Input.Mouse.Position);
         }
         else
         {
             world.RemoveJoint(_mouseJoint);
             _mouseJoint = null;
         }
     }
     else
     {
         Vector2 cursorWorldPosition = cameraOperator.Camera.PositionOnWorld(Input.Mouse.Position);
         if (Input.Mouse.IsButtonClicked(Input.Mouse.MouseButton.Left))
         {
             Fixture fixture;
             float radiusMeters = _sprite.Body.Projection.BoundingBox.Dimensions.X.ToMeters();
             if ((fixture =
                 world.TestPoint(cursorWorldPosition - new Vector2(radiusMeters))) != null ||
                 (fixture =
                     world.TestPoint(cursorWorldPosition + new Vector2(radiusMeters))) != null ||
                 (fixture =
                     world.TestPoint(cursorWorldPosition + new Vector2(radiusMeters, -radiusMeters))) != null ||
                 (fixture =
                     world.TestPoint(cursorWorldPosition - new Vector2(radiusMeters, -radiusMeters))) != null)
             {
                 if (fixture.UserData is Coin)
                 {
                     _mouseJoint = new FixedMouseJoint(fixture.Body, cursorWorldPosition)
                     {
                         MaxForce = 200*fixture.Body.Mass
                     };
                     world.AddJoint(_mouseJoint);
                 }
             }
         }
     }
 }
コード例 #5
0
 public void Update(GameTime gameTime, CameraOperator cameraOperator, World world)
 {
     _sprite.Body.Center = Input.Mouse.Position;
     if (_mouseJoint != null)
     {
         if (Input.Mouse.IsButtonDown(Input.Mouse.MouseButton.Left))
         {
             _mouseJoint.WorldAnchorB = cameraOperator.Camera.PositionOnWorld(Input.Mouse.Position);
         }
         else
         {
             world.RemoveJoint(_mouseJoint);
             _mouseJoint = null;
         }
     }
     else
     {
         Vector2 cursorWorldPosition = cameraOperator.Camera.PositionOnWorld(Input.Mouse.Position);
         if (Input.Mouse.IsButtonClicked(Input.Mouse.MouseButton.Left))
         {
             Fixture fixture;
             float   radiusMeters = _sprite.Body.Projection.BoundingBox.Dimensions.X.ToMeters();
             if ((fixture =
                      world.TestPoint(cursorWorldPosition - new Vector2(radiusMeters))) != null ||
                 (fixture =
                      world.TestPoint(cursorWorldPosition + new Vector2(radiusMeters))) != null ||
                 (fixture =
                      world.TestPoint(cursorWorldPosition + new Vector2(radiusMeters, -radiusMeters))) != null ||
                 (fixture =
                      world.TestPoint(cursorWorldPosition - new Vector2(radiusMeters, -radiusMeters))) != null)
             {
                 if (fixture.UserData is Coin)
                 {
                     _mouseJoint = new FixedMouseJoint(fixture.Body, cursorWorldPosition)
                     {
                         MaxForce = 200 * fixture.Body.Mass
                     };
                     world.AddJoint(_mouseJoint);
                 }
             }
         }
     }
 }
コード例 #6
0
 public void Update(GameTime gameTime, CameraOperator cameraOperator, World world)
 {
     Player.Update(gameTime);
     Coins.Update(gameTime, cameraOperator, this, world);
     Slimes.Update(gameTime);
 }
コード例 #7
0
 public void Draw(SpriteBatch spriteBatch, CameraOperator cameraOperator)
 {
     Coins.Draw(spriteBatch, cameraOperator, false);
     Slimes.Draw(spriteBatch, cameraOperator);
     Player.Draw(spriteBatch, cameraOperator);
 }
コード例 #8
0
        public void Update(GameTime gameTime, CameraOperator cameraOperator, Entities entities, World world)
        {
            foreach (Coin coin in _coins)
            {
                coin.Update(gameTime);
            }

            _seconds += gameTime.ElapsedGameTime.Milliseconds*1e-3f;
            if (_seconds > 1f)
            {
                --_seconds;

                RotatableRectangleF cameraViewport = cameraOperator.Camera.Viewport;
                if (_coins.Count == _coins.Capacity)
                    Remove(_coins[0], world);

                //select a way to launch
                if (InfiniteIsland.Random.Next(2) == 0)
                {
                    //Launch from the left
                    _coins.Add(
                        new Coin(
                            position:
                                (cameraViewport.TopLeft +
                                 new Vector2(0,
                                     (float) InfiniteIsland.Random.NextDouble()*
                                     cameraViewport.Dimensions.Y*.75f)).ToMeters(),
                            linearVelocity:
                                entities.Player.Body.Wheel.LinearVelocity*
                                new Vector2(1.5f + (float) InfiniteIsland.Random.NextDouble()/2.5f,
                                    -2*(float) InfiniteIsland.Random.NextDouble()), world: world));
                }
                else
                {
                    //Launch from the right
                    _coins.Add(
                        new Coin(
                            position:
                                (cameraViewport.TopRight +
                                new Vector2(0, (float) InfiniteIsland.Random.NextDouble()*cameraViewport.Dimensions.Y*.75f)).ToMeters(),
                            linearVelocity:
                                entities.Player.Body.Wheel.LinearVelocity*
                                (new Vector2(
                                    x: 1.5f + (float) InfiniteIsland.Random.NextDouble()/2.5f,
                                    y:-2*(float) InfiniteIsland.Random.NextDouble()) - Vector2.UnitX),
                            world: world));
                }
            }
        }
コード例 #9
0
        public void Draw(SpriteBatch spriteBatch, CameraOperator cameraOperator, bool revealCoins)
        {
            if (revealCoins)
            {
                spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null,
                    cameraOperator.Camera.CalculateTransformMatrix(Vector2.One));
                foreach (Coin coin in _coins)
                {
                    coin.Sprite.Key = coin.Type;
                    Vector2 badOffset = Vector2.Zero;
                    if (coin.Type == Coin.AnimationKeys.Bad)
                    {
                        badOffset = new Vector2(
                            x: (float) (InfiniteIsland.Random.NextDouble() - .5f)*15,
                            y: (float) (InfiniteIsland.Random.NextDouble() - .5f)*15);
                        coin.Sprite.Body.Center += badOffset;
                    }

                    coin.Sprite.Body.Pivot -= Vector2.One*3;
                    coin.Sprite.Body.Center -= Vector2.One*3;
                    coin.Draw(spriteBatch);
                    coin.Sprite.Body.Center += Vector2.One*3;
                    coin.Sprite.Body.Pivot += Vector2.One*3;
                    coin.Sprite.Body.Center -= badOffset;
                }
                spriteBatch.End();
            }
            else
            {
                spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null,
                    cameraOperator.Camera.CalculateTransformMatrix(Vector2.One));
                foreach (Coin coin in _coins)
                {
                    coin.Sprite.Key = Coin.AnimationKeys.Outline;
                    coin.Draw(spriteBatch);
                }
                spriteBatch.End();
            }
        }
コード例 #10
0
 public void Update(GameTime gameTime, CameraOperator cameraOperator, World world)
 {
     Player.Update(gameTime);
     Coins.Update(gameTime, cameraOperator, this, world);
     Slimes.Update(gameTime);
 }
コード例 #11
0
 public void Draw(SpriteBatch spriteBatch, CameraOperator cameraOperator)
 {
     Coins.Draw(spriteBatch, cameraOperator, false);
     Slimes.Draw(spriteBatch, cameraOperator);
     Player.Draw(spriteBatch, cameraOperator);
 }
コード例 #12
0
 public void Draw(SpriteBatch spriteBatch, CameraOperator cameraOperator)
 {
     spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null,
         cameraOperator.Camera.CalculateTransformMatrix(Vector2.One));
     foreach (Slime slime in SlimeList)
     {
         slime.Draw(spriteBatch);
     }
     spriteBatch.End();
 }