예제 #1
0
        public override void Update(double total_seconds_elapsed, CollisionGrid grid)
        {
            //do stuff before the update
            _maxVelocity.X = Math.Abs(_desiredVelocity);
            float current_velocity = Velocity.X;
            if (Math.Abs(current_velocity) < Math.Abs(_desiredVelocity))
            {
                _accelleration.X = _runAccelleration * Math.Sign(_desiredVelocity);
            }
            else if (Math.Abs(current_velocity) > Math.Abs(_desiredVelocity))
            {
                _accelleration.X = _runDeccelleration * Math.Sign(_desiredVelocity);
            }

            base.Update(total_seconds_elapsed, grid);
        }
예제 #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);
            if (_gameCamera == null)
            {
                _gameCamera = new Camera2D(_graphics.GraphicsDevice.Viewport);
            }
            Texture2D theDudeTexture;
            theDudeTexture = Content.Load<Texture2D>("dude");

            font = Content.Load<SpriteFont>("SpriteFont1");

            CustomWorldData worldData = new CustomWorldData("Examplia");
            worldData.LoadContent(Content);

            itemCatalog = new ItemCatalog(worldData._itemData);

            if (System.IO.File.Exists("C:\\Users\\Public\\MyLevel.lvl") == true)
            {

                    try
                    {
                        _theGrid = new CollisionGrid("C:\\Users\\Public\\MyLevel.lvl", Content.Load<Texture2D>("Active"), Content.Load<Texture2D>("Inactive"), Content.Load<Texture2D>("Platform"));
                    }
                    catch //err as F
                    {
                        _theGrid = new CollisionGrid(100, 100);
                    }

            }
            else
            {
                _theGrid = new CollisionGrid(100, 100);
            }

            theDude = new Player(theDudeTexture, Vector2.Zero);
            theDude.TempAddItem(itemCatalog.GetItem(2));
            theDude.TempAddItem(itemCatalog.GetItem(1));

            // TODO: use this.Content to load your game content here
        }
예제 #3
0
        public virtual void Update(double total_seconds_elapsed, CollisionGrid grid)
        {
            if (total_seconds_elapsed == 0.0)
                return;
            Vector2 new_velocity = _velocity;
            new_velocity += (_accelleration * (float)total_seconds_elapsed);
            new_velocity.Y += _gravitationalAccelleration * (float)total_seconds_elapsed;
            new_velocity = Vector2.Clamp(new_velocity, Vector2.Negate(_maxVelocity), _maxVelocity);

            Vector2 distance_to_travel = (new_velocity * (float)total_seconds_elapsed) + _positionCarryOver;
            Vector2 distance_traveled = grid.CheckCollision(BoundingBox, distance_to_travel, _fallThrough);

            //Check to see if we moved as expected, if not we hit a block, so set the new velocity to 0.
            if (distance_traveled.X != distance_to_travel.X)
                new_velocity.X = 0;
            if (distance_traveled.Y != distance_to_travel.Y)
            {
                new_velocity.Y = 0;
            }

            Velocity = new_velocity;

            int original_y_position = _boundingBox.Y;

            AddToPositionAndCarry(distance_traveled);

            //If we were stopped from traveling downward, set the isAirborn flag to false
            if (distance_to_travel.Y > distance_traveled.Y)
            {
                _isAirborn = false;
            }
            //Otherwise if we moved in the Y direction, set us as airborn
            else if (original_y_position != _boundingBox.Y)
            {
                _isAirborn = true;
            }
        }
예제 #4
0
        public override void Update(double total_seconds_elapsed, CollisionGrid grid)
        {
            //TODO check for window is active before doing stuff based on keys and buttons, it's getting pretty annoying

            Camera2D camera = Game.CameraInstance;
            if (Keyboard.GetState().IsKeyDown(Keys.A) == true)
            {
                this.Run(-1.0f);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.D) == true)
            {
                this.Run(1.0f);
            }
            else
            {
                this.Run(GamePad.GetState(_controllerIndex).ThumbSticks.Left.X);
            }

            bool jump = (GamePad.GetState(_controllerIndex).Buttons.A == ButtonState.Pressed);
            if (_usingPcControls == true)
                jump |= Keyboard.GetState().IsKeyDown(Keys.Space) || Keyboard.GetState().IsKeyDown(Keys.W);

            this.Jump(jump);

            bool fall_through = (GamePad.GetState(_controllerIndex).ThumbSticks.Left.Y < -0.25);
            if (_usingPcControls == true)
                fall_through |= Keyboard.GetState().IsKeyDown(Keys.S);

            if ((fall_through == true) && (IsAirborn == false))
                this.FallThrough = (1 << (int)Teraform.Item.BLOCK_SURFACE.BLOCK_TOP);
            else
                this.FallThrough = 0;

            if ((GamePad.GetState(_controllerIndex).Buttons.B == ButtonState.Pressed))
            {
                grid.DEBUG_ENABLED = true;
            }
            else
            {
                grid.DEBUG_ENABLED = false;
            }

            if (GamePad.GetState(_controllerIndex).Buttons.LeftShoulder == ButtonState.Pressed)
                _belt.SelectPreviousItem();
            if (GamePad.GetState(_controllerIndex).Buttons.RightShoulder == ButtonState.Pressed)
                _belt.SelectNextItem();

            //Handle mouse wheel
            if (_usingPcControls == true)
            {
                int newScrollValue = Mouse.GetState().ScrollWheelValue;
                int relativeScrollValue = newScrollValue - _mouseScrollValue;
                _mouseScrollValue = newScrollValue;

                if (_inventoryOpen == false)
                {
                    if (relativeScrollValue < 0)
                    {
                        _belt.SelectPreviousItem();
                    }
                    else if (relativeScrollValue > 0)
                    {
                        _belt.SelectNextItem();
                    }

                    if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                    {
                        Item selectedItem = _belt.GetCurrentBeltItem();
                        if (selectedItem != null)
                        {
                            selectedItem.Use(new Point(Mouse.GetState().X + camera.Left, Mouse.GetState().Y + camera.Top), this);
                        }
                    }
                    if (Mouse.GetState().RightButton == ButtonState.Pressed)
                    {
                        grid.RemoveObject(Mouse.GetState().X + camera.Left, Mouse.GetState().Y + camera.Top);
                    }
                }
            }

            base.Update(total_seconds_elapsed, grid);
        }
예제 #5
0
        public virtual void Update(double total_seconds_elapsed, CollisionGrid grid)
        {
            if (_currentState == ITEM_STATE.IN_WORLD)
            {

            }
            else if (_currentState == ITEM_STATE.EQUIPPED)
            {

            }
        }