/// <summary> /// Move the box in the current moveDir. /// </summary> /// <param name="renderContext"></param> /// <param name="moveDir"></param> /// <param name="movementAmount"></param> public void Move(RenderContext renderContext, GameConstants.DIRECTION moveDir, float movementAmount) { facingDirection = moveDir; //Rotate(0f, -90f, 0f); //No need to rotate moving platform to set its direction Vector3 newPosition; Vector3 PositionChange; //Get position change depending on direction if(moveDir == LEFT) PositionChange = new Vector3(-movementAmount, 0, 0); else if (moveDir == RIGHT) PositionChange = new Vector3(movementAmount, 0, 0); else if (moveDir == UP) PositionChange = new Vector3(0, movementAmount, 0); else// if (moveDir == DOWN) PositionChange = new Vector3(0, -movementAmount, 0); newPosition = Position + PositionChange; currDistance += movementAmount; Translate(newPosition); //if player is on the platform, move the player just as much as the platform does if (PlayerOnPlatform) { Vector3 newPlayerPosition = renderContext.Player.Position + PositionChange; renderContext.Player.Translate(newPlayerPosition); } }
public MovingPlatform(int column, int row) : base(column, row) { base.Model = GameplayScreen._models["MovingBlock"]; base.isCollidable = true; maxDistance = 2 * GameConstants.SINGLE_CELL_SIZE; //default distance this.facingDirection = RIGHT; this.movingDirection = RIGHT; //default direction Scale(1, 0.25f, 1); Translate(Position.X, Position.Y + 18, Position.Z); // Provides a hitbox for the moving platform UpdateBoundingBox(base.Model, Matrix.CreateTranslation(base.Position), false, false); HitboxHeight = 12; HitboxHeightOffset = 18; }